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.NodeNetworks import NodeNetwork, NodeNetworks
8 class DeleteNodeNetwork(Method):
10 Delete an existing Node Network. Nodenetwork_id must be associated to
11 node_id and not be associated with a different node.
13 ins may delete any node network. PIs and techs can only delete
14 nodenetworks for thier nodes.
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi', 'tech']
23 Mixed(NodeNetwork.fields['nodenetwork_id'],
24 NodeNetwork.fields['ip'])
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, nodenetwork_id_or_ip):
30 # Get node network information
31 nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_ip]).values()
33 raise PLCInvalidArgument, "No such node network"
34 nodenetwork = nodenetworks[0]
36 # Get node information
37 nodes = Nodes(self.api, [nodenetwork['node_id']]).values()
39 raise PLCInvalidArgument, "No such node"
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 node network"