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