diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py index 158662c8f3551e6b5d6c9d00bb58a2e296065dc3..7a685140c2436e616c7bf7db37b1aad109fc1ad5 100644 --- a/lib/client/gnt_instance.py +++ b/lib/client/gnt_instance.py @@ -889,18 +889,26 @@ def ConnectToInstanceConsole(opts, args): """ instance_name = args[0] - op = opcodes.OpInstanceConsole(instance_name=instance_name) - cl = GetClient() try: cluster_name = cl.QueryConfigValues(["cluster_name"])[0] - console_data = SubmitOpCode(op, opts=opts, cl=cl) + ((console_data, oper_state), ) = \ + cl.QueryInstances([instance_name], ["console", "oper_state"], False) finally: # Ensure client connection is closed while external commands are run cl.Close() del cl + if not console_data: + if oper_state: + # Instance is running + raise errors.OpExecError("Console information for instance %s is" + " unavailable" % instance_name) + else: + raise errors.OpExecError("Instance %s is not running, can't get console" % + instance_name) + return _DoConsole(objects.InstanceConsole.FromDict(console_data), opts.show_command, cluster_name)