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.InterfaceTags import InterfaceTag, InterfaceTags
14 from PLC.Interfaces import Interface, Interfaces
16 from PLC.Nodes import Node, Nodes
17 from PLC.Sites import Site, Sites
19 class DeleteInterfaceTag(Method):
21 Deletes the specified interface setting
23 Attributes may require the caller to have a particular role in order
24 to be deleted, depending on the related tag type.
25 Admins may delete attributes of any slice or sliver.
27 Returns 1 if successful, faults otherwise.
30 roles = ['admin', 'pi', 'user']
34 InterfaceTag.fields['interface_tag_id']
37 returns = Parameter(int, '1 if successful')
39 object_type = 'Interface'
42 def call(self, auth, interface_tag_id):
43 interface_tags = InterfaceTags(self.api, [interface_tag_id])
44 if not interface_tags:
45 raise PLCInvalidArgument, "No such interface tag %r"%interface_tag_id
46 interface_tag = interface_tags[0]
48 ### reproducing a check from UpdateSliceTag, looks dumb though
49 interfaces = Interfaces(self.api, [interface_tag['interface_id']])
51 raise PLCInvalidArgument, "No such interface %r"%interface_tag['interface_id']
52 interface = interfaces[0]
54 assert interface_tag['interface_tag_id'] in interface['interface_tag_ids']
56 # check permission : it not admin, is the user affiliated with the right site
57 if 'admin' not in self.caller['roles']:
59 node = Nodes (self.api,[interface['node_id']])[0]
61 site = Sites (self.api, [node['site_id']])[0]
62 # check caller is affiliated with this site
63 if self.caller['person_id'] not in site['person_ids']:
64 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
66 required_min_role = tag_type ['min_role_id']
67 if required_min_role is not None and \
68 min(self.caller['role_ids']) > required_min_role:
69 raise PLCPermissionDenied, "Not allowed to modify the specified interface setting, requires role %d",required_min_role
71 interface_tag.delete()
72 self.object_ids = [interface_tag['interface_tag_id']]