3 # Thierry Parmentelat - INRIA
8 from PLC.Faults import *
9 from PLC.Method import Method
10 from PLC.Parameter import Parameter, Mixed
11 from PLC.Auth import Auth
13 from PLC.InterfaceSettings import InterfaceSetting, InterfaceSettings
14 from PLC.Interfaces import Interface, Interfaces
16 from PLC.Nodes import Nodes
17 from PLC.Sites import Sites
19 class UpdateInterfaceSetting(Method):
21 Updates the value of an existing interface setting
23 Access rights depend on the tag type.
25 Returns 1 if successful, faults otherwise.
28 roles = ['admin', 'pi', 'tech', 'user']
32 InterfaceSetting.fields['interface_setting_id'],
33 InterfaceSetting.fields['value']
36 returns = Parameter(int, '1 if successful')
38 object_type = 'Interface'
40 def call(self, auth, interface_setting_id, value):
41 interface_settings = InterfaceSettings(self.api, [interface_setting_id])
42 if not interface_settings:
43 raise PLCInvalidArgument, "No such interface setting %r"%interface_setting_id
44 interface_setting = interface_settings[0]
46 ### reproducing a check from UpdateSliceAttribute, looks dumb though
47 interfaces = Interfaces(self.api, [interface_setting['interface_id']])
49 raise PLCInvalidArgument, "No such interface %r"%interface_setting['interface_id']
50 interface = interfaces[0]
52 assert interface_setting['interface_setting_id'] in interface['interface_setting_ids']
54 # check permission : it not admin, is the user affiliated with the right site
55 if 'admin' not in self.caller['roles']:
57 node = Nodes (self.api,[interface['node_id']])[0]
59 site = Sites (self.api, [node['site_id']])[0]
60 # check caller is affiliated with this site
61 if self.caller['person_id'] not in site['person_ids']:
62 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
64 required_min_role = tag_type ['min_role_id']
65 if required_min_role is not None and \
66 min(self.caller['role_ids']) > required_min_role:
67 raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
69 interface_setting['value'] = value
70 interface_setting.sync()
72 self.object_ids = [interface_setting['interface_setting_id']]