From aca137129f7a4fc935d0be17720ea6c51b5164c7 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 9 Jun 2009 17:52:43 +0200 Subject: [PATCH] Convert instance_list rpc to new style result Since backend.GetInstanceList() is used both as RPC endpoint and as internal function, it can't return (status, value). Instead it returns only valid instance info, and failures are denoted by exceptions; and the ganeti-noded function adds the (True,) status. The patch also fixes a typo. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- daemons/ganeti-noded | 2 +- lib/backend.py | 4 ++-- lib/cmdlib.py | 41 +++++++++++++++++++++++------------------ 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 0678d114d..6ec61dc59 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -476,7 +476,7 @@ class NodeHttpServer(http.server.HttpServer): """Query the list of running instances. """ - return backend.GetInstanceList(params[0]) + return True, backend.GetInstanceList(params[0]) # node -------------------------- diff --git a/lib/backend.py b/lib/backend.py index 14d600d5d..a34364936 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -603,8 +603,8 @@ def GetInstanceList(hypervisor_list): names = hypervisor.GetHypervisor(hname).ListInstances() results.extend(names) except errors.HypervisorError, err: - logging.exception("Error enumerating instances for hypevisor %s", hname) - raise + _Fail("Error enumerating instances (hypervisor %s): %s", + hname, err, exc=True) return results diff --git a/lib/cmdlib.py b/lib/cmdlib.py index cc22e3d2f..1ca4528c1 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2769,14 +2769,14 @@ def _SafeShutdownInstanceDisks(lu, instance): _ShutdownInstanceDisks. """ - ins_l = lu.rpc.call_instance_list([instance.primary_node], - [instance.hypervisor]) - ins_l = ins_l[instance.primary_node] - if ins_l.failed or not isinstance(ins_l.data, list): - raise errors.OpExecError("Can't contact node '%s'" % - instance.primary_node) - - if instance.name in ins_l.data: + pnode = instance.primary_node + ins_l = lu.rpc.call_instance_list([pnode], [instance.hypervisor]) + ins_l = ins_l[pnode] + msg = ins_l.RemoteFailMsg() + if msg: + raise errors.OpExecError("Can't contact node %s: %s" % (pnode, msg)) + + if instance.name in ins_l.payload: raise errors.OpExecError("Instance is running, can't shutdown" " block devices.") @@ -3890,12 +3890,12 @@ class LUMigrateInstance(LogicalUnit): " a bad state)") ins_l = self.rpc.call_instance_list(self.all_nodes, [instance.hypervisor]) for node, result in ins_l.items(): - result.Raise() - if not isinstance(result.data, list): - raise errors.OpExecError("Can't contact node '%s'" % node) + msg = result.RemoteFailMsg() + if msg: + raise errors.OpExecError("Can't contact node %s: %s" % (node, msg)) - runningon_source = instance.name in ins_l[source_node].data - runningon_target = instance.name in ins_l[target_node].data + runningon_source = instance.name in ins_l[source_node].payload + runningon_target = instance.name in ins_l[target_node].payload if runningon_source and runningon_target: raise errors.OpExecError("Instance seems to be running on two nodes," @@ -5010,9 +5010,12 @@ class LUConnectConsole(NoHooksLU): node_insts = self.rpc.call_instance_list([node], [instance.hypervisor])[node] - node_insts.Raise() + msg = node_insts.RemoteFailMsg() + if msg: + raise errors.OpExecError("Can't get node information from %s: %s" % + (node, msg)) - if instance.name not in node_insts.data: + if instance.name not in node_insts.payload: raise errors.OpExecError("Instance %s is not running." % instance.name) logging.debug("Connecting to console of %s on %s", instance.name, node) @@ -6217,9 +6220,11 @@ class LUSetInstanceParams(LogicalUnit): " an instance") ins_l = self.rpc.call_instance_list([pnode], [instance.hypervisor]) ins_l = ins_l[pnode] - if ins_l.failed or not isinstance(ins_l.data, list): - raise errors.OpPrereqError("Can't contact node '%s'" % pnode) - if instance.name in ins_l.data: + msg = ins_l.RemoteFailMsg() + if msg: + raise errors.OpPrereqError("Can't contact node %s: %s" % + (pnode, msg)) + if instance.name in ins_l.payload: raise errors.OpPrereqError("Instance is running, can't remove" " disks.") -- GitLab