3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.PCUs import PCU, PCUs
7 from PLC.Nodes import Node, Nodes
8 from PLC.NodeNetworks import NodeNetwork, NodeNetworks, valid_ip
9 from PLC.Auth import Auth
11 class AdmQueryPowerControlUnit(Method):
13 Deprecated. Functionality can be implemented with GetPCUs or
19 roles = ['admin', 'pi', 'user', 'tech']
23 {'pcu_hostname': PCU.fields['hostname'],
24 'pcu_ip': PCU.fields['ip'],
25 'node_hostname': Node.fields['hostname'],
26 'node_id': Node.fields['node_id']}
29 returns = [PCU.fields['pcu_id']]
31 def call(self, auth, search_vals):
32 # Get all PCUs. This is a stupid function. The API should not
33 # be used for DB mining.
36 if 'pcu_hostname' in search_vals:
37 pcus = filter(lambda pcu: \
38 pcu['hostname'].lower() == search_vals['pcu_hostname'].lower(),
41 if 'pcu_ip' in search_vals:
42 if not valid_ip(search_vals['pcu_ip']):
43 raise PLCInvalidArgument, "Invalid IP address"
44 pcus = filter(lambda pcu: \
45 socket.inet_aton(pcu['ip']) == socket.inet_aton(search_vals['pcu_ip']),
48 if 'node_id' in search_vals:
49 pcus = filter(lambda pcu: \
50 search_vals['node_id'] in pcu['node_ids'],
53 if 'node_hostname' in search_vals:
54 pcus = filter(lambda pcu: \
55 search_vals['node_hostname'] in \
56 [node['hostname'] for node in Nodes(self.api, pcu['node_ids'])],
59 return [pcu['pcu_id'] for pcu in pcus]