This commit was manufactured by cvs2svn to create branch
[plcapi.git] / PLC / Methods / AdmDisassociatePowerControlUnitPort.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Nodes import Node, Nodes
5 from PLC.PCUs import PCU, PCUs
6 from PLC.Auth import Auth
7 from PLC.Methods.DeleteNodeFromPCU import DeleteNodeFromPCU
8
9 class AdmDisassociatePowerControlUnitPort(DeleteNodeFromPCU):
10     """
11     Deprecated. See DeleteNodeFromPCU.
12     """
13
14     status = "deprecated"
15
16     roles = ['admin', 'pi', 'tech']
17
18     accepts = [
19         Auth(),
20         PCU.fields['pcu_id'],
21         Parameter(int, 'PCU port number'),
22         ]
23
24     returns = Parameter(int, '1 if successful')
25
26     def call(self, auth, pcu_id, port):
27         pcus = PCUs(self.api, [pcu_id])
28         if not pcus:
29             raise PLCInvalidArgument, "No such PCU"
30
31         pcu = pcus[0]
32
33         ports = dict(zip(pcu['ports'], pcu['node_ids']))
34         if port not in ports:
35             raise PLCInvalidArgument, "No node on that port or no such port"
36
37         return DeleteNodeFromPCU(self, auth, ports[port], pcu_id)