1 from PLC.Faults import *
2 from PLC.Auth import Auth
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Table import Row
7 from PLC.Nodes import Node, Nodes
8 from PLC.Interfaces import Interface, Interfaces
9 from PLC.Methods.DeleteIpAddress import DeleteIpAddress
11 class DeleteInterface(Method):
13 Deletes an existing interface.
15 Admins may delete any interface. PIs and techs may only delete
16 interface interfaces associated with nodes at their sites.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi', 'tech']
25 Interface.fields['interface_id']
28 returns = Parameter(int, '1 if successful')
31 def call(self, auth, interface_id):
33 # Get interface information
34 interfaces = Interfaces(self.api, [interface_id])
36 raise PLCInvalidArgument, "No such interface %r"%interface_id
37 interface = interfaces[0]
39 # Get node information
40 nodes = Nodes(self.api, [interface['node_id']])
42 raise PLCInvalidArgument, "No such node %r"%node_id
45 # Authenticated functino
46 assert self.caller is not None
48 # If we are not an admin, make sure that the caller is a
49 # member of the site at which the node is located.
50 if 'admin' not in self.caller['roles']:
51 if node['site_id'] not in self.caller['site_ids']:
52 raise PLCPermissionDenied, "Not allowed to delete this interface"
54 for ip_address_id in interface['ip_address_ids']:
55 DeleteIpAddress(self.api).__call__(auth, ip_address_id)
60 self.event_objects = {'Interface': [interface['interface_id']]}
61 self.message = "Interface %d deleted" % interface['interface_id']