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.Ilinks import Ilink, Ilinks
13 from PLC.Interfaces import Interface, Interfaces
14 from PLC.Nodes import Node, Nodes
15 from PLC.Sites import Site, Sites
16 from PLC.TagTypes import TagType, TagTypes
18 class DeleteIlink(Method):
20 Deletes the specified ilink
22 Attributes may require the caller to have a particular
23 role in order 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 Ilink.fields['ilink_id']
36 returns = Parameter(int, '1 if successful')
38 object_type = 'Interface'
41 def call(self, auth, ilink_id):
42 ilinks = Ilinks(self.api, [ilink_id])
44 raise PLCInvalidArgument, "No such ilink %r"%ilink_id
47 tag_type_id = ilink['tag_type_id']
48 tag_type = TagTypes (self.api,[tag_type_id])[0]
49 required_min_role = tag_type ['min_role_id']
51 # check permission : it not admin, is the user affiliated with the right site<S>
52 if 'admin' not in self.caller['roles']:
53 for key in ['src_interface_id','dst_interface_id']:
55 interface_id=ilink[key]
56 interface = Interfaces (self.api,interface_id)[0]
57 node_id=interface['node_id']
58 node = Nodes (self.api,node_id) [0]
60 site_id = node['site_id']
61 site = Sites (self.api, [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 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 ilink, requires role %d",required_min_role
71 self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]