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')
30 # needed for generating the doc and prevent conflicts in the xml ids
33 def call(self, auth, interface_id):
35 # Get interface information
36 interfaces = Interfaces(self.api, [interface_id])
38 raise PLCInvalidArgument, "No such interface %r"%interface_id
39 interface = interfaces[0]
41 # Get node information
42 nodes = Nodes(self.api, [interface['node_id']])
44 raise PLCInvalidArgument, "No such node %r"%node_id
47 # Authenticated functino
48 assert self.caller is not None
50 # If we are not an admin, make sure that the caller is a
51 # member of the site at which the node is located.
52 if 'admin' not in self.caller['roles']:
53 if node['site_id'] not in self.caller['site_ids']:
54 raise PLCPermissionDenied, "Not allowed to delete this interface"
56 for ip_address_id in interface['ip_address_ids']:
57 DeleteIpAddress(self.api).__call__(auth, ip_address_id)
62 self.event_objects = {'Interface': [interface['interface_id']]}
63 self.message = "Interface %d deleted" % interface['interface_id']