2 # Thierry Parmentelat - INRIA
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
9 from PLC.Sites import Sites
10 from PLC.Nodes import Nodes
11 from PLC.Interfaces import Interface, Interfaces
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
15 # need to import so the core classes get decorated with caller_may_write_tag
16 from PLC.AuthorizeHelpers import AuthorizeHelpers
18 class UpdateInterfaceTag(Method):
20 Updates the value of an existing interface setting
22 Admins have full access. Non-admins need to
23 (1) have at least one of the roles attached to the tagtype,
24 and (2) belong in the same site as the tagged subject.
26 Returns 1 if successful, faults otherwise.
29 roles = ['admin', 'pi', 'tech', 'user']
33 InterfaceTag.fields['interface_tag_id'],
34 InterfaceTag.fields['value']
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, interface_tag_id, value):
40 interface_tags = InterfaceTags(self.api, [interface_tag_id])
41 if not interface_tags:
42 raise PLCInvalidArgument("No such interface setting %r"%interface_tag_id)
43 interface_tag = interface_tags[0]
45 tag_type_id = interface_tag['tag_type_id']
46 tag_type = TagTypes (self.api,[tag_type_id])[0]
48 interfaces = Interfaces (self.api, interface_tag['interface_id'])
50 raise PLCInvalidArgument("No such interface %d"%interface_tag['interface_id'])
51 interface=interfaces[0]
53 # check authorizations
54 interface.caller_may_write_tag(self.api, self.caller, tag_type)
56 interface_tag['value'] = value
59 self.object_ids = [interface_tag['interface_tag_id']]