From 2876c2d6d975429a6b5a472df0245a264135bb56 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 17 Oct 2011 11:35:52 +0100 Subject: [PATCH] Abstract xen's 'xm' command as a constant Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/constants.py | 1 + lib/hypervisor/hv_xen.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/constants.py b/lib/constants.py index fd9cc7c0b..242fe61ab 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -249,6 +249,7 @@ EXPORT_CONF_FILE = "config.ini" XEN_BOOTLOADER = _autoconf.XEN_BOOTLOADER XEN_KERNEL = _autoconf.XEN_KERNEL XEN_INITRD = _autoconf.XEN_INITRD +XEN_CMD = "xm" KVM_PATH = _autoconf.KVM_PATH SOCAT_PATH = _autoconf.SOCAT_PATH diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 5a4bdb938..290409470 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -89,7 +89,7 @@ class XenHypervisor(hv_base.BaseHypervisor): """Helper function for L{_GetXMList} to run "xm list". """ - result = utils.RunCmd(["xm", "list"]) + result = utils.RunCmd([constants.XEN_CMD, "list"]) if result.failed: logging.error("xm list failed (%s): %s", result.fail_reason, result.output) @@ -185,7 +185,7 @@ class XenHypervisor(hv_base.BaseHypervisor): """ self._WriteConfigFile(instance, block_devices) - cmd = ["xm", "create"] + cmd = [constants.XEN_CMD, "create"] if startup_paused: cmd.extend(["--paused"]) cmd.extend([instance.name]) @@ -204,9 +204,9 @@ class XenHypervisor(hv_base.BaseHypervisor): name = instance.name self._RemoveConfigFile(name) if force: - command = ["xm", "destroy", name] + command = [constants.XEN_CMD, "destroy", name] else: - command = ["xm", "shutdown", name] + command = [constants.XEN_CMD, "shutdown", name] result = utils.RunCmd(command) if result.failed: @@ -223,7 +223,7 @@ class XenHypervisor(hv_base.BaseHypervisor): raise errors.HypervisorError("Failed to reboot instance %s," " not running" % instance.name) - result = utils.RunCmd(["xm", "reboot", instance.name]) + result = utils.RunCmd([constants.XEN_CMD, "reboot", instance.name]) if result.failed: raise errors.HypervisorError("Failed to reboot instance %s: %s, %s" % (instance.name, result.fail_reason, @@ -261,7 +261,7 @@ class XenHypervisor(hv_base.BaseHypervisor): """ # note: in xen 3, memory has changed to total_memory - result = utils.RunCmd(["xm", "info"]) + result = utils.RunCmd([constants.XEN_CMD, "info"]) if result.failed: logging.error("Can't run 'xm info' (%s): %s", result.fail_reason, result.output) @@ -325,7 +325,7 @@ class XenHypervisor(hv_base.BaseHypervisor): For Xen, this verifies that the xend process is running. """ - result = utils.RunCmd(["xm", "info"]) + result = utils.RunCmd([constants.XEN_CMD, "info"]) if result.failed: return "'xm info' failed: %s, %s" % (result.fail_reason, result.output) @@ -432,7 +432,7 @@ class XenHypervisor(hv_base.BaseHypervisor): raise errors.HypervisorError("Remote host %s not listening on port" " %s, cannot migrate" % (target, port)) - args = ["xm", "migrate", "-p", "%d" % port] + args = [constants.XEN_CMD, "migrate", "-p", "%d" % port] if live: args.append("-l") args.extend([instance.name, target]) @@ -461,7 +461,7 @@ class XenHypervisor(hv_base.BaseHypervisor): try: cls.LinuxPowercycle() finally: - utils.RunCmd(["xm", "debug", "R"]) + utils.RunCmd([constants.XEN_CMD, "debug", "R"]) class XenPvmHypervisor(XenHypervisor): -- GitLab