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.Sites import Site, Sites
7 from PLC.Auth import Auth
9 class AddNodeToPCU(Method):
11 Adds a node to a port on a PCU. Faults if the node has already
12 been added to the PCU or if the port is already in use.
14 Non-admins may only update PCUs at their sites.
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi', 'tech']
23 Mixed(Node.fields['node_id'],
24 Node.fields['hostname']),
26 Parameter(int, 'PCU port number')
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, node_id_or_hostname, pcu_id, port):
33 nodes = Nodes(self.api, [node_id_or_hostname])
35 raise PLCInvalidArgument, "No such node"
38 if node['peer_id'] is not None:
39 raise PLCInvalidArgument, "Not a local node"
42 pcus = PCUs(self.api, [pcu_id])
44 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)
70 self.event_objects = {'Node': [node['node_id']],
71 'PCU': [pcu['pcu_id']]}
72 self.message = 'Node %d added to pcu %d on port %d' % \
73 (node['node_id'], pcu['pcu_id'], port)