add a parameter to RebootNodeWithPCU to perform a 'testrun' without rebooting the...
[plcapi.git] / PLC / Methods / RebootNodeWithPCU.py
index 46c8c84..ac5b6b6 100644 (file)
@@ -1,12 +1,14 @@
+# $Id$
+# $URL$
 import socket
 
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
-from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
 from PLC.Auth import Auth
-from PLC.POD import udp_pod
+
+from PLC.Nodes import Node, Nodes
+from PLC.PCUs import PCU, PCUs
 
 try:
        from pcucontrol import reboot
@@ -32,17 +34,21 @@ class RebootNodeWithPCU(Method):
     accepts = [
         Auth(),
         Mixed(Node.fields['node_id'],
-              Node.fields['hostname'])
+              Node.fields['hostname']),
+        Parameter(bool, "Run as a test, or as a real reboot", nullok = True)
         ]
 
     returns = Parameter(int, '1 if successful')
 
-    def call(self, auth, node_id_or_hostname):
+    def call(self, auth, node_id_or_hostname, testrun=None):
         # Get account information
         nodes = Nodes(self.api, [node_id_or_hostname])
         if not nodes:
             raise PLCInvalidArgument, "No such node"
 
+        if testrun is None:
+            testrun = False
+
         node = nodes[0]
 
         # Authenticated function
@@ -54,20 +60,20 @@ class RebootNodeWithPCU(Method):
             if node['site_id'] not in self.caller['site_ids']:
                 raise PLCPermissionDenied, "Not allowed to reboot nodes from specified site"
 
-               # Verify that the node has pcus associated with it.
-               pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
+       # Verify that the node has pcus associated with it.
+       pcus = PCUs(self.api, {'pcu_id' : node['pcu_ids']} )
         if not pcus:
             raise PLCInvalidArgument, "No PCUs associated with Node"
 
-               pcu = pcus[0]
+       pcu = pcus[0]
 
-               if not external_dependency:
+       if not external_dependency:
             raise PLCNotImplemented, "Could not load external module to attempt reboot"
 
-               # model, hostname, port, 
-               # i = pcu['node_ids'].index(node['node_id'])
-               # p = pcu['ports'][i]
-               ret = reboot.reboot_api(node, pcu)
+       # model, hostname, port, 
+       # i = pcu['node_ids'].index(node['node_id'])
+       # p = pcu['ports'][i]
+       ret = reboot.reboot_api(node, pcu, testrun)
 
         self.event_objects = {'Node': [node['node_id']]}
         self.message = "RebootNodeWithPCU called"