gnt-instance console: Use query instead of opcode
authorMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 06:14:39 +0000 (08:14 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 10:29:06 +0000 (12:29 +0200)
This means opening the console no longer requires the instance lock,
allowing it to be used during long-running operations (e.g. replacing a
disk).

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/client/gnt_instance.py

index 158662c..7a68514 100644 (file)
@@ -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)