rename attributes to slice_attribute_types
[plcapi.git] / PLC / Methods / AddSliceAttributeType.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.SliceAttributeTypes import SliceAttributeType, SliceAttributeTypes
5 from PLC.Auth import PasswordAuth
6
7 can_update = lambda (field, value): field in \
8              ['description', 'min_role_id']
9
10 class AddSliceAttributeType(Method):
11     """
12     Adds a new type of slice attribute. Any fields specified in
13     attribute_type_fields are used, otherwise defaults are used.
14
15     Returns the new attribute_type_id (> 0) if successful, faults
16     otherwise.
17     """
18
19     roles = ['admin']
20
21     update_fields = dict(filter(can_update, SliceAttributeType.fields.items()))
22
23     accepts = [
24         PasswordAuth(),
25         SliceAttributeType.fields['name'],
26         update_fields
27         ]
28
29     returns = Parameter(int, 'New attribute_id (> 0) if successful')
30
31     def call(self, auth, name, attribute_type_fields = {}):
32         attribute_type_fields = dict(filter(can_update, attribute_type_fields.items()))
33         attribute_type = SliceAttributeType(self.api, attribute_type_fields)
34         attribute_type['name'] = name
35         attribute_type.sync()
36
37         return attribute_type['attribute_type_id']