From 637ce7f9cbd4b689829776094aef275e4eea79c4 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Tue, 27 Jan 2009 11:31:19 +0000 Subject: [PATCH] KVM: implement GetShellCommandForConsole This is a class method, because it calls _InstanceSerial, which is another class method. The patch changes it to classmethod for all the hypervisor classes. Reviewed-by: iustinp --- lib/hypervisor/hv_base.py | 4 ++-- lib/hypervisor/hv_fake.py | 4 ++-- lib/hypervisor/hv_kvm.py | 18 ++++++++++++++---- lib/hypervisor/hv_xen.py | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index ebae830a1..68766908e 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -84,8 +84,8 @@ class BaseHypervisor(object): """ raise NotImplementedError - @staticmethod - def GetShellCommandForConsole(instance): + @classmethod + def GetShellCommandForConsole(cls, instance): """Return a command for connecting to the console of an instance. """ diff --git a/lib/hypervisor/hv_fake.py b/lib/hypervisor/hv_fake.py index 53dc62644..52ef62826 100644 --- a/lib/hypervisor/hv_fake.py +++ b/lib/hypervisor/hv_fake.py @@ -203,8 +203,8 @@ class FakeHypervisor(hv_base.BaseHypervisor): return result - @staticmethod - def GetShellCommandForConsole(instance): + @classmethod + def GetShellCommandForConsole(cls, instance): """Return a command for connecting to the console of an instance. """ diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index c01b391db..0316b1ba5 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -576,13 +576,23 @@ class KVMHypervisor(hv_base.BaseHypervisor): return result - @staticmethod - def GetShellCommandForConsole(instance): + @classmethod + def GetShellCommandForConsole(cls, instance): """Return a command for connecting to the console of an instance. """ - # TODO: we can either try the serial socket or suggest vnc - return "echo Console not available for the kvm hypervisor yet" + # FIXME: The socat shell is not perfect. In particular the way we start + # it ctrl+c will close it, rather than being passed to the other end. + # On the other hand if we pass the option 'raw' (or ignbrk=1) there + # will be no way of exiting socat (except killing it from another shell) + # and ctrl+c doesn't work anyway, printing ^C rather than being + # interpreted by kvm. For now we'll leave it this way, which at least + # allows a minimal interaction and changes on the machine. + socat_shell = ("%s STDIO,echo=0,icanon=0 UNIX-CONNECT:%s" % + (constants.SOCAT_PATH, + utils.ShellQuote(cls._InstanceSerial(instance.name)))) + + return socat_shell def Verify(self): """Verify the hypervisor. diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 46a1359fe..f92b2fe6e 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -232,8 +232,8 @@ class XenHypervisor(hv_base.BaseHypervisor): return result - @staticmethod - def GetShellCommandForConsole(instance): + @classmethod + def GetShellCommandForConsole(cls, instance): """Return a command for connecting to the console of an instance. """ -- GitLab