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