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.Ilinks import Ilink, Ilinks
15 from PLC.Interfaces import Interface, Interfaces
16 from PLC.Nodes import Node, Nodes
17 from PLC.Sites import Site, Sites
18 from PLC.TagTypes import TagType, TagTypes
20 class DeleteIlink(Method):
22 Deletes the specified ilink
24 Attributes may require the caller to have a particular
25 role in order to be deleted, depending on the related tag type.
26 Admins may delete attributes of any slice or sliver.
28 Returns 1 if successful, faults otherwise.
31 roles = ['admin', 'pi', 'user']
35 Ilink.fields['ilink_id']
38 returns = Parameter(int, '1 if successful')
40 object_type = 'Interface'
43 def call(self, auth, ilink_id):
44 ilinks = Ilinks(self.api, [ilink_id])
46 raise PLCInvalidArgument, "No such ilink %r"%ilink_id
49 tag_type_id = ilink['tag_type_id']
50 tag_type = TagTypes (self.api,[tag_type_id])[0]
51 required_min_role = tag_type ['min_role_id']
53 # check permission : it not admin, is the user affiliated with the right site<S>
54 if 'admin' not in self.caller['roles']:
55 for key in ['src_interface_id','dst_interface_id']:
57 interface_id=ilink[key]
58 interface = Interfaces (self.api,interface_id)[0]
59 node_id=interface['node_id']
60 node = Nodes (self.api,node_id) [0]
62 site_id = node['site_id']
63 site = Sites (self.api, [site_id]) [0]
64 # check caller is affiliated with this site
65 if self.caller['person_id'] not in site['person_ids']:
66 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
68 if required_min_role is not None and \
69 min(self.caller['role_ids']) > required_min_role:
70 raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
73 self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]