3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Nodes import Node, Nodes
7 from PLC.PCUs import PCU, PCUs
8 from PLC.Sites import Site, Sites
9 from PLC.Auth import Auth
11 class AddNodeToPCU(Method):
13 Adds a node to a port on a PCU. Faults if the node has already
14 been added to the PCU or if the port is already in use.
16 Non-admins may only update PCUs at their sites.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi', 'tech']
25 Mixed(Node.fields['node_id'],
26 Node.fields['hostname']),
28 Parameter(int, 'PCU port number')
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, node_id_or_hostname, pcu_id, port):
35 nodes = Nodes(self.api, [node_id_or_hostname])
37 raise PLCInvalidArgument, "No such node"
40 if node['peer_id'] is not None:
41 raise PLCInvalidArgument, "Not a local node"
44 pcus = PCUs(self.api, [pcu_id])
46 raise PLCInvalidArgument, "No such PCU"
49 if 'admin' not in self.caller['roles']:
51 sites = Sites(self.api, self.caller['site_ids'])
53 if pcu['pcu_id'] in site['pcu_ids']:
57 raise PLCPermissionDenied, "Not allowed to update that PCU"
60 if node['node_id'] in pcu['node_ids']:
61 raise PLCInvalidArgument, "Node already controlled by PCU"
63 if node['site_id'] != pcu['site_id']:
64 raise PLCInvalidArgument, "Node is at a different site than this PCU"
66 if port in pcu['ports']:
67 raise PLCInvalidArgument, "PCU port already in use"
69 pcu.add_node(node, port)
72 self.event_objects = {'Node': [node['node_id']],
73 'PCU': [pcu['pcu_id']]}
74 self.message = 'Node %d added to pcu %d on port %d' % \
75 (node['node_id'], pcu['pcu_id'], port)