diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index a388ec25424ce43306e87aee1fbfe9db4c49790f..2fd3684e5cd1cf905a6badf448c812691b68da6e 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -549,6 +549,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): _CPU_INFO_CMD = "info cpus" _CONT_CMD = "cont" + _DEFAULT_MACHINE_VERSION_RE = re.compile(r"(\S+).*\(default\)") + ANCILLARY_FILES = [ _KVM_NETWORK_SCRIPT, ] @@ -1003,6 +1005,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): pidfile = self._InstancePidFile(instance.name) kvm = constants.KVM_PATH kvm_cmd = [kvm] + kvm_cmd.extend(["-M", self._GetDefaultMachineVersion()]) # used just by the vnc server, if enabled kvm_cmd.extend(["-name", instance.name]) kvm_cmd.extend(["-m", instance.beparams[constants.BE_MAXMEM]]) @@ -1654,6 +1657,21 @@ class KVMHypervisor(hv_base.BaseHypervisor): else: self._CallMonitorCommand(name, "system_powerdown") + @classmethod + def _GetDefaultMachineVersion(cls): + """Return the default hardware revision (e.g. pc-1.1) + + """ + 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" + def CleanupInstance(self, instance_name): """Cleanup after a stopped instance