2 # Thierry Parmentelat - INRIA
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
12 from PLC.InterfaceSettings import InterfaceSetting, InterfaceSettings
13 from PLC.Interfaces import Interface, Interfaces
15 from PLC.Nodes import Node, Nodes
16 from PLC.Sites import Site, Sites
18 class DeleteInterfaceSetting(Method):
20 Deletes the specified interface setting
22 Attributes may require the caller to have a particular role in order
23 to be deleted, depending on the related tag type.
24 Admins may delete attributes of any slice or sliver.
26 Returns 1 if successful, faults otherwise.
29 roles = ['admin', 'pi', 'user']
33 InterfaceSetting.fields['interface_setting_id']
36 returns = Parameter(int, '1 if successful')
38 object_type = 'Interface'
41 def call(self, auth, interface_setting_id):
42 interface_settings = InterfaceSettings(self.api, [interface_setting_id])
43 if not interface_settings:
44 raise PLCInvalidArgument, "No such interface setting %r"%interface_setting_id
45 interface_setting = interface_settings[0]
47 ### reproducing a check from UpdateSliceAttribute, looks dumb though
48 interfaces = Interfaces(self.api, [interface_setting['interface_id']])
50 raise PLCInvalidArgument, "No such interface %r"%interface_setting['interface_id']
51 interface = interfaces[0]
53 assert interface_setting['interface_setting_id'] in interface['interface_setting_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_setting.delete()
71 self.object_ids = [interface_setting['interface_setting_id']]