Revision 6e043e60
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
581 | 581 |
_KVM_NETWORK_SCRIPT, |
582 | 582 |
] |
583 | 583 |
|
584 |
# Supported kvm options to get output from |
|
585 |
_KVMOPT_HELP = "help" |
|
586 |
_KVMOPT_MLIST = "mlist" |
|
587 |
_KVMOPTS_CMDS = { |
|
588 |
_KVMOPT_HELP: ["--help"], |
|
589 |
_KVMOPT_MLIST: ["-M", "?"], |
|
590 |
} |
|
591 |
|
|
584 | 592 |
def __init__(self): |
585 | 593 |
hv_base.BaseHypervisor.__init__(self) |
586 | 594 |
# Let's make sure the directories we need exist, even if the RUN_DIR lives |
... | ... | |
1642 | 1650 |
""" |
1643 | 1651 |
self._CheckDown(instance.name) |
1644 | 1652 |
kvmpath = instance.hvparams[constants.HV_KVM_PATH] |
1645 |
kvmhelp = self._GetKVMHelpOutput(kvmpath)
|
|
1653 |
kvmhelp = self._GetKVMOutput(kvmpath, self._KVMOPT_HELP)
|
|
1646 | 1654 |
kvm_runtime = self._GenerateKVMRuntime(instance, block_devices, |
1647 | 1655 |
startup_paused, kvmhelp) |
1648 | 1656 |
self._SaveKVMRuntime(instance, kvm_runtime) |
... | ... | |
1690 | 1698 |
return (v_all, v_maj, v_min, v_rev) |
1691 | 1699 |
|
1692 | 1700 |
@classmethod |
1693 |
def _GetKVMHelpOutput(cls, kvm_path):
|
|
1694 |
"""Return the KVM help output.
|
|
1701 |
def _GetKVMOutput(cls, kvm_path, option):
|
|
1702 |
"""Return the output of a kvm invocation
|
|
1695 | 1703 |
|
1696 |
@return: output of kvm --help
|
|
1704 |
@return: output a supported kvm invocation
|
|
1697 | 1705 |
@raise errors.HypervisorError: when the KVM help output cannot be retrieved |
1698 | 1706 |
|
1699 | 1707 |
""" |
1700 |
result = utils.RunCmd([kvm_path, "--help"]) |
|
1708 |
assert option in cls._KVMOPTS_CMDS, "Invalid output option" |
|
1709 |
|
|
1710 |
result = utils.RunCmd([kvm_path] + cls._KVMOPTS_CMDS[option]) |
|
1701 | 1711 |
if result.failed: |
1702 |
raise errors.HypervisorError("Unable to get KVM help output") |
|
1712 |
raise errors.HypervisorError("Unable to get KVM % output" % |
|
1713 |
' '.join(cls._KVMOPTS_CMDS[option])) |
|
1703 | 1714 |
return result.output |
1704 | 1715 |
|
1705 | 1716 |
@classmethod |
... | ... | |
1710 | 1721 |
@raise errors.HypervisorError: when the KVM version cannot be retrieved |
1711 | 1722 |
|
1712 | 1723 |
""" |
1713 |
return cls._ParseKVMVersion(cls._GetKVMHelpOutput(kvm_path)) |
|
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 |
|
1724 |
return cls._ParseKVMVersion(cls._GetKVMOutput(kvm_path, cls._KVMOPT_HELP)) |
|
1727 | 1725 |
|
1728 | 1726 |
@classmethod |
1729 | 1727 |
def _GetDefaultMachineVersion(cls, kvm_path): |
1730 | 1728 |
"""Return the default hardware revision (e.g. pc-1.1) |
1731 | 1729 |
|
1732 | 1730 |
""" |
1733 |
output = cls._GetKVMSupportedMachinesOutput(kvm_path)
|
|
1731 |
output = cls._GetKVMOutput(kvm_path, cls._KVMOPT_MLIST)
|
|
1734 | 1732 |
match = cls._DEFAULT_MACHINE_VERSION_RE.search(output) |
1735 | 1733 |
if match: |
1736 | 1734 |
return match.group(1) |
... | ... | |
1784 | 1782 |
# ...and finally we can save it again, and execute it... |
1785 | 1783 |
self._SaveKVMRuntime(instance, kvm_runtime) |
1786 | 1784 |
kvmpath = instance.hvparams[constants.HV_KVM_PATH] |
1787 |
kvmhelp = self._GetKVMHelpOutput(kvmpath)
|
|
1785 |
kvmhelp = self._GetKVMOutput(kvmpath, self._KVMOPT_HELP)
|
|
1788 | 1786 |
self._ExecuteKVMRuntime(instance, kvm_runtime, kvmhelp) |
1789 | 1787 |
|
1790 | 1788 |
def MigrationInfo(self, instance): |
... | ... | |
1812 | 1810 |
kvm_runtime = self._LoadKVMRuntime(instance, serialized_runtime=info) |
1813 | 1811 |
incoming_address = (target, instance.hvparams[constants.HV_MIGRATION_PORT]) |
1814 | 1812 |
kvmpath = instance.hvparams[constants.HV_KVM_PATH] |
1815 |
kvmhelp = self._GetKVMHelpOutput(kvmpath)
|
|
1813 |
kvmhelp = self._GetKVMOutput(kvmpath, self._KVMOPT_HELP)
|
|
1816 | 1814 |
self._ExecuteKVMRuntime(instance, kvm_runtime, kvmhelp, |
1817 | 1815 |
incoming=incoming_address) |
1818 | 1816 |
|
... | ... | |
2124 | 2122 |
" given time.") |
2125 | 2123 |
|
2126 | 2124 |
# check that KVM supports SPICE |
2127 |
kvmhelp = cls._GetKVMHelpOutput(kvm_path)
|
|
2125 |
kvmhelp = cls._GetKVMOutput(kvm_path, cls._KVMOPT_HELP)
|
|
2128 | 2126 |
if not cls._SPICE_RE.search(kvmhelp): |
2129 | 2127 |
raise errors.HypervisorError("spice is configured, but it is not" |
2130 | 2128 |
" supported according to kvm --help") |
... | ... | |
2139 | 2137 |
|
2140 | 2138 |
machine_version = hvparams[constants.HV_KVM_MACHINE_VERSION] |
2141 | 2139 |
if machine_version: |
2142 |
output = cls._GetKVMSupportedMachinesOutput(kvm_path)
|
|
2140 |
output = cls._GetKVMOutput(kvm_path, cls._KVMOPT_MLIST)
|
|
2143 | 2141 |
if not cls._CHECK_MACHINE_VERSION_RE(machine_version).search(output): |
2144 | 2142 |
raise errors.HypervisorError("Unsupported machine version: %s" % |
2145 | 2143 |
machine_version) |
Also available in: Unified diff