0cc393474826620366abc3fac2613a1a8c1dad48
[plcapi.git] / PLC / Methods / UpdateIlink.py
1 # $Id$
2 #
3 # Thierry Parmentelat - INRIA
4 #
5 # $Revision: 9423 $
6 #
7
8 from PLC.Faults import *
9 from PLC.Method import Method
10 from PLC.Parameter import Parameter, Mixed
11 from PLC.Auth import Auth
12
13 from PLC.Ilinks import Ilink, Ilinks
14 from PLC.Interfaces import Interface, Interfaces
15
16 from PLC.Sites import Sites
17
18 class UpdateIlink(Method):
19     """
20     Updates the value of an existing ilink
21
22     Access rights depend on the tag type.
23
24     Returns 1 if successful, faults otherwise.
25     """
26
27     roles = ['admin', 'pi', 'tech', 'user']
28
29     accepts = [
30         Auth(),
31         Ilink.fields['ilink_id'],
32         Ilink.fields['value']
33         ]
34
35     returns = Parameter(int, '1 if successful')
36
37     object_type = 'Interface'
38
39     def call(self, auth, ilink_id, value):
40         ilinks = Ilinks(self.api, [ilink_id])
41         if not ilinks:
42             raise PLCInvalidArgument, "No such ilink %r"%ilink_id
43         ilink = ilinks[0]
44
45         # xxx see AddIlink for this - should be written once in the Ilink class I guess
46         # checks rights and stuff
47
48         ilink['value'] = value
49         ilink.sync()
50
51         self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
52         return 1