2 # Thierry Parmentelat - INRIA
5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
10 from PLC.Ilinks import Ilink, Ilinks
11 from PLC.Interfaces import Interface, Interfaces
12 from PLC.Nodes import Node, Nodes
13 from PLC.Sites import Site, Sites
14 from PLC.TagTypes import TagType, TagTypes
16 from PLC.AuthorizeHelpers import AuthorizeHelpers
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 src_if=Interfaces(self.api,ilink['src_interface_id'])[0]
48 dst_if=Interfaces(self.api,ilink['dst_interface_id'])[0]
50 tag_type_id = ilink['tag_type_id']
51 tag_type = TagTypes (self.api,[tag_type_id])[0]
53 # check authorizations
54 if 'admin' in self.caller['roles']:
56 elif not AuthorizeHelpers.caller_may_access_tag_type (self.api, self.caller, tag_type):
57 raise PLCPermissionDenied, "%s, forbidden tag %s"%(self.name,tag_type['tagname'])
58 elif AuthorizeHelpers.interface_belongs_to_person (self.api, src_if, self.caller):
60 elif src_if_id != dst_if_id and AuthorizeHelpers.interface_belongs_to_person (self.api, dst_if, self.caller):
63 raise PLCPermissionDenied, "%s: you must own either the src or dst interface"%self.name
66 self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]