Revision 3b59ec02 lib/hypervisor/hv_kvm.py
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
1020 | 1020 |
|
1021 | 1021 |
""" |
1022 | 1022 |
# pylint: disable=R0912,R0914,R0915 |
1023 |
kvmhelp = self._GetKVMHelpOutput() |
|
1024 | 1023 |
hvp = instance.hvparams |
1024 |
kvmhelp = self._GetKVMHelpOutput(constants.KVM_PATH) |
|
1025 | 1025 |
|
1026 | 1026 |
pidfile = self._InstancePidFile(instance.name) |
1027 | 1027 |
kvm = constants.KVM_PATH |
... | ... | |
1051 | 1051 |
|
1052 | 1052 |
mversion = hvp[constants.HV_KVM_MACHINE_VERSION] |
1053 | 1053 |
if not mversion: |
1054 |
mversion = self._GetDefaultMachineVersion() |
|
1054 |
mversion = self._GetDefaultMachineVersion(constants.KVM_PATH)
|
|
1055 | 1055 |
kvm_cmd.extend(["-M", mversion]) |
1056 | 1056 |
|
1057 | 1057 |
kernel_path = hvp[constants.HV_KERNEL_PATH] |
... | ... | |
1453 | 1453 |
kvm_cmd, kvm_nics, up_hvp = kvm_runtime |
1454 | 1454 |
up_hvp = objects.FillDict(conf_hvp, up_hvp) |
1455 | 1455 |
|
1456 |
kvmhelp = self._GetKVMHelpOutput() |
|
1456 |
kvmhelp = self._GetKVMHelpOutput(constants.KVM_PATH)
|
|
1457 | 1457 |
_, v_major, v_min, _ = self._ParseKVMVersion(kvmhelp) |
1458 | 1458 |
|
1459 | 1459 |
# We know it's safe to run as a different user upon migration, so we'll use |
... | ... | |
1492 | 1492 |
nic_model = "virtio" |
1493 | 1493 |
|
1494 | 1494 |
if up_hvp[constants.HV_VHOST_NET]: |
1495 |
# vhost_net is only available from version 0.13.0 or newer
|
|
1495 |
# check for vhost_net support
|
|
1496 | 1496 |
if self._VHOST_RE.search(kvmhelp): |
1497 | 1497 |
tap_extra = ",vhost=on" |
1498 | 1498 |
else: |
... | ... | |
1682 | 1682 |
return (v_all, v_maj, v_min, v_rev) |
1683 | 1683 |
|
1684 | 1684 |
@classmethod |
1685 |
def _GetKVMHelpOutput(cls): |
|
1685 |
def _GetKVMHelpOutput(cls, kvm_path):
|
|
1686 | 1686 |
"""Return the KVM help output. |
1687 | 1687 |
|
1688 | 1688 |
@return: output of kvm --help |
1689 | 1689 |
@raise errors.HypervisorError: when the KVM help output cannot be retrieved |
1690 | 1690 |
|
1691 | 1691 |
""" |
1692 |
result = utils.RunCmd([constants.KVM_PATH, "--help"])
|
|
1692 |
result = utils.RunCmd([kvm_path, "--help"])
|
|
1693 | 1693 |
if result.failed: |
1694 | 1694 |
raise errors.HypervisorError("Unable to get KVM help output") |
1695 | 1695 |
return result.output |
1696 | 1696 |
|
1697 | 1697 |
@classmethod |
1698 |
def _GetKVMVersion(cls): |
|
1698 |
def _GetKVMVersion(cls, kvm_path):
|
|
1699 | 1699 |
"""Return the installed KVM version. |
1700 | 1700 |
|
1701 | 1701 |
@return: (version, v_maj, v_min, v_rev) |
1702 | 1702 |
@raise errors.HypervisorError: when the KVM version cannot be retrieved |
1703 | 1703 |
|
1704 | 1704 |
""" |
1705 |
return cls._ParseKVMVersion(cls._GetKVMHelpOutput()) |
|
1705 |
return cls._ParseKVMVersion(cls._GetKVMHelpOutput(kvm_path))
|
|
1706 | 1706 |
|
1707 | 1707 |
def StopInstance(self, instance, force=False, retry=False, name=None): |
1708 | 1708 |
"""Stop an instance. |
... | ... | |
1723 | 1723 |
self._CallMonitorCommand(name, "system_powerdown") |
1724 | 1724 |
|
1725 | 1725 |
@classmethod |
1726 |
def _GetDefaultMachineVersion(cls): |
|
1726 |
def _GetDefaultMachineVersion(cls, kvm_path):
|
|
1727 | 1727 |
"""Return the default hardware revision (e.g. pc-1.1) |
1728 | 1728 |
|
1729 | 1729 |
""" |
1730 |
result = utils.RunCmd([constants.KVM_PATH, "-M", "?"])
|
|
1730 |
result = utils.RunCmd([kvm_path, "-M", "?"])
|
|
1731 | 1731 |
if result.failed: |
1732 | 1732 |
raise errors.HypervisorError("Unable to get default hardware revision") |
1733 | 1733 |
match = cls._DEFAULT_MACHINE_VERSION_RE.search(result.output) |
... | ... | |
1937 | 1937 |
|
1938 | 1938 |
""" |
1939 | 1939 |
result = self.GetLinuxNodeInfo() |
1940 |
_, v_major, v_min, v_rev = self._GetKVMVersion() |
|
1940 |
_, v_major, v_min, v_rev = self._GetKVMVersion(constants.KVM_PATH)
|
|
1941 | 1941 |
result[constants.HV_NODEINFO_KEY_VERSION] = (v_major, v_min, v_rev) |
1942 | 1942 |
return result |
1943 | 1943 |
|
... | ... | |
2091 | 2091 |
" only one of them can be used at a" |
2092 | 2092 |
" given time.") |
2093 | 2093 |
|
2094 |
# KVM version should be >= 0.14.0
|
|
2095 |
kvmhelp = cls._GetKVMHelpOutput() |
|
2094 |
# check that KVM supports SPICE
|
|
2095 |
kvmhelp = cls._GetKVMHelpOutput(constants.KVM_PATH)
|
|
2096 | 2096 |
if not cls._SPICE_RE.search(kvmhelp): |
2097 | 2097 |
raise errors.HypervisorError("spice is configured, but it is not" |
2098 | 2098 |
" supported according to kvm --help") |
Also available in: Unified diff