1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import PasswordAuth
5 from PLC.Nodes import Node, Nodes
6 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
8 class AdmDeleteNodeNetwork(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 Admins 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(Node.fields['node_id'],
24 Node.fields['hostname']),
25 Mixed(NodeNetwork.fields['nodenetwork_id'],
26 NodeNetwork.fields['hostname'])
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, node_id_or_hostname, nodenetwork_id_or_hostname):
32 # Get node network information
33 nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
35 raise PLCInvalidArgument, "No such node network"
36 nodenetwork = nodenetworks[0]
38 # Get node information
39 nodes = Nodes(self.api, [node_id_or_hostname]).values()
41 raise PLCInvalidArgument, "No such node"
44 # Check if node network is associated with specified node
45 if node['node_id'] != nodenetwork['node_id'] or \
46 nodenetwork['nodenetwork_id'] not in node['nodenetwork_ids']:
47 raise PLCInvalidArgument, "Node network not associated with node"
49 # Authenticated functino
50 assert self.caller is not None
52 # If we are not an admin, make sure that the caller is a
53 # member of the site at which the node is located.
54 if 'admin' not in self.caller['roles']:
55 if node['site_id'] not in self.caller['site_ids']:
56 raise PLCPermissionDenied, "Not allowed to delete this node network"