From 489fcbe9d69b4d1d32a82d644d914039d7dfeff0 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Thu, 12 Feb 2009 07:30:06 +0000 Subject: [PATCH] Switch the instance_reboot rpc to (status, data) 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 | 2 +- lib/backend.py | 21 ++++++++++++--------- lib/cmdlib.py | 5 +++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 0337dca..f2b85e7 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -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): diff --git a/lib/backend.py b/lib/backend.py index 9ebab3b..48d0dc8 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index b709455..954fd1d 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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") -- 1.7.10.4