Merge from HEAD. Signed off by tmack.
[plcapi.git] / PLC / Methods / UpdateSliceAttributeType.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 UpdateSliceAttributeType(Method):
11     """
12     Updates the parameters of an existing attribute with the values in
13     attribute_type_fields.
14
15     Returns 1 if successful, faults otherwise.
16     """
17
18     roles = ['admin']
19
20     attribute_type_fields = dict(filter(can_update, SliceAttributeType.fields.items()))
21
22     accepts = [
23         Auth(),
24         Mixed(SliceAttributeType.fields['attribute_type_id'],
25               SliceAttributeType.fields['name']),
26         attribute_type_fields
27         ]
28
29     returns = Parameter(int, '1 if successful')
30
31     def call(self, auth, attribute_type_id_or_name, attribute_type_fields):
32         attribute_type_fields = dict(filter(can_update, attribute_type_fields.items()))
33
34         attribute_types = SliceAttributeTypes(self.api, [attribute_type_id_or_name])
35         if not attribute_types:
36             raise PLCInvalidArgument, "No such attribute"
37         attribute_type = attribute_types[0]
38
39         attribute_type.update(attribute_type_fields)
40         attribute_type.sync()
41         self.event_objects = {'AttributeType': [attribute_type['attribute_type_id']]}
42
43         return 1