640ee50d1d8841bc7e0e357744f3e80fad42dc15
[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 Auth
6
7 can_update = lambda (field, value): field in \
8              ['name', '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     attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items()))
22
23     accepts = [
24         Auth(),
25         attribute_type_fields
26         ]
27
28     returns = Parameter(int, 'New attribute_id (> 0) if successful')
29
30     event_type = 'Add'
31     object_type = 'SliceAttributeType'
32     object_ids = []
33
34     def call(self, auth, attribute_type_fields):
35         attribute_type_fields = dict(filter(can_update, attribute_type_fields.items()))
36         attribute_type = SliceAttributeType(self.api, attribute_type_fields)
37         attribute_type.sync()
38
39         self.object_ids = [attribute_type['attribute_type_id']]
40
41         return attribute_type['attribute_type_id']