a single tag type for slice attributes, iterface settings, node tags and ilinks
[plcapi.git] / PLC / Methods / UpdateTagType.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 # $Revision: 9423 $
5 #
6 from PLC.Faults import *
7 from PLC.Method import Method
8 from PLC.Parameter import Parameter, Mixed
9 from PLC.TagTypes import TagType, TagTypes
10 from PLC.Auth import Auth
11
12 can_update = lambda (field, value): field in \
13              ['tagname', 'description', 'category', 'min_role_id']
14
15 class UpdateTagType(Method):
16     """
17     Updates the parameters of an existing tag type
18     with the values in tag_type_fields.
19
20     Returns 1 if successful, faults otherwise.
21     """
22
23     roles = ['admin']
24
25     tag_type_fields = dict(filter(can_update, TagType.fields.items()))
26
27     accepts = [
28         Auth(),
29         Mixed(TagType.fields['tag_type_id'],
30               TagType.fields['tagname']),
31         tag_type_fields
32         ]
33
34     returns = Parameter(int, '1 if successful')
35
36     def call(self, auth, tag_type_id_or_name, tag_type_fields):
37         tag_type_fields = dict(filter(can_update, tag_type_fields.items()))
38
39         tag_types = TagTypes(self.api, [tag_type_id_or_name])
40         if not tag_types:
41             raise PLCInvalidArgument, "No such tag type"
42         tag_type = tag_types[0]
43
44         tag_type.update(tag_type_fields)
45         tag_type.sync()
46         self.object_ids = [tag_type['tag_type_id']]
47
48         return 1