rename IlinkType into LinkType as these types will be used for Nlinks as well
[plcapi.git] / PLC / Methods / AddLinkType.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 # $Revision: 9423 $
5 #
6
7
8 from PLC.Faults import *
9 from PLC.Method import Method
10 from PLC.Parameter import Parameter, Mixed
11 from PLC.LinkTypes import LinkType, LinkTypes
12 from PLC.Auth import Auth
13
14 can_update = lambda (field, value): field in \
15              ['name', 'description', 'category', 'min_role_id']
16
17 class AddLinkType(Method):
18     """
19     Adds a new type of ilink.
20     Any fields specified are used, otherwise defaults are used.
21
22     Returns the new ilink_id (> 0) if successful,
23     faults otherwise.
24     """
25
26     roles = ['admin']
27
28     link_type_fields = dict(filter(can_update, LinkType.fields.items()))
29
30     accepts = [
31         Auth(),
32         link_type_fields
33         ]
34
35     returns = Parameter(int, 'New ilink_id (> 0) if successful')
36
37
38     def call(self, auth, link_type_fields):
39         link_type_fields = dict(filter(can_update, link_type_fields.items()))
40         link_type = LinkType(self.api, link_type_fields)
41         link_type.sync()
42
43         self.object_ids = [link_type['link_type_id']]
44
45         return link_type['link_type_id']