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