The wrapper will connect to the console, and check in the background if
the instance is paused, unpausing it as necessary.

Signed-off-by: Stephen Shirley <[email protected]>
---
 Makefile.am              |    1 +
 lib/constants.py         |    1 +
 lib/hypervisor/hv_xen.py |    3 ++-
 tools/xm-console-wrapper |   33 +++++++++++++++++++++++++++++++++
 4 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100755 tools/xm-console-wrapper

diff --git a/Makefile.am b/Makefile.am
index f8f836b..82bdf4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -495,6 +495,7 @@ nodist_pkglib_python_scripts = \
 pkglib_SCRIPTS = \
        daemons/daemon-util \
        tools/kvm-ifup \
+       tools/xm-console-wrapper \
        $(pkglib_python_scripts)
 
 nodist_pkglib_SCRIPTS = \
diff --git a/lib/constants.py b/lib/constants.py
index d2450c6..75589bf 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -144,6 +144,7 @@ QUEUE_DIR = DATA_DIR + "/queue"
 DAEMON_UTIL = _autoconf.PKGLIBDIR + "/daemon-util"
 SETUP_SSH = _autoconf.TOOLSDIR + "/setup-ssh"
 KVM_IFUP = _autoconf.PKGLIBDIR + "/kvm-ifup"
+XM_CONSOLE_WRAPPER = _autoconf.PKGLIBDIR + "/xm-console-wrapper"
 ETC_HOSTS = "/etc/hosts"
 DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
 DEFAULT_SHARED_FILE_STORAGE_DIR = _autoconf.SHARED_FILE_STORAGE_DIR
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index dcb7187..33127ef 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -303,7 +303,8 @@ class XenHypervisor(hv_base.BaseHypervisor):
                                    kind=constants.CONS_SSH,
                                    host=instance.primary_node,
                                    user=constants.GANETI_RUNAS,
-                                   command=["xm", "console", instance.name])
+                                   command=[constants.XM_CONSOLE_WRAPPER,
+                                            instance.name])
 
   def Verify(self):
     """Verify the hypervisor.
diff --git a/tools/xm-console-wrapper b/tools/xm-console-wrapper
new file mode 100755
index 0000000..a5085c9
--- /dev/null
+++ b/tools/xm-console-wrapper
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Copyright (C) 2011 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+INSTANCE="$1"
+
+unpause() {
+  ispaused=$(xm list -l "$INSTANCE" 2>/dev/null |
+             sed -n 's/^[[:blank:]]*(state ..\(.\)...)/\1/p')
+  [ "$ispaused" == "p" ] || return
+  # Sleep to allow xm console enough time to connect
+  sleep 3
+  printf "Instance $INSTANCE is paused, unpausing\r\n"
+  xm unpause "$INSTANCE"
+}
+
+unpause &
+xm console "$INSTANCE"
-- 
1.7.3.1

Reply via email to