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