caps: Simplify guest lookup routines
Checking for acceleration should always be done, API users can opt out by requesting a specific domain type.
This commit is contained in:
parent
96232ba2f0
commit
63b27ceae1
|
@ -1,6 +1,6 @@
|
|||
Copying test.ovf-disk1.vmdk to /tmp/test.ovf-disk1
|
||||
Copying testfile to /tmp/testfile
|
||||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>test.ovf</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<description>This is the description, created by RWMJ.</description>
|
||||
|
@ -16,6 +16,9 @@ Copying testfile to /tmp/testfile
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -25,7 +28,7 @@ Copying testfile to /tmp/testfile
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu"/>
|
||||
<source file="/tmp/test.ovf-disk1"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Running /usr/bin/qemu-img convert -O qcow2 fedora.vmdk /var/lib/libvirt/images/fedora.qcow2
|
||||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>fedora</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>524288</memory>
|
||||
|
@ -14,6 +14,9 @@ Running /usr/bin/qemu-img convert -O qcow2 fedora.vmdk /var/lib/libvirt/images/f
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@ Running /usr/bin/qemu-img convert -O qcow2 fedora.vmdk /var/lib/libvirt/images/f
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu" type="qcow2"/>
|
||||
<source file="/var/lib/libvirt/images/fedora.qcow2"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>CentOS-6.4-i386-Gnome.ovf</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>524288</memory>
|
||||
|
@ -13,6 +13,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -22,7 +25,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu"/>
|
||||
<source file="/var/lib/libvirt/images/CentOS-6.4-i386-Gnome-disk1"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>test.ovf</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<description>This is the description, created by RWMJ.</description>
|
||||
|
@ -14,6 +14,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu"/>
|
||||
<source file="/var/lib/libvirt/images/test.ovf-disk1"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>test.ovf</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<description>This is the description, created by RWMJ.</description>
|
||||
|
@ -14,6 +14,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu" type="qcow2"/>
|
||||
<source file="/var/lib/libvirt/images/test.ovf-disk1.qcow2"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>w2k3_32bit</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<description>Description added by RWMJ.</description>
|
||||
|
@ -14,6 +14,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu"/>
|
||||
<source file="/var/lib/libvirt/images/w2k3_32bit-disk1"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>minix</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>204800</memory>
|
||||
|
@ -14,6 +14,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="block" device="cdrom">
|
||||
<driver type="raw"/>
|
||||
<target dev="hda" bus="ide"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>fedora</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>524288</memory>
|
||||
|
@ -13,6 +13,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -22,7 +25,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu"/>
|
||||
<source file="/var/lib/libvirt/images/fedora"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>fedora</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>524288</memory>
|
||||
|
@ -13,6 +13,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -22,7 +25,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="file" device="disk">
|
||||
<driver name="qemu" type="raw"/>
|
||||
<source file="/var/lib/libvirt/images/fedora.raw"/>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<domain type="qemu">
|
||||
<domain type="kvm">
|
||||
<name>esx4.0-rhel4.8-i386</name>
|
||||
<uuid>00000000-1111-2222-3333-444444444444</uuid>
|
||||
<memory>524288</memory>
|
||||
|
@ -14,6 +14,9 @@
|
|||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<cpu mode="custom" match="exact">
|
||||
<model>core2duo</model>
|
||||
</cpu>
|
||||
<clock offset="utc">
|
||||
<timer name="rtc" tickpolicy="catchup"/>
|
||||
<timer name="pit" tickpolicy="delay"/>
|
||||
|
@ -23,7 +26,7 @@
|
|||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>restart</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<emulator>/usr/bin/qemu-kvm</emulator>
|
||||
<disk type="block" device="cdrom">
|
||||
<target dev="hda" bus="ide"/>
|
||||
<readonly/>
|
||||
|
|
|
@ -177,7 +177,6 @@ def get_guest(conn, options):
|
|||
options.container]]) > 1:
|
||||
fail(_("Can't do more than one of --hvm, --paravirt, or --container"))
|
||||
|
||||
req_accel = True
|
||||
req_hv_type = options.hv_type and options.hv_type.lower() or None
|
||||
if options.fullvirt:
|
||||
req_virt_type = "hvm"
|
||||
|
@ -203,7 +202,6 @@ def get_guest(conn, options):
|
|||
os_type=req_virt_type,
|
||||
arch=arch,
|
||||
typ=req_hv_type,
|
||||
accelerated=req_accel,
|
||||
machine=options.machine)
|
||||
guest = conn.caps.build_virtinst_guest(conn, capsguest, capsdomain)
|
||||
guest.os.machine = options.machine
|
||||
|
@ -212,7 +210,6 @@ def get_guest(conn, options):
|
|||
|
||||
if (not req_virt_type and
|
||||
not req_hv_type and
|
||||
req_accel and
|
||||
conn.is_qemu() and
|
||||
capsguest.arch in ["i686", "x86_64"] and
|
||||
not capsdomain.is_accelerated()):
|
||||
|
|
|
@ -858,9 +858,7 @@ class vmmCreate(vmmGObjectUI):
|
|||
gtype = "hvm"
|
||||
break
|
||||
|
||||
(newg, newdom) = self.caps.guest_lookup(os_type=gtype,
|
||||
accelerated=True,
|
||||
arch=arch)
|
||||
(newg, newdom) = self.caps.guest_lookup(os_type=gtype, arch=arch)
|
||||
|
||||
if (self.capsguest and self.capsdomain and
|
||||
(newg.arch == self.capsguest.arch and
|
||||
|
|
|
@ -345,18 +345,15 @@ class Guest(object):
|
|||
|
||||
child = child.next
|
||||
|
||||
def _favoredDomain(self, accelerated, domains):
|
||||
def _favoredDomain(self, domains):
|
||||
"""
|
||||
Return the recommended domain for use if the user does not explicitly
|
||||
request one.
|
||||
"""
|
||||
if accelerated is None:
|
||||
# Picking last in list so we favour KVM/KQEMU over QEMU
|
||||
return domains[-1]
|
||||
if not domains:
|
||||
return None
|
||||
|
||||
priority = ["kvm", "xen", "kqemu", "qemu"]
|
||||
if not accelerated:
|
||||
priority.reverse()
|
||||
|
||||
for t in priority:
|
||||
for d in domains:
|
||||
|
@ -366,7 +363,7 @@ class Guest(object):
|
|||
# Fallback, just return last item in list
|
||||
return domains[-1]
|
||||
|
||||
def bestDomainType(self, accelerated=None, dtype=None, machine=None):
|
||||
def bestDomainType(self, dtype=None, machine=None):
|
||||
domains = []
|
||||
for d in self.domains:
|
||||
if dtype and d.hypervisor_type != dtype.lower():
|
||||
|
@ -375,22 +372,7 @@ class Guest(object):
|
|||
continue
|
||||
domains.append(d)
|
||||
|
||||
if len(domains) == 0:
|
||||
domainerr = ""
|
||||
machineerr = ""
|
||||
if dtype:
|
||||
domainerr = _(", domain type '%s'") % dtype
|
||||
if machine:
|
||||
machineerr = _(", machine type '%s'") % machine
|
||||
|
||||
error = (_("No domains available for virt type '%(type)s', "
|
||||
"arch '%(arch)s'") %
|
||||
{'type': self.os_type, 'arch': self.arch})
|
||||
error += domainerr
|
||||
error += machineerr
|
||||
raise RuntimeError(error)
|
||||
|
||||
return self._favoredDomain(accelerated, domains)
|
||||
return self._favoredDomain(domains)
|
||||
|
||||
|
||||
class Domain(object):
|
||||
|
@ -621,7 +603,7 @@ class Capabilities(object):
|
|||
return True
|
||||
return False
|
||||
|
||||
def guestForOSType(self, typ=None, arch=None):
|
||||
def _guestForOSType(self, typ=None, arch=None):
|
||||
if self.host is None:
|
||||
return None
|
||||
|
||||
|
@ -652,8 +634,7 @@ class Capabilities(object):
|
|||
return self._cpu_values.get_arch(arch)
|
||||
|
||||
|
||||
def guest_lookup(self, os_type=None, arch=None, typ=None,
|
||||
accelerated=False, machine=None):
|
||||
def guest_lookup(self, os_type=None, arch=None, typ=None, machine=None):
|
||||
"""
|
||||
Simple virtualization availability lookup
|
||||
|
||||
|
@ -671,20 +652,13 @@ class Capabilities(object):
|
|||
not found.
|
||||
|
||||
@param typ: Virtualization type ('hvm', 'xen', ...)
|
||||
@type typ: C{str}
|
||||
@param arch: Guest architecture ('x86_64', 'i686' ...)
|
||||
@type arch: C{str}
|
||||
@param os_type: Hypervisor name ('qemu', 'kvm', 'xen', ...)
|
||||
@type os_type: C{str}
|
||||
@param accelerated: Whether to look for accelerated domain if none is
|
||||
specifically requested
|
||||
@type accelerated: C{bool}
|
||||
@param machine: Optional machine type to emulate
|
||||
@type machine: C{str}
|
||||
|
||||
@returns: A (Capabilities Guest, Capabilities Domain) tuple
|
||||
"""
|
||||
guest = self.guestForOSType(os_type, arch)
|
||||
guest = self._guestForOSType(os_type, arch)
|
||||
if not guest:
|
||||
archstr = _("for arch '%s'") % arch
|
||||
if not arch:
|
||||
|
@ -697,12 +671,9 @@ class Capabilities(object):
|
|||
raise ValueError(_("Host does not support %(virttype)s %(arch)s") %
|
||||
{'virttype' : osstr, 'arch' : archstr})
|
||||
|
||||
domain = guest.bestDomainType(accelerated=accelerated,
|
||||
dtype=typ,
|
||||
machine=machine)
|
||||
|
||||
domain = guest.bestDomainType(dtype=typ, machine=machine)
|
||||
if domain is None:
|
||||
machinestr = "with machine '%s'" % machine
|
||||
machinestr = " with machine '%s'" % machine
|
||||
if not machine:
|
||||
machinestr = ""
|
||||
raise ValueError(_("Host does not support domain type %(domain)s"
|
||||
|
|
|
@ -348,13 +348,8 @@ class ImageInstaller(Installer):
|
|||
self._boot_caps = image.domain.boots[boot_index]
|
||||
|
||||
# Set up internal caps.guest object
|
||||
self._guest = self.conn.caps.guestForOSType(self.boot_caps.type,
|
||||
self.boot_caps.arch)
|
||||
if self._guest is None:
|
||||
raise RuntimeError(_("Unsupported virtualization type: %s %s" %
|
||||
(self.boot_caps.type, self.boot_caps.arch)))
|
||||
self._domain = self._guest.bestDomainType()
|
||||
|
||||
self._guest, self._domain = self.conn.caps.guest_lookup(
|
||||
os_type=self.boot_caps.type, arch=self.boot_caps.arch)
|
||||
|
||||
|
||||
# Custom ImageInstaller methods
|
||||
|
|
Loading…
Reference in New Issue