add backward compatible pcu functions
[plcapi.git] / PLC / Methods / AdmGetPowerControlUnitNodes.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.PCUs import PCU, PCUs
5 from PLC.Auth import PasswordAuth
6 from PLC.Methods.GetPCUs import GetPCUs
7
8 class AdmGetPowerControlUnitNodes(GetPCUs):
9     """
10     Deprecated. See GetPCUs.
11
12     Returns a list of the nodes, and the ports they are assigned to,
13     on the specified PCU.
14     
15     Admin may query all PCUs. Non-admins may only query the PCUs at
16     their sites.
17     """
18
19     roles = ['admin', 'pi', 'tech']
20
21     accepts = [
22         PasswordAuth(),
23         PCU.fields['pcu_id']
24         ]
25
26     returns = [{'node_id': Parameter(int, "Node identifier"),
27                 'port_number': Parameter(int, "Port number")}]
28
29     def call(self, auth, pcu_id):
30         pcus = GetPCUs.call(self, auth, [pcu_id])
31         if not pcus:
32             raise PLCInvalidArgument, "No such PCU"
33         pcu = pcus[0]
34
35         return [{'node_id': node_id, 'port_number': port} \
36                 for (node_id, port) in zip(pcu['node_ids'], pcu['ports'])]