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