Revision 82e3bf85
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
560 | 560 |
_CONT_CMD = "cont" |
561 | 561 |
|
562 | 562 |
_DEFAULT_MACHINE_VERSION_RE = re.compile(r"^(\S+).*\(default\)", re.M) |
563 |
_CHECK_MACHINE_VERSION_RE = \ |
|
564 |
staticmethod(lambda x: re.compile(r"^(%s)[ ]+.*PC" % x, re.M)) |
|
563 | 565 |
|
564 | 566 |
_QMP_RE = re.compile(r"^-qmp\s", re.M) |
565 | 567 |
_SPICE_RE = re.compile(r"^-spice\s", re.M) |
... | ... | |
1710 | 1712 |
""" |
1711 | 1713 |
return cls._ParseKVMVersion(cls._GetKVMHelpOutput(kvm_path)) |
1712 | 1714 |
|
1715 |
@classmethod |
|
1716 |
def _GetKVMSupportedMachinesOutput(cls, kvm_path): |
|
1717 |
"""Return the output regarding supported machine versions. |
|
1718 |
|
|
1719 |
@return: output of kvm -M ? |
|
1720 |
@raise errors.HypervisorError: when the KVM help output cannot be retrieved |
|
1721 |
|
|
1722 |
""" |
|
1723 |
result = utils.RunCmd([kvm_path, "-M", "?"]) |
|
1724 |
if result.failed: |
|
1725 |
raise errors.HypervisorError("Unable to get kvm -M ? output") |
|
1726 |
return result.output |
|
1727 |
|
|
1728 |
@classmethod |
|
1729 |
def _GetDefaultMachineVersion(cls, kvm_path): |
|
1730 |
"""Return the default hardware revision (e.g. pc-1.1) |
|
1731 |
|
|
1732 |
""" |
|
1733 |
output = cls._GetKVMSupportedMachinesOutput(kvm_path) |
|
1734 |
match = cls._DEFAULT_MACHINE_VERSION_RE.search(output) |
|
1735 |
if match: |
|
1736 |
return match.group(1) |
|
1737 |
else: |
|
1738 |
return "pc" |
|
1739 |
|
|
1713 | 1740 |
def StopInstance(self, instance, force=False, retry=False, name=None): |
1714 | 1741 |
"""Stop an instance. |
1715 | 1742 |
|
... | ... | |
1728 | 1755 |
else: |
1729 | 1756 |
self._CallMonitorCommand(name, "system_powerdown") |
1730 | 1757 |
|
1731 |
@classmethod |
|
1732 |
def _GetDefaultMachineVersion(cls, kvm_path): |
|
1733 |
"""Return the default hardware revision (e.g. pc-1.1) |
|
1734 |
|
|
1735 |
""" |
|
1736 |
result = utils.RunCmd([kvm_path, "-M", "?"]) |
|
1737 |
if result.failed: |
|
1738 |
raise errors.HypervisorError("Unable to get default hardware revision") |
|
1739 |
match = cls._DEFAULT_MACHINE_VERSION_RE.search(result.output) |
|
1740 |
if match: |
|
1741 |
return match.group(1) |
|
1742 |
else: |
|
1743 |
return "pc" |
|
1744 |
|
|
1745 | 1758 |
def CleanupInstance(self, instance_name): |
1746 | 1759 |
"""Cleanup after a stopped instance |
1747 | 1760 |
|
... | ... | |
2091 | 2104 |
""" |
2092 | 2105 |
super(KVMHypervisor, cls).ValidateParameters(hvparams) |
2093 | 2106 |
|
2107 |
kvm_path = hvparams[constants.HV_KVM_PATH] |
|
2108 |
|
|
2094 | 2109 |
security_model = hvparams[constants.HV_SECURITY_MODEL] |
2095 | 2110 |
if security_model == constants.HT_SM_USER: |
2096 | 2111 |
username = hvparams[constants.HV_SECURITY_DOMAIN] |
... | ... | |
2109 | 2124 |
" given time.") |
2110 | 2125 |
|
2111 | 2126 |
# check that KVM supports SPICE |
2112 |
kvmhelp = cls._GetKVMHelpOutput(hvparams[constants.HV_KVM_PATH])
|
|
2127 |
kvmhelp = cls._GetKVMHelpOutput(kvm_path)
|
|
2113 | 2128 |
if not cls._SPICE_RE.search(kvmhelp): |
2114 | 2129 |
raise errors.HypervisorError("spice is configured, but it is not" |
2115 | 2130 |
" supported according to kvm --help") |
... | ... | |
2122 | 2137 |
" a valid IP address or interface name" % |
2123 | 2138 |
constants.HV_KVM_SPICE_BIND) |
2124 | 2139 |
|
2140 |
machine_version = hvparams[constants.HV_KVM_MACHINE_VERSION] |
|
2141 |
if machine_version: |
|
2142 |
output = cls._GetKVMSupportedMachinesOutput(kvm_path) |
|
2143 |
if not cls._CHECK_MACHINE_VERSION_RE(machine_version).search(output): |
|
2144 |
raise errors.HypervisorError("Unsupported machine version: %s" % |
|
2145 |
machine_version) |
|
2146 |
|
|
2125 | 2147 |
@classmethod |
2126 | 2148 |
def PowercycleNode(cls): |
2127 | 2149 |
"""KVM powercycle, just a wrapper over Linux powercycle. |
Also available in: Unified diff