5 from PLC.Faults import *
6 from PLC.Method import Method
7 from PLC.Parameter import Parameter, Mixed
8 from PLC.Auth import Auth
10 from PLC.Nodes import Node, Nodes
11 from PLC.PCUs import PCU, PCUs
14 from pcucontrol import reboot
15 external_dependency = True
17 external_dependency = False
19 class RebootNodeWithPCU(Method):
21 Uses the associated PCU to attempt to reboot the given Node.
23 Admins can reboot any node. Techs and PIs can only reboot nodes at
26 Returns 1 if the reboot proceeded without error (Note: this does not guarantee
27 that the reboot is successful).
28 Returns -1 if external dependencies for this call are not available.
29 Returns "error string" if the reboot failed with a specific message.
32 roles = ['admin', 'pi', 'tech']
36 Mixed(Node.fields['node_id'],
37 Node.fields['hostname'])
40 returns = Parameter(int, '1 if successful')
42 def call(self, auth, node_id_or_hostname):
43 # Get account information
44 nodes = Nodes(self.api, [node_id_or_hostname])
46 raise PLCInvalidArgument, "No such node"
50 # Authenticated function
51 assert self.caller is not None
53 # If we are not an admin, make sure that the caller is a
54 # member of the site at which the node is located.
55 if 'admin' not in self.caller['roles']:
56 if node['site_id'] not in self.caller['site_ids']:
57 raise PLCPermissionDenied, "Not allowed to reboot nodes from specified site"
59 # Verify that the node has pcus associated with it.
60 pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
62 raise PLCInvalidArgument, "No PCUs associated with Node"
66 if not external_dependency:
67 raise PLCNotImplemented, "Could not load external module to attempt reboot"
69 # model, hostname, port,
70 # i = pcu['node_ids'].index(node['node_id'])
72 ret = reboot.reboot_api(node, pcu)
74 self.event_objects = {'Node': [node['node_id']]}
75 self.message = "RebootNodeWithPCU called"