2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Nodes import Node, Nodes
6 from PLC.PCUs import PCU, PCUs
7 from PLC.Sites import Site, Sites
8 from PLC.Auth import Auth
10 class DeleteNodeFromPCU(Method):
12 Deletes a node from a PCU.
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']),
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, node_id_or_hostname, pcu_id):
32 nodes = Nodes(self.api, [node_id_or_hostname])
34 raise PLCInvalidArgument, "No such node"
39 pcus = PCUs(self.api, [pcu_id])
41 raise PLCInvalidArgument, "No such PCU"
45 if 'admin' not in self.caller['roles']:
47 sites = Sites(self.api, self.caller['site_ids'])
49 if pcu['pcu_id'] in site['pcu_ids']:
53 raise PLCPermissionDenied, "Not allowed to update that PCU"
55 # Removed node from PCU
57 if node['node_id'] in pcu['node_ids']:
61 self.event_objects = {'PCU': [pcu['pcu_id']],
62 'Node': [node['node_id']]}
63 self.message = 'Node %d removed from PCU %d' % \
64 (node['node_id'], pcu['pcu_id'])