Commit 440351f8 authored by Andrea Spadaccini's avatar Andrea Spadaccini Committed by Michael Hanselmann
Browse files

Removed code duplication for calls to _GetKVMVersion


Signed-off-by: default avatarAndrea Spadaccini <spadaccio@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 0b0ca0c0
...@@ -518,11 +518,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -518,11 +518,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
"""Generate KVM information to start an instance. """Generate KVM information to start an instance.
""" """
kvm_version = self._GetKVMVersion() _, v_major, v_min, _ = self._GetKVMVersion()
if kvm_version:
_, v_major, v_min, _ = kvm_version
else:
raise errors.HypervisorError("Unable to get KVM version")
pidfile = self._InstancePidFile(instance.name) pidfile = self._InstancePidFile(instance.name)
kvm = constants.KVM_PATH kvm = constants.KVM_PATH
...@@ -816,11 +812,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -816,11 +812,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
kvm_cmd, kvm_nics, up_hvp = kvm_runtime kvm_cmd, kvm_nics, up_hvp = kvm_runtime
up_hvp = objects.FillDict(conf_hvp, up_hvp) up_hvp = objects.FillDict(conf_hvp, up_hvp)
kvm_version = self._GetKVMVersion() _, v_major, v_min, _ = self._GetKVMVersion()
if kvm_version:
_, v_major, v_min, _ = kvm_version
else:
raise errors.HypervisorError("Unable to get KVM version")
# We know it's safe to run as a different user upon migration, so we'll use # We know it's safe to run as a different user upon migration, so we'll use
# the latest conf, from conf_hvp. # the latest conf, from conf_hvp.
...@@ -962,15 +954,16 @@ class KVMHypervisor(hv_base.BaseHypervisor): ...@@ -962,15 +954,16 @@ class KVMHypervisor(hv_base.BaseHypervisor):
def _GetKVMVersion(cls): def _GetKVMVersion(cls):
"""Return the installed KVM version """Return the installed KVM version
@return: (version, v_maj, v_min, v_rev), or None @return: (version, v_maj, v_min, v_rev)
@raise: L{errors.HypervisorError}
""" """
result = utils.RunCmd([constants.KVM_PATH, "--help"]) result = utils.RunCmd([constants.KVM_PATH, "--help"])
if result.failed: if result.failed:
return None raise errors.HypervisorError("Unable to get KVM version")
match = cls._VERSION_RE.search(result.output.splitlines()[0]) match = cls._VERSION_RE.search(result.output.splitlines()[0])
if not match: if not match:
return None raise errors.HypervisorError("Unable to get KVM version")
return (match.group(0), int(match.group(1)), int(match.group(2)), return (match.group(0), int(match.group(1)), int(match.group(2)),
int(match.group(3))) int(match.group(3)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment