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
8 class AddNodeToPCU(Method):
10 Adds a node to a port on a PCU. Faults if the node has already
11 been added to the PCU or if the port is already in use.
13 Non-admins may only update PCUs at their sites.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi', 'tech']
22 Mixed(Node.fields['node_id'],
23 Node.fields['hostname']),
25 Parameter(int, 'PCU port number')
28 returns = Parameter(int, '1 if successful')
32 def call(self, auth, node_id_or_hostname, pcu_id, port):
34 nodes = Nodes(self.api, [node_id_or_hostname])
36 raise PLCInvalidArgument, "No such node"
41 pcus = PCUs(self.api, [pcu_id])
43 raise PLCInvalidArgument, "No such PCU"
47 if 'admin' not in self.caller['roles']:
49 sites = Sites(self.api, self.caller['site_ids'])
51 if pcu['pcu_id'] in site['pcu_ids']:
55 raise PLCPermissionDenied, "Not allowed to update that PCU"
58 if node['node_id'] in pcu['node_ids']:
59 raise PLCInvalidArgument, "Node already controlled by PCU"
61 if node['site_id'] != pcu['site_id']:
62 raise PLCInvalidArgument, "Node is at a different site than this PCU"
64 if port in pcu['ports']:
65 raise PLCInvalidArgument, "PCU port already in use"
67 pcu.add_node(node, port)
69 self.object_ids = [node['node_id'], pcu['pcu_id']]