2 # Thierry Parmentelat - INRIA
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
10 from PLC.Sites import Sites
11 from PLC.Nodes import Node, Nodes
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.NodeTags import NodeTag, NodeTags
15 class UpdateNodeTag(Method):
17 Updates the value of an existing node tag
19 Admins have full access. Non-admins need to
20 (1) have at least one of the roles attached to the tagtype,
21 and (2) belong in the same site as the tagged subject.
23 Returns 1 if successful, faults otherwise.
26 roles = ['admin', 'pi', 'tech', 'user']
30 NodeTag.fields['node_tag_id'],
31 NodeTag.fields['value']
34 returns = Parameter(int, '1 if successful')
36 def call(self, auth, node_tag_id, value):
37 node_tags = NodeTags(self.api, [node_tag_id])
39 raise PLCInvalidArgument, "No such node tag %r"%node_tag_id
40 node_tag = node_tags[0]
42 tag_type_id = node_tag['tag_type_id']
43 tag_type = TagTypes (self.api,[tag_type_id])[0]
45 nodes = Nodes (self.api, node_tag['node_id'])
47 raise PLCInvalidArgument, "No such node %d"%node_tag['node_id']
50 # check authorizations
51 node.caller_may_write_tag(self.api,self.caller,tag_type)
53 node_tag['value'] = value
56 self.object_ids = [node_tag['node_tag_id']]