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.NodeNetworks import NodeNetwork, NodeNetworks
8 from PLC.Auth import Auth
9 from PLC.POD import udp_pod
12 from pcucontrol import reboot
13 external_dependency = True
15 external_dependency = False
17 class RebootNodeWithPCU(Method):
19 Uses the associated PCU to attempt to reboot the given Node.
21 Admins can reboot any node. Techs and PIs can only reboot nodes at
24 Returns 1 if the reboot proceeded without error (Note: this does not guarantee
25 that the reboot is successful).
26 Returns -1 if external dependencies for this call are not available.
27 Returns "error string" if the reboot failed with a specific message.
30 roles = ['admin', 'pi', 'tech']
34 Mixed(Node.fields['node_id'],
35 Node.fields['hostname'])
38 returns = Parameter(int, '1 if successful')
40 def call(self, auth, node_id_or_hostname):
41 # Get account information
42 nodes = Nodes(self.api, [node_id_or_hostname])
44 raise PLCInvalidArgument, "No such node"
48 # Authenticated function
49 assert self.caller is not None
51 # If we are not an admin, make sure that the caller is a
52 # member of the site at which the node is located.
53 if 'admin' not in self.caller['roles']:
54 if node['site_id'] not in self.caller['site_ids']:
55 raise PLCPermissionDenied, "Not allowed to reboot nodes from specified site"
57 # Verify that the node has pcus associated with it.
58 pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
60 raise PLCInvalidArgument, "No PCUs associated with Node"
64 if not external_dependency:
65 raise PLCNotImplemented, "Could not load external module to attempt reboot"
67 # model, hostname, port,
68 # i = pcu['node_ids'].index(node['node_id'])
70 ret = reboot.reboot_api(node, pcu)
72 self.event_objects = {'Node': [node['node_id']]}
73 self.message = "RebootNodeWithPCU called"