From 7f83345f2d7c1a37dce65437782b25e8b0745961 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 11 Jan 2013 17:47:47 +0100 Subject: [PATCH] kvm: simplify _GetMachineVersion Use a multiline regexp rather than a single line one, and then split lines in the code. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/hypervisor/hv_kvm.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 2d401efed..94ce5b19f 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -553,7 +553,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): _CPU_INFO_CMD = "info cpus" _CONT_CMD = "cont" - _DEFAULT_MACHINE_VERSION_RE = re.compile(r"(\S+).*\(default\)") + _DEFAULT_MACHINE_VERSION_RE = re.compile(r"^(\S+).*\(default\)", re.M) _QMP_RE = re.compile(r"^-qmp\s", re.M) _SPICE_RE = re.compile(r"^-spice\s", re.M) @@ -1705,12 +1705,11 @@ class KVMHypervisor(hv_base.BaseHypervisor): result = utils.RunCmd([constants.KVM_PATH, "-M", "?"]) if result.failed: raise errors.HypervisorError("Unable to get default hardware revision") - for line in result.output.splitlines(): - match = cls._DEFAULT_MACHINE_VERSION_RE.match(line) - if match: - return match.group(1) - - return "pc" + match = cls._DEFAULT_MACHINE_VERSION_RE.search(result.output) + if match: + return match.group(1) + else: + return "pc" def CleanupInstance(self, instance_name): """Cleanup after a stopped instance -- GitLab