4 # Thierry Parmentelat - INRIA
9 from PLC.Faults import *
10 from PLC.Method import Method
11 from PLC.Parameter import Parameter, Mixed
12 from PLC.Auth import Auth
14 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
15 from PLC.Interfaces import Interface, Interfaces
17 from PLC.Nodes import Nodes
18 from PLC.Sites import Sites
20 class UpdateInterfaceTag(Method):
22 Updates the value of an existing interface setting
24 Access rights depend on the tag type.
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 object_type = 'Interface'
41 def call(self, auth, interface_tag_id, value):
42 interface_tags = InterfaceTags(self.api, [interface_tag_id])
43 if not interface_tags:
44 raise PLCInvalidArgument, "No such interface setting %r"%interface_tag_id
45 interface_tag = interface_tags[0]
47 ### reproducing a check from UpdateSliceTag, looks dumb though
48 interfaces = Interfaces(self.api, [interface_tag['interface_id']])
50 raise PLCInvalidArgument, "No such interface %r"%interface_tag['interface_id']
51 interface = interfaces[0]
53 assert interface_tag['interface_tag_id'] in interface['interface_tag_ids']
55 # check permission : it not admin, is the user affiliated with the right site
56 if 'admin' not in self.caller['roles']:
58 node = Nodes (self.api,[interface['node_id']])[0]
60 site = Sites (self.api, [node['site_id']])[0]
61 # check caller is affiliated with this site
62 if self.caller['person_id'] not in site['person_ids']:
63 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
65 required_min_role = tag_type ['min_role_id']
66 if required_min_role is not None and \
67 min(self.caller['role_ids']) > required_min_role:
68 raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
70 interface_tag['value'] = value
73 self.object_ids = [interface_tag['interface_tag_id']]