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