rename IlinkType into LinkType as these types will be used for Nlinks as well
[plcapi.git] / PLC / Methods / UpdateLinkType.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.LinkTypes import LinkType, LinkTypes
10 from PLC.Auth import Auth
11
12 can_update = lambda (field, value): field in \
13              ['name', 'description', 'category', 'min_role_id']
14
15 class UpdateLinkType(Method):
16     """
17     Updates the parameters of an existing link type
18     with the values in link_type_fields.
19
20     Returns 1 if successful, faults otherwise.
21     """
22
23     roles = ['admin']
24
25     link_type_fields = dict(filter(can_update, LinkType.fields.items()))
26
27     accepts = [
28         Auth(),
29         Mixed(LinkType.fields['link_type_id'],
30               LinkType.fields['name']),
31         link_type_fields
32         ]
33
34     returns = Parameter(int, '1 if successful')
35
36     def call(self, auth, link_type_id_or_name, link_type_fields):
37         link_type_fields = dict(filter(can_update, link_type_fields.items()))
38
39         link_types = LinkTypes(self.api, [link_type_id_or_name])
40         if not link_types:
41             raise PLCInvalidArgument, "No such tag type"
42         link_type = link_types[0]
43
44         link_type.update(link_type_fields)
45         link_type.sync()
46         self.object_ids = [link_type['link_type_id']]
47
48         return 1