2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# Some code for parsing libvirt's capabilities XML
|
|
|
|
#
|
2014-03-12 19:36:17 +08:00
|
|
|
# Copyright 2007, 2012-2014 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
# Mark McLoughlin <markmc@redhat.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-10-28 04:59:47 +08:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2014-09-13 03:59:22 +08:00
|
|
|
from . import util
|
2015-04-04 00:40:16 +08:00
|
|
|
from .cpu import CPU as DomainCPU
|
|
|
|
from .xmlbuilder import XMLBuilder, XMLChildProperty
|
|
|
|
from .xmlbuilder import XMLProperty as _XMLProperty
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
# Disable test suite property tracking
|
|
|
|
class XMLProperty(_XMLProperty):
|
|
|
|
_track = False
|
2013-07-07 02:12:13 +08:00
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
class CPUValuesModel(object):
|
|
|
|
"""
|
2014-03-13 03:59:33 +08:00
|
|
|
Single CPU model
|
2013-03-18 05:06:52 +08:00
|
|
|
"""
|
2014-03-13 03:59:33 +08:00
|
|
|
def __init__(self, model):
|
|
|
|
self.model = model
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CPUValuesArch(object):
|
|
|
|
"""
|
|
|
|
Single <arch> instance of valid CPUs
|
|
|
|
"""
|
|
|
|
def __init__(self, arch, node=None):
|
|
|
|
self.arch = arch
|
|
|
|
self.vendors = []
|
|
|
|
self.cpus = []
|
|
|
|
|
|
|
|
if node:
|
|
|
|
self._parseXML(node)
|
|
|
|
|
|
|
|
def _parseXML(self, node):
|
|
|
|
child = node.children
|
|
|
|
while child:
|
|
|
|
if child.name == "vendor":
|
|
|
|
self.vendors.append(child.prop("name"))
|
|
|
|
if child.name == "model":
|
2014-03-13 03:59:33 +08:00
|
|
|
newcpu = CPUValuesModel(child.prop("name"))
|
2013-03-18 05:06:52 +08:00
|
|
|
self.cpus.append(newcpu)
|
|
|
|
|
|
|
|
child = child.next
|
|
|
|
|
|
|
|
self.vendors.sort()
|
|
|
|
|
|
|
|
def get_cpu(self, model):
|
|
|
|
for c in self.cpus:
|
|
|
|
if c.model == model:
|
|
|
|
return c
|
|
|
|
raise ValueError(_("Unknown CPU model '%s'") % model)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2014-03-21 01:48:49 +08:00
|
|
|
class _CPUAPIValues(object):
|
2013-03-18 05:06:52 +08:00
|
|
|
"""
|
2014-03-13 19:52:51 +08:00
|
|
|
Lists valid values for cpu models obtained trough libvirt's getCPUModelNames
|
2013-03-18 05:06:52 +08:00
|
|
|
"""
|
2014-03-13 19:52:51 +08:00
|
|
|
def __init__(self):
|
|
|
|
self._cpus = None
|
|
|
|
|
|
|
|
def get_cpus(self, arch, conn):
|
|
|
|
if self._cpus is not None:
|
|
|
|
return self._cpus
|
|
|
|
|
2014-03-21 01:45:52 +08:00
|
|
|
if (conn and conn.check_support(conn.SUPPORT_CONN_CPU_MODEL_NAMES)):
|
|
|
|
names = conn.getCPUModelNames(arch, 0)
|
|
|
|
|
|
|
|
# Bindings were broke for a long time, so catch -1
|
|
|
|
if names != -1:
|
|
|
|
self._cpus = [CPUValuesModel(i) for i in names]
|
|
|
|
return self._cpus
|
2014-03-13 19:52:51 +08:00
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2014-03-21 01:48:49 +08:00
|
|
|
class _CPUMapFileValues(_CPUAPIValues):
|
2014-03-13 19:52:51 +08:00
|
|
|
"""
|
|
|
|
Fallback method to lists cpu models, parsed directly from libvirt's local
|
|
|
|
cpu_map.xml
|
|
|
|
"""
|
2014-04-05 01:13:20 +08:00
|
|
|
_cpu_filename = "/usr/share/libvirt/cpu_map.xml"
|
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
def __init__(self):
|
2014-03-21 01:48:49 +08:00
|
|
|
_CPUAPIValues.__init__(self)
|
2013-03-18 05:06:52 +08:00
|
|
|
self.archmap = {}
|
2014-04-05 01:13:20 +08:00
|
|
|
xml = file(self._cpu_filename).read()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-11 22:27:02 +08:00
|
|
|
util.parse_node_helper(xml, "cpus",
|
2013-03-18 05:06:52 +08:00
|
|
|
self._parseXML,
|
2013-07-07 02:12:13 +08:00
|
|
|
RuntimeError)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-04-10 23:15:55 +08:00
|
|
|
@staticmethod
|
|
|
|
def update_cpu_filename(name):
|
|
|
|
_CPUMapFileValues._cpu_filename = name
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def _parseXML(self, node):
|
|
|
|
child = node.children
|
|
|
|
while child:
|
|
|
|
if child.name == "arch":
|
|
|
|
arch = child.prop("name")
|
|
|
|
self.archmap[arch] = CPUValuesArch(arch, child)
|
|
|
|
|
|
|
|
child = child.next
|
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
def get_cpus(self, arch, conn):
|
|
|
|
ignore = conn
|
2013-03-18 05:06:52 +08:00
|
|
|
if re.match(r'i[4-9]86', arch):
|
|
|
|
arch = "x86"
|
|
|
|
elif arch == "x86_64":
|
|
|
|
arch = "x86"
|
|
|
|
|
|
|
|
cpumap = self.archmap.get(arch)
|
|
|
|
if not cpumap:
|
|
|
|
cpumap = CPUValuesArch(arch)
|
|
|
|
self.archmap[arch] = cpumap
|
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
return cpumap.cpus
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsCPU(DomainCPU):
|
|
|
|
arch = XMLProperty("./arch")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
# capabilities used to just expose these properties as bools
|
|
|
|
_svm_bool = XMLProperty("./features/svm", is_bool=True)
|
|
|
|
_vmx_bool = XMLProperty("./features/vmx", is_bool=True)
|
|
|
|
_pae_bool = XMLProperty("./features/pae", is_bool=True)
|
|
|
|
_nonpae_bool = XMLProperty("./features/nonpae", is_bool=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
has_feature_block = XMLProperty("./features", is_bool=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
##############
|
|
|
|
# Public API #
|
|
|
|
##############
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
def has_feature(self, name):
|
|
|
|
if name == "svm" and self._svm_bool:
|
|
|
|
return True
|
|
|
|
if name == "vmx" and self._vmx_bool:
|
|
|
|
return True
|
|
|
|
if name == "pae" and self._pae_bool:
|
|
|
|
return True
|
|
|
|
if name == "nonpae" and self._nonpae_bool:
|
|
|
|
return True
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
return name in [f.name for f in self.features]
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
###########################
|
|
|
|
# Caps <topology> parsers #
|
|
|
|
###########################
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsTopologyCPU(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "cpu"
|
|
|
|
id = XMLProperty("./@id")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _TopologyCell(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "cell"
|
|
|
|
id = XMLProperty("./@id")
|
|
|
|
cpus = XMLChildProperty(_CapsTopologyCPU, relative_xpath="./cpus")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsTopology(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "topology"
|
|
|
|
cells = XMLChildProperty(_TopologyCell, relative_xpath="./cells")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
######################################
|
|
|
|
# Caps <host> and <secmodel> parsers #
|
|
|
|
######################################
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsSecmodelBaselabel(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "baselabel"
|
|
|
|
type = XMLProperty("./@type")
|
|
|
|
content = XMLProperty(".")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsSecmodel(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "secmodel"
|
|
|
|
model = XMLProperty("./model")
|
|
|
|
baselabels = XMLChildProperty(_CapsSecmodelBaselabel)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsHost(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "host"
|
|
|
|
secmodels = XMLChildProperty(_CapsSecmodel)
|
|
|
|
cpu = XMLChildProperty(_CapsCPU, is_single=True)
|
|
|
|
topology = XMLChildProperty(_CapsTopology, is_single=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
################################
|
|
|
|
# <guest> and <domain> parsers #
|
|
|
|
################################
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsMachine(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "machine"
|
|
|
|
name = XMLProperty(".")
|
|
|
|
canonical = XMLProperty("./@canonical")
|
2014-09-24 04:05:48 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsDomain(XMLBuilder):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
XMLBuilder.__init__(self, *args, **kwargs)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
self.machines = []
|
|
|
|
for m in self._machines:
|
|
|
|
self.machines.append(m.name)
|
|
|
|
if m.canonical:
|
|
|
|
self.machines.append(m.canonical)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
self._recommended_machine = None
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
_XML_ROOT_NAME = "domain"
|
|
|
|
hypervisor_type = XMLProperty("./@type")
|
|
|
|
emulator = XMLProperty("./emulator")
|
|
|
|
_machines = XMLChildProperty(_CapsMachine)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-24 04:05:48 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
###############
|
|
|
|
# Public APIs #
|
|
|
|
###############
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-09-24 04:05:48 +08:00
|
|
|
def get_recommended_machine(self, conn, capsguest):
|
|
|
|
if self._recommended_machine:
|
|
|
|
return self._recommended_machine
|
|
|
|
|
|
|
|
if not conn.is_test() and not conn.is_qemu():
|
|
|
|
return None
|
|
|
|
|
2015-01-05 10:16:18 +08:00
|
|
|
if capsguest.arch in ["ppc64", "ppc64le"] and "pseries" in self.machines:
|
2014-09-24 04:05:48 +08:00
|
|
|
return "pseries"
|
|
|
|
if capsguest.arch in ["armv7l", "aarch64"]:
|
|
|
|
if "virt" in self.machines:
|
|
|
|
return "virt"
|
|
|
|
if "vexpress-a15" in self.machines:
|
|
|
|
return "vexpress-a15"
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def set_recommended_machine(self, machine):
|
|
|
|
self._recommended_machine = machine
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def is_accelerated(self):
|
|
|
|
return self.hypervisor_type in ["kvm", "kqemu"]
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsGuestFeatures(XMLBuilder):
|
|
|
|
_XML_ROOT_NAME = "features"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
pae = XMLProperty("./pae", is_bool=True)
|
|
|
|
nonpae = XMLProperty("./nonpae", is_bool=True)
|
|
|
|
acpi = XMLProperty("./acpi", is_bool=True)
|
|
|
|
apic = XMLProperty("./apci", is_bool=True)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
class _CapsGuest(XMLBuilder):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
XMLBuilder.__init__(self, *args, **kwargs)
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
self.machines = []
|
|
|
|
for m in self._machines:
|
|
|
|
self.machines.append(m.name)
|
|
|
|
if m.canonical:
|
|
|
|
self.machines.append(m.canonical)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
for d in self.domains:
|
|
|
|
if not d.emulator:
|
|
|
|
d.emulator = self.emulator
|
|
|
|
if not d.machines:
|
|
|
|
d.machines = self.machines
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
_XML_ROOT_NAME = "guest"
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
os_type = XMLProperty("./os_type")
|
|
|
|
arch = XMLProperty("./arch/@name")
|
|
|
|
loader = XMLProperty("./arch/loader")
|
|
|
|
emulator = XMLProperty("./arch/emulator")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
domains = XMLChildProperty(_CapsDomain, relative_xpath="./arch")
|
|
|
|
features = XMLChildProperty(_CapsGuestFeatures, is_single=True)
|
|
|
|
_machines = XMLChildProperty(_CapsMachine, relative_xpath="./arch")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
###############
|
|
|
|
# Public APIs #
|
|
|
|
###############
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
def bestDomainType(self, dtype=None, machine=None):
|
|
|
|
"""
|
|
|
|
Return the recommended domain for use if the user does not explicitly
|
|
|
|
request one.
|
|
|
|
"""
|
|
|
|
domains = []
|
|
|
|
for d in self.domains:
|
|
|
|
d.set_recommended_machine(None)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
if dtype and d.hypervisor_type != dtype.lower():
|
|
|
|
continue
|
|
|
|
if machine and machine not in d.machines:
|
|
|
|
continue
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
if machine:
|
|
|
|
d.set_recommended_machine(machine)
|
|
|
|
domains.append(d)
|
|
|
|
|
|
|
|
if not domains:
|
|
|
|
return None
|
|
|
|
|
|
|
|
priority = ["kvm", "xen", "kqemu", "qemu"]
|
|
|
|
|
|
|
|
for t in priority:
|
|
|
|
for d in domains:
|
|
|
|
if d.hypervisor_type == t:
|
|
|
|
return d
|
|
|
|
|
|
|
|
# Fallback, just return last item in list
|
|
|
|
return domains[-1]
|
|
|
|
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Main capabilities object #
|
|
|
|
############################
|
|
|
|
|
|
|
|
class Capabilities(XMLBuilder):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
XMLBuilder.__init__(self, *args, **kwargs)
|
2013-03-18 05:06:52 +08:00
|
|
|
self._cpu_values = None
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
_XML_ROOT_NAME = "capabilities"
|
|
|
|
|
|
|
|
host = XMLChildProperty(_CapsHost, is_single=True)
|
|
|
|
guests = XMLChildProperty(_CapsGuest)
|
|
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
# Private helpers #
|
|
|
|
###################
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def _is_xen(self):
|
|
|
|
for g in self.guests:
|
|
|
|
if g.os_type != "xen":
|
|
|
|
continue
|
|
|
|
|
|
|
|
for d in g.domains:
|
|
|
|
if d.hypervisor_type == "xen":
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
|
|
|
|
##############
|
|
|
|
# Public API #
|
|
|
|
##############
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def no_install_options(self):
|
|
|
|
"""
|
|
|
|
Return True if there are no install options available
|
|
|
|
"""
|
|
|
|
for g in self.guests:
|
|
|
|
if len(g.domains) > 0:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def hw_virt_supported(self):
|
|
|
|
"""
|
|
|
|
Return True if the machine supports hardware virtualization.
|
|
|
|
|
|
|
|
For some cases (like qemu caps pre libvirt 0.7.4) this info isn't
|
|
|
|
sufficiently provided, so we will return True in cases that we
|
|
|
|
aren't sure.
|
|
|
|
"""
|
2015-04-04 00:40:16 +08:00
|
|
|
# Obvious case of feature being specified
|
|
|
|
if (self.host.cpu.has_feature("vmx") or
|
|
|
|
self.host.cpu.has_feature("svm")):
|
|
|
|
return True
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
has_hvm_guests = False
|
|
|
|
for g in self.guests:
|
|
|
|
if g.os_type == "hvm":
|
|
|
|
has_hvm_guests = True
|
|
|
|
break
|
|
|
|
|
|
|
|
# Xen seems to block the vmx/svm feature bits from cpuinfo?
|
|
|
|
# so make sure no hvm guests are listed
|
|
|
|
if self._is_xen() and has_hvm_guests:
|
|
|
|
return True
|
|
|
|
|
|
|
|
# If there is other features, but no virt bit, then HW virt
|
|
|
|
# isn't supported
|
2015-04-04 00:40:16 +08:00
|
|
|
if self.host.cpu.has_feature_block:
|
2013-03-18 05:06:52 +08:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Xen caps have always shown this info, so if we didn't find any
|
2013-07-01 02:33:01 +08:00
|
|
|
# features, the host really doesn't have the nec support
|
2013-03-18 05:06:52 +08:00
|
|
|
if self._is_xen():
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Otherwise, we can't be sure, because there was a period for along
|
|
|
|
# time that qemu caps gave no indication one way or the other.
|
|
|
|
return True
|
|
|
|
|
|
|
|
def is_kvm_available(self):
|
|
|
|
"""
|
|
|
|
Return True if kvm guests can be installed
|
|
|
|
"""
|
|
|
|
for g in self.guests:
|
|
|
|
if g.os_type != "hvm":
|
|
|
|
continue
|
|
|
|
|
|
|
|
for d in g.domains:
|
|
|
|
if d.hypervisor_type == "kvm":
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_xenner_available(self):
|
|
|
|
"""
|
|
|
|
Return True if xenner install option is available
|
|
|
|
"""
|
|
|
|
for g in self.guests:
|
|
|
|
if g.os_type != "xen":
|
|
|
|
continue
|
|
|
|
|
|
|
|
for d in g.domains:
|
|
|
|
if d.hypervisor_type == "kvm":
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_bios_virt_disabled(self):
|
|
|
|
"""
|
|
|
|
Try to determine if fullvirt may be disabled in the bios.
|
|
|
|
|
|
|
|
Check is basically:
|
|
|
|
- We support HW virt
|
|
|
|
- We appear to be xen
|
|
|
|
- There are no HVM install options
|
|
|
|
|
|
|
|
We don't do this check for KVM, since no KVM options may mean
|
|
|
|
KVM isn't installed or the module isn't loaded (and loading the
|
|
|
|
module will give an appropriate error
|
|
|
|
"""
|
|
|
|
if not self.hw_virt_supported():
|
|
|
|
return False
|
|
|
|
|
|
|
|
if not self._is_xen():
|
|
|
|
return False
|
|
|
|
|
|
|
|
for g in self.guests:
|
|
|
|
if g.os_type == "hvm":
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
def supports_pae(self):
|
|
|
|
"""
|
|
|
|
Return True if capabilities report support for PAE
|
|
|
|
"""
|
2013-03-18 05:06:52 +08:00
|
|
|
for g in self.guests:
|
2015-04-04 00:40:16 +08:00
|
|
|
if g.features.pae:
|
2013-03-18 05:06:52 +08:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
def get_cpu_values(self, conn, arch):
|
2014-03-21 01:48:49 +08:00
|
|
|
if not arch:
|
|
|
|
return []
|
2014-03-13 19:52:51 +08:00
|
|
|
if self._cpu_values:
|
|
|
|
return self._cpu_values.get_cpus(arch, conn)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
# Iterate over the available methods until a set of CPU models is found
|
2014-03-21 01:48:49 +08:00
|
|
|
for mode in (_CPUAPIValues, _CPUMapFileValues):
|
2014-03-13 19:52:51 +08:00
|
|
|
cpu_values = mode()
|
|
|
|
cpus = cpu_values.get_cpus(arch, conn)
|
2014-03-21 01:48:49 +08:00
|
|
|
if len(cpus) > 0:
|
2014-03-13 19:52:51 +08:00
|
|
|
self._cpu_values = cpu_values
|
|
|
|
return cpus
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-03-13 19:52:51 +08:00
|
|
|
return []
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2015-04-04 00:40:16 +08:00
|
|
|
|
|
|
|
############################
|
|
|
|
# Public XML building APIs #
|
|
|
|
############################
|
|
|
|
|
|
|
|
def _guestForOSType(self, typ=None, arch=None):
|
|
|
|
if self.host is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
archs = [arch]
|
|
|
|
if arch is None:
|
|
|
|
archs = [self.host.cpu.arch, None]
|
|
|
|
|
|
|
|
for a in archs:
|
|
|
|
for g in self.guests:
|
|
|
|
if ((typ is None or g.os_type == typ) and
|
|
|
|
(a is None or g.arch == a)):
|
|
|
|
return g
|
|
|
|
|
2014-02-18 00:43:53 +08:00
|
|
|
def guest_lookup(self, os_type=None, arch=None, typ=None, machine=None):
|
2013-07-07 02:12:13 +08:00
|
|
|
"""
|
|
|
|
Simple virtualization availability lookup
|
|
|
|
|
|
|
|
Convenience function for looking up 'Guest' and 'Domain' capabilities
|
|
|
|
objects for the desired virt type. If type, arch, or os_type are none,
|
|
|
|
we return the default virt type associated with those values. These are
|
|
|
|
typically:
|
|
|
|
|
|
|
|
- os_type : hvm, then xen
|
|
|
|
- typ : kvm over plain qemu
|
|
|
|
- arch : host arch over all others
|
|
|
|
|
|
|
|
Otherwise the default will be the first listed in the capabilities xml.
|
|
|
|
This function throws C{ValueError}s if any of the requested values are
|
|
|
|
not found.
|
|
|
|
|
|
|
|
@param typ: Virtualization type ('hvm', 'xen', ...)
|
|
|
|
@param arch: Guest architecture ('x86_64', 'i686' ...)
|
|
|
|
@param os_type: Hypervisor name ('qemu', 'kvm', 'xen', ...)
|
|
|
|
@param machine: Optional machine type to emulate
|
|
|
|
|
|
|
|
@returns: A (Capabilities Guest, Capabilities Domain) tuple
|
|
|
|
"""
|
2014-02-18 00:43:53 +08:00
|
|
|
guest = self._guestForOSType(os_type, arch)
|
2013-07-07 02:12:13 +08:00
|
|
|
if not guest:
|
|
|
|
archstr = _("for arch '%s'") % arch
|
|
|
|
if not arch:
|
|
|
|
archstr = ""
|
|
|
|
|
|
|
|
osstr = _("virtualization type '%s'") % os_type
|
|
|
|
if not os_type:
|
|
|
|
osstr = _("any virtualization options")
|
|
|
|
|
|
|
|
raise ValueError(_("Host does not support %(virttype)s %(arch)s") %
|
|
|
|
{'virttype' : osstr, 'arch' : archstr})
|
|
|
|
|
2014-02-18 00:43:53 +08:00
|
|
|
domain = guest.bestDomainType(dtype=typ, machine=machine)
|
2013-07-07 02:12:13 +08:00
|
|
|
if domain is None:
|
2014-02-18 00:43:53 +08:00
|
|
|
machinestr = " with machine '%s'" % machine
|
2013-07-07 02:12:13 +08:00
|
|
|
if not machine:
|
|
|
|
machinestr = ""
|
|
|
|
raise ValueError(_("Host does not support domain type %(domain)s"
|
|
|
|
"%(machine)s for virtualization type "
|
|
|
|
"'%(virttype)s' arch '%(arch)s'") %
|
|
|
|
{'domain': typ, 'virttype': guest.os_type,
|
|
|
|
'arch': guest.arch, 'machine': machinestr})
|
|
|
|
|
|
|
|
return (guest, domain)
|
2013-07-17 19:53:47 +08:00
|
|
|
|
|
|
|
def build_virtinst_guest(self, conn, guest, domain):
|
2015-04-04 00:40:16 +08:00
|
|
|
from .guest import Guest
|
|
|
|
gobj = Guest(conn)
|
2013-07-17 19:53:47 +08:00
|
|
|
gobj.type = domain.hypervisor_type
|
|
|
|
gobj.os.os_type = guest.os_type
|
|
|
|
gobj.os.arch = guest.arch
|
2015-04-04 00:40:16 +08:00
|
|
|
gobj.os.loader = guest.loader
|
2013-07-17 19:53:47 +08:00
|
|
|
gobj.emulator = domain.emulator
|
2014-09-24 04:05:48 +08:00
|
|
|
gobj.os.machine = domain.get_recommended_machine(conn, guest)
|
2013-07-17 19:53:47 +08:00
|
|
|
|
|
|
|
return gobj
|