3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Nodes import Node, Nodes
7 from PLC.NodeNetworks import NodeNetwork, NodeNetworks, valid_ip
8 from PLC.Auth import PasswordAuth
10 class AdmQueryNode(Method):
12 Deprecated. Functionality can be implemented with GetNodes and
18 roles = ['admin', 'pi', 'user', 'tech']
22 {'node_hostname': Node.fields['hostname'],
23 'nodenetwork_ip': NodeNetwork.fields['ip'],
24 'nodenetwork_mac': NodeNetwork.fields['mac'],
25 'nodenetwork_method': NodeNetwork.fields['method']}
28 returns = [Node.fields['node_id']]
30 def call(self, auth, search_vals):
31 # Get possible nodenetworks
32 if 'node_hostname' in search_vals:
33 nodes = Nodes(self.api, [search_vals['node_hostname']]).values()
37 # No network interface filters specified
38 if 'nodenetwork_ip' not in search_vals and \
39 'nodenetwork_mac' not in search_vals and \
40 'nodenetwork_method' not in search_vals:
41 return [nodes[0]['node_id']]
43 if nodes[0]['nodenetwork_ids']:
44 nodenetworks = NodeNetworks(self.api, nodes[0]['nodenetwork_ids']).values()
48 nodenetworks = NodeNetworks(self.api).values()
50 if 'nodenetwork_ip' in search_vals:
51 if not valid_ip(search_vals['nodenetwork_ip']):
52 raise PLCInvalidArgument, "Invalid IP address"
53 nodenetworks = filter(lambda nodenetwork: \
54 socket.inet_aton(nodenetwork['ip']) == socket.inet_aton(search_vals['nodenetwork_ip']),
57 if 'nodenetwork_mac' in search_vals:
58 nodenetworks = filter(lambda nodenetwork: \
59 nodenetwork['mac'].lower() == search_vals['nodenetwork_mac'].lower(),
62 if 'nodenetwork_method' in search_vals:
63 nodenetworks = filter(lambda nodenetwork: \
64 nodenetwork['method'].lower() == search_vals['nodenetwork_method'].lower(),
67 return [nodenetwork['node_id'] for nodenetwork in nodenetworks]