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 DeleteNodeFromPCU(Method):
13 Deletes a node from a PCU.
15 Non-admins may only update PCUs at their sites.
17 Returns 1 if successful, faults otherwise.
20 roles = ['admin', 'pi', 'tech']
24 Mixed(Node.fields['node_id'],
25 Node.fields['hostname']),
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, node_id_or_hostname, pcu_id):
33 nodes = Nodes(self.api, [node_id_or_hostname])
35 raise PLCInvalidArgument, "No such node"
40 pcus = PCUs(self.api, [pcu_id])
42 raise PLCInvalidArgument, "No such PCU"
46 if 'admin' not in self.caller['roles']:
48 sites = Sites(self.api, self.caller['site_ids'])
50 if pcu['pcu_id'] in site['pcu_ids']:
54 raise PLCPermissionDenied, "Not allowed to update that PCU"
56 # Removed node from PCU
58 if node['node_id'] in pcu['node_ids']:
62 self.event_objects = {'PCU': [pcu['pcu_id']],
63 'Node': [node['node_id']]}
64 self.message = 'Node %d removed from PCU %d' % \
65 (node['node_id'], pcu['pcu_id'])