virt-manager/0003-caps-Simplify-guest-lookup-routines.patch

498 lines
19 KiB
Diff
Raw Normal View History

From 12c4a54a92f935abceb358a8d7ba8f391597f014 Mon Sep 17 00:00:00 2001
From: Cole Robinson <crobinso@redhat.com>
Date: Mon, 17 Feb 2014 11:43:53 -0500
Subject: [PATCH] caps: Simplify guest lookup routines
Checking for acceleration should always be done, API users can opt out
by requesting a specific domain type.
(cherry picked from commit 63b27ceae1e5a1521b968deb7e04d1a5ebd3de39)
---
.../compare/virt-convert-ovf-compare.xml | 7 +++-
.../compare/virt-convert-vmx-compare.xml | 7 +++-
.../ovf2libvirt_ovf_directory.libvirt | 7 +++-
.../libvirt_output/ovf2libvirt_test1.libvirt | 7 +++-
.../ovf2libvirt_test1.libvirt.disk_qcow2 | 7 +++-
.../libvirt_output/ovf2libvirt_test2.libvirt | 7 +++-
.../vmx2libvirt_test-vmx-zip.libvirt | 7 +++-
.../libvirt_output/vmx2libvirt_test1.libvirt | 7 +++-
.../vmx2libvirt_test1.libvirt.disk_raw | 7 +++-
.../libvirt_output/vmx2libvirt_vmx-dir.libvirt | 7 +++-
virt-install | 3 --
virtManager/create.py | 4 +-
virtinst/capabilities.py | 49 +++++-----------------
virtinst/virtimage.py | 9 +---
14 files changed, 63 insertions(+), 72 deletions(-)
diff --git a/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml b/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml
index c073ffc..a1d2f75 100644
--- a/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml
+++ b/tests/cli-test-xml/compare/virt-convert-ovf-compare.xml
@@ -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"/>
diff --git a/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml b/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml
index 20f046d..ffe7b59 100644
--- a/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml
+++ b/tests/cli-test-xml/compare/virt-convert-vmx-compare.xml
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt
index c88c140..597a0c5 100644
--- a/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt
+++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_ovf_directory.libvirt
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt
index 22978ca..83c3f90 100644
--- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt
+++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2 b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2
index d86ced0..1b50422 100644
--- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2
+++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test1.libvirt.disk_qcow2
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt b/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt
index aa0303e..9d28269 100644
--- a/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt
+++ b/tests/virtconv-files/libvirt_output/ovf2libvirt_test2.libvirt
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt
index 179978b..9e2058f 100644
--- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt
+++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test-vmx-zip.libvirt
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt
index 1ff4eec..a6fc259 100644
--- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt
+++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw
index 2abd1e2..9c3d6e2 100644
--- a/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw
+++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_test1.libvirt.disk_raw
@@ -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"/>
diff --git a/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt b/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt
index 7887f36..74f3541 100644
--- a/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt
+++ b/tests/virtconv-files/libvirt_output/vmx2libvirt_vmx-dir.libvirt
@@ -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/>
diff --git a/virt-install b/virt-install
index 6453f77..a801952 100755
--- a/virt-install
+++ b/virt-install
@@ -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()):
diff --git a/virtManager/create.py b/virtManager/create.py
index f1c57b7..2af62c4 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -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
diff --git a/virtinst/capabilities.py b/virtinst/capabilities.py
index c55f67d..b8d3330 100644
--- a/virtinst/capabilities.py
+++ b/virtinst/capabilities.py
@@ -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"
diff --git a/virtinst/virtimage.py b/virtinst/virtimage.py
index 44c5640..c09428b 100644
--- a/virtinst/virtimage.py
+++ b/virtinst/virtimage.py
@@ -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