Switch the instance_reboot rpc to (status, data)
authorIustin Pop <iustin@google.com>
Thu, 12 Feb 2009 07:30:06 +0000 (07:30 +0000)
committerIustin Pop <iustin@google.com>
Thu, 12 Feb 2009 07:30:06 +0000 (07:30 +0000)
This small patch changes the return type from this RPC call to include
status information and renames the backend method to match the RPC call
name.

Reviewed-by: ultrotter

daemons/ganeti-noded
lib/backend.py
lib/cmdlib.py

index 0337dca..f2b85e7 100755 (executable)
@@ -446,7 +446,7 @@ class NodeHttpServer(http.server.HttpServer):
     instance = objects.Instance.FromDict(params[0])
     reboot_type = params[1]
     extra_args = params[2]
-    return backend.RebootInstance(instance, reboot_type, extra_args)
+    return backend.InstanceReboot(instance, reboot_type, extra_args)
 
   @staticmethod
   def perspective_instance_info(params):
index 9ebab3b..48d0dc8 100644 (file)
@@ -939,7 +939,7 @@ def ShutdownInstance(instance):
   return True
 
 
-def RebootInstance(instance, reboot_type, extra_args):
+def InstanceReboot(instance, reboot_type, extra_args):
   """Reboot an instance.
 
   @type instance: L{objects.Instance}
@@ -961,27 +961,30 @@ def RebootInstance(instance, reboot_type, extra_args):
   running_instances = GetInstanceList([instance.hypervisor])
 
   if instance.name not in running_instances:
-    logging.error("Cannot reboot instance that is not running")
-    return False
+    msg = "Cannot reboot instance %s that is not running" % instance.name
+    logging.error(msg)
+    return (False, msg)
 
   hyper = hypervisor.GetHypervisor(instance.hypervisor)
   if reboot_type == constants.INSTANCE_REBOOT_SOFT:
     try:
       hyper.RebootInstance(instance)
     except errors.HypervisorError, err:
-      logging.exception("Failed to soft reboot instance")
-      return False
+      msg = "Failed to soft reboot instance %s: %s" % (instance.name, err)
+      logging.error(msg)
+      return (False, msg)
   elif reboot_type == constants.INSTANCE_REBOOT_HARD:
     try:
       ShutdownInstance(instance)
       StartInstance(instance, extra_args)
     except errors.HypervisorError, err:
-      logging.exception("Failed to hard reboot instance")
-      return False
+      msg = "Failed to hard reboot instance %s: %s" % (instance.name, err)
+      logging.error(msg)
+      return (False, msg)
   else:
-    raise errors.ParameterError("reboot_type invalid")
+    return (False, "Invalid reboot_type received: %s" % (reboot_type,))
 
-  return True
+  return (True, "Reboot successful")
 
 
 def MigrationInfo(instance):
index b709455..954fd1d 100644 (file)
@@ -2792,8 +2792,9 @@ class LURebootInstance(LogicalUnit):
                        constants.INSTANCE_REBOOT_HARD]:
       result = self.rpc.call_instance_reboot(node_current, instance,
                                              reboot_type, extra_args)
-      if result.failed or not result.data:
-        raise errors.OpExecError("Could not reboot instance")
+      msg = result.RemoteFailMsg()
+      if msg:
+        raise errors.OpExecError("Could not reboot instance: %s" % msg)
     else:
       if not self.rpc.call_instance_shutdown(node_current, instance):
         raise errors.OpExecError("could not shutdown instance for full reboot")