00030854e7707db1dc097458ce2103f95058d459
[plcapi.git] / PLC / Methods / AddTagType.py
1 # $Id$
2 #
3 # Thierry Parmentelat - INRIA
4 #
5 # $Revision: 9423 $
6 #
7
8
9 from PLC.Faults import *
10 from PLC.Method import Method
11 from PLC.Parameter import Parameter, Mixed
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.Auth import Auth
14
15 can_update = lambda (field, value): field in \
16              ['tagname', 'description', 'category', 'min_role_id']
17
18 class AddTagType(Method):
19     """
20     Adds a new type of node tag.
21     Any fields specified are used, otherwise defaults are used.
22
23     Returns the new node_tag_id (> 0) if successful,
24     faults otherwise.
25     """
26
27     roles = ['admin']
28
29     tag_type_fields = dict(filter(can_update, TagType.fields.items()))
30
31     accepts = [
32         Auth(),
33         tag_type_fields
34         ]
35
36     returns = Parameter(int, 'New node_tag_id (> 0) if successful')
37
38
39     def call(self, auth, tag_type_fields):
40         tag_type_fields = dict(filter(can_update, tag_type_fields.items()))
41         tag_type = TagType(self.api, tag_type_fields)
42         tag_type.sync()
43
44         self.object_ids = [tag_type['tag_type_id']]
45
46         return tag_type['tag_type_id']