Branch 5.0 for module PLCAPI created from tag PLCAPI-4.2-8
[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 Auth
6
7 class AdmGetPowerControlUnitNodes(Method):
8     """
9     Deprecated. See GetPCUs.
10
11     Returns a list of the nodes, and the ports they are assigned to,
12     on the specified PCU.
13     
14     Admin may query all PCUs. Non-admins may only query the PCUs at
15     their sites.
16     """
17
18     status = "deprecated"
19
20     roles = ['admin', 'pi', 'tech']
21
22     accepts = [
23         Auth(),
24         PCU.fields['pcu_id']
25         ]
26
27     returns = [{'node_id': Parameter(int, "Node identifier"),
28                 'port_number': Parameter(int, "Port number")}]
29
30     def call(self, auth, pcu_id):
31         pcus = PCUs(self.api, [pcu_id])
32         if not pcus:
33             raise PLCInvalidArgument, "No such PCU"
34         pcu = pcus[0]
35
36         if 'admin' not in self.caller['roles']:
37             if pcu['site_id'] not in self.caller['site_ids']:
38                 raise PLCPermissionDenied, "Not allowed to view that PCU"
39
40         return [{'node_id': node_id, 'port_number': port} \
41                 for (node_id, port) in zip(pcu['node_ids'], pcu['ports'])]