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 DeleteNodeFromPCU(Method):
10 Deletes a node from a PCU.
12 Non-admins may only update PCUs at their sites.
14 Returns 1 if successful, faults otherwise.
17 roles = ['admin', 'pi', 'tech']
21 Mixed(Node.fields['node_id'],
22 Node.fields['hostname']),
26 returns = Parameter(int, '1 if successful')
28 def call(self, auth, node_id_or_hostname, pcu_id):
30 nodes = Nodes(self.api, [node_id_or_hostname])
32 raise PLCInvalidArgument, "No such node"
37 pcus = PCUs(self.api, [pcu_id])
39 raise PLCInvalidArgument, "No such PCU"
43 if 'admin' not in self.caller['roles']:
45 sites = Sites(self.api, self.caller['site_ids'])
47 if pcu['pcu_id'] in site['pcu_ids']:
51 raise PLCPermissionDenied, "Not allowed to update that PCU"
53 # Removed node from PCU
55 if node['node_id'] in pcu['node_ids']:
59 self.event_objects = {'PCU': [pcu['pcu_id']],
60 'Node': [node['node_id']]}
61 self.message = 'Node %d removed from PCU %d' % \
62 (node['node_id'], pcu['pcu_id'])