osdict: Don't run support checks, make the caller do it
Some ARM bits we are about to add would substantially complicate the current setup, so move all the logic into guest.py where we can be more flexible. I think this is closer to what libosinfo will give us as well.
This commit is contained in:
parent
3130f64e35
commit
a8858cd366
|
@ -1346,6 +1346,7 @@ def default_uri(always_system=False):
|
|||
return "qemu:///session"
|
||||
return None
|
||||
|
||||
|
||||
def exception_is_libvirt_error(e, error):
|
||||
return (hasattr(libvirt, error) and
|
||||
e.get_error_code() == getattr(libvirt, error))
|
||||
|
|
|
@ -549,8 +549,8 @@ class Guest(XMLBuilder):
|
|||
Use self.os_variant to find key in OSTYPES
|
||||
@returns: dict value, or None if os_type/variant wasn't set
|
||||
"""
|
||||
return osdict.lookup_osdict_key(self.conn, self.type,
|
||||
self.os_variant, key, default)
|
||||
return osdict.lookup_osdict_key(self.os_variant, key, default)
|
||||
|
||||
|
||||
###################
|
||||
# Device defaults #
|
||||
|
@ -620,8 +620,7 @@ class Guest(XMLBuilder):
|
|||
if self.os.kernel or self.os.init:
|
||||
self.os.bootorder = []
|
||||
|
||||
if (self.os.machine is None and
|
||||
self.conn.caps.host.arch == "ppc64"):
|
||||
if (self.os.machine is None and self.os.is_ppc64()):
|
||||
self.os.machine = "pseries"
|
||||
|
||||
def _set_clock_defaults(self):
|
||||
|
@ -658,10 +657,17 @@ class Guest(XMLBuilder):
|
|||
if not self.os.is_hvm():
|
||||
return
|
||||
|
||||
default = True
|
||||
if (self._lookup_osdict_key("xen_disable_acpi", False) and
|
||||
self.conn.check_conn_hv_support(
|
||||
support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI,
|
||||
self.type)):
|
||||
default = False
|
||||
|
||||
if self.features["acpi"] == "default":
|
||||
self.features["acpi"] = self._lookup_osdict_key("acpi", True)
|
||||
self.features["acpi"] = self._lookup_osdict_key("acpi", default)
|
||||
if self.features["apic"] == "default":
|
||||
self.features["apic"] = self._lookup_osdict_key("apic", True)
|
||||
self.features["apic"] = self._lookup_osdict_key("apic", default)
|
||||
if self.features["pae"] == "default":
|
||||
self.features["pae"] = self.conn.caps.support_pae()
|
||||
|
||||
|
@ -677,8 +683,17 @@ class Guest(XMLBuilder):
|
|||
ctrl.address.set_addrstr("spapr-vio")
|
||||
self.add_device(ctrl)
|
||||
|
||||
def _can_virtio(self, key):
|
||||
if not self.os.is_x86():
|
||||
return False
|
||||
if not self.conn.is_qemu() or self.type != "kvm":
|
||||
return False
|
||||
if not self._lookup_osdict_key(key, False):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _set_disk_defaults(self):
|
||||
os_disk_bus = self._lookup_osdict_key("diskbus", None)
|
||||
os_disk_bus = self._lookup_osdict_key("diskbus", None)
|
||||
|
||||
def set_disk_bus(d):
|
||||
if d.is_floppy():
|
||||
|
@ -691,11 +706,11 @@ class Guest(XMLBuilder):
|
|||
d.bus = "ide"
|
||||
return
|
||||
|
||||
|
||||
if os_disk_bus and d.is_disk():
|
||||
if self._can_virtio("virtiodisk") and d.is_disk():
|
||||
d.bus = "virtio"
|
||||
elif os_disk_bus and d.is_disk():
|
||||
d.bus = os_disk_bus
|
||||
elif (self.type == "kvm" and
|
||||
self.os.machine == "pseries"):
|
||||
elif self.os.is_pseries():
|
||||
d.bus = "scsi"
|
||||
else:
|
||||
d.bus = "ide"
|
||||
|
@ -719,9 +734,12 @@ class Guest(XMLBuilder):
|
|||
used_targets.append(disk.generate_target(used_targets))
|
||||
|
||||
def _set_net_defaults(self):
|
||||
net_model = self._lookup_osdict_key("netmodel", None)
|
||||
if not self.os.is_hvm():
|
||||
net_model = None
|
||||
elif self._can_virtio("virtionet"):
|
||||
net_model = "virtio"
|
||||
else:
|
||||
net_model = self._lookup_osdict_key("netmodel", None)
|
||||
|
||||
for net in self.get_devices("interface"):
|
||||
if net_model and not net.model:
|
||||
|
|
|
@ -19,40 +19,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
from virtinst import support
|
||||
|
||||
_SENTINEL = -1234
|
||||
|
||||
|
||||
class _SupportCheck(object):
|
||||
"""
|
||||
Class for encapsulating complex support checks.
|
||||
|
||||
Example: Fedora 18 supports virtio disks, but we only want to
|
||||
use virtio if the HV supports it. So this is initialized like:
|
||||
|
||||
_SupportCheck(support.SUPPORT_CONN_HV_VIRTIO, "virtio")
|
||||
|
||||
And that object should be passed to the diskbus value of _OSVariant.
|
||||
"""
|
||||
def __init__(self, key, val):
|
||||
self._checks = []
|
||||
self.add_check(key, val)
|
||||
|
||||
def add_check(self, key, val):
|
||||
self._checks.append((key, val))
|
||||
|
||||
def check(self, conn, hv_type):
|
||||
for (support_key, value) in self._checks:
|
||||
if conn.check_conn_hv_support(support_key, hv_type):
|
||||
return value
|
||||
return _SENTINEL
|
||||
|
||||
|
||||
_DISK_BUS_VIRTIO = _SupportCheck(support.SUPPORT_CONN_HV_VIRTIO, "virtio")
|
||||
_NET_MODEL_VIRTIO = _SupportCheck(support.SUPPORT_CONN_HV_VIRTIO, "virtio")
|
||||
_ACPI_OLD_XEN = _SupportCheck(support.SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI, False)
|
||||
|
||||
_allvariants = {}
|
||||
|
||||
|
||||
|
@ -127,13 +94,10 @@ def list_os(list_types=False, typename=None,
|
|||
return _sort(sortmap, **kwargs)
|
||||
|
||||
|
||||
def lookup_osdict_key(conn, hv_type, variant, key, default):
|
||||
def lookup_osdict_key(variant, key, default):
|
||||
val = _SENTINEL
|
||||
if variant is not None:
|
||||
val = getattr(_allvariants[variant], key)
|
||||
if isinstance(val, _SupportCheck):
|
||||
val = val.check(conn, hv_type)
|
||||
else:
|
||||
val = _SENTINEL
|
||||
if val == _SENTINEL:
|
||||
val = default
|
||||
return val
|
||||
|
@ -168,6 +132,10 @@ class _OSVariant(object):
|
|||
distros we show in virt-manager by default, so old distros aren't
|
||||
squeezing out current ones.
|
||||
@three_stage_install: If True, this VM has a 3 stage install, AKA windows.
|
||||
@xen_disable_acpi: If True, disable acpi/apic for this OS if on old xen.
|
||||
This corresponds with the SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI check
|
||||
@virtionet: If True, this OS supports virtionet out of the box
|
||||
@virtiodisk: If True, this OS supports virtiodisk out of the box
|
||||
|
||||
The rest of the parameters are about setting device/guest defaults
|
||||
based on the OS. They should be self explanatory. See guest.py for
|
||||
|
@ -180,7 +148,8 @@ class _OSVariant(object):
|
|||
acpi=_SENTINEL, apic=_SENTINEL, clock=_SENTINEL,
|
||||
netmodel=_SENTINEL, diskbus=_SENTINEL,
|
||||
inputtype=_SENTINEL, inputbus=_SENTINEL,
|
||||
videomodel=_SENTINEL):
|
||||
videomodel=_SENTINEL, virtionet=_SENTINEL,
|
||||
virtiodisk=_SENTINEL, xen_disable_acpi=_SENTINEL):
|
||||
if is_type:
|
||||
if parent != _SENTINEL:
|
||||
raise RuntimeError("OS types must not specify parent")
|
||||
|
@ -233,6 +202,11 @@ class _OSVariant(object):
|
|||
self.inputtype = _get_default("inputtype", inputtype)
|
||||
self.inputbus = _get_default("inputbus", inputbus)
|
||||
|
||||
self.xen_disable_acpi = _get_default("xen_disable_acpi",
|
||||
xen_disable_acpi)
|
||||
self.virtiodisk = _get_default("virtiodisk", virtiodisk)
|
||||
self.virtionet = _get_default("virtionet", virtionet)
|
||||
|
||||
|
||||
def _add_type(*args, **kwargs):
|
||||
kwargs["is_type"] = True
|
||||
|
@ -240,9 +214,6 @@ def _add_type(*args, **kwargs):
|
|||
_allvariants[_t.name] = _t
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def _add_var(*args, **kwargs):
|
||||
v = _OSVariant(*args, **kwargs)
|
||||
_allvariants[v.name] = v
|
||||
|
@ -253,8 +224,8 @@ _add_var("rhel2.1", "Red Hat Enterprise Linux 2.1", distro="rhel", parent="linux
|
|||
_add_var("rhel3", "Red Hat Enterprise Linux 3", parent="rhel2.1")
|
||||
_add_var("rhel4", "Red Hat Enterprise Linux 4", supported=True, parent="rhel3")
|
||||
_add_var("rhel5", "Red Hat Enterprise Linux 5", supported=False, parent="rhel4")
|
||||
_add_var("rhel5.4", "Red Hat Enterprise Linux 5.4 or later", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="rhel5")
|
||||
_add_var("rhel6", "Red Hat Enterprise Linux 6", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, inputtype="tablet", inputbus="usb", parent="rhel5.4")
|
||||
_add_var("rhel5.4", "Red Hat Enterprise Linux 5.4 or later", supported=True, virtiodisk=True, virtionet=True, parent="rhel5")
|
||||
_add_var("rhel6", "Red Hat Enterprise Linux 6", inputtype="tablet", inputbus="usb", parent="rhel5.4")
|
||||
_add_var("rhel7", "Red Hat Enterprise Linux 7", supported=False, parent="rhel6")
|
||||
|
||||
_add_var("fedora5", "Fedora Core 5", sortby="fedora05", distro="fedora", parent="linux")
|
||||
|
@ -263,9 +234,9 @@ _add_var("fedora7", "Fedora 7", sortby="fedora07", parent="fedora6")
|
|||
_add_var("fedora8", "Fedora 8", sortby="fedora08", parent="fedora7")
|
||||
# Apparently F9 has selinux errors when installing with virtio:
|
||||
# https: //bugzilla.redhat.com/show_bug.cgi?id=470386
|
||||
_add_var("fedora9", "Fedora 9", sortby="fedora09", netmodel=_NET_MODEL_VIRTIO, parent="fedora8")
|
||||
_add_var("fedora10", "Fedora 10", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="fedora9")
|
||||
_add_var("fedora11", "Fedora 11", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, inputtype="tablet", inputbus="usb", parent="fedora10")
|
||||
_add_var("fedora9", "Fedora 9", sortby="fedora09", virtionet=True, parent="fedora8")
|
||||
_add_var("fedora10", "Fedora 10", virtiodisk=True, parent="fedora9")
|
||||
_add_var("fedora11", "Fedora 11", inputtype="tablet", inputbus="usb", parent="fedora10")
|
||||
_add_var("fedora12", "Fedora 12", parent="fedora11")
|
||||
_add_var("fedora13", "Fedora 13", parent="fedora12")
|
||||
_add_var("fedora14", "Fedora 14", parent="fedora13")
|
||||
|
@ -276,30 +247,30 @@ _add_var("fedora18", "Fedora 18", supported=True, parent="fedora17")
|
|||
_add_var("fedora19", "Fedora 19", parent="fedora18")
|
||||
_add_var("fedora20", "Fedora 20", parent="fedora19")
|
||||
|
||||
_add_var("opensuse11", "openSuse 11", distro="suse", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="linux")
|
||||
_add_var("opensuse11", "openSuse 11", distro="suse", supported=True, virtiodisk=True, virtionet=True, parent="linux")
|
||||
_add_var("opensuse12", "openSuse 12", parent="opensuse11")
|
||||
|
||||
_add_var("sles10", "Suse Linux Enterprise Server", distro="suse", supported=True, parent="linux")
|
||||
_add_var("sles11", "Suse Linux Enterprise Server 11", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="sles10")
|
||||
_add_var("sles11", "Suse Linux Enterprise Server 11", supported=True, virtiodisk=True, virtionet=True, parent="sles10")
|
||||
|
||||
_add_var("mandriva2009", "Mandriva Linux 2009 and earlier", distro="mandriva", parent="linux")
|
||||
_add_var("mandriva2010", "Mandriva Linux 2010 and later", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="mandriva2009")
|
||||
_add_var("mandriva2010", "Mandriva Linux 2010 and later", virtiodisk=True, virtionet=True, parent="mandriva2009")
|
||||
|
||||
_add_var("mes5", "Mandriva Enterprise Server 5.0", distro="mandriva", parent="linux")
|
||||
_add_var("mes5.1", "Mandriva Enterprise Server 5.1 and later", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="mes5")
|
||||
_add_var("mes5.1", "Mandriva Enterprise Server 5.1 and later", supported=True, virtiodisk=True, virtionet=True, parent="mes5")
|
||||
|
||||
_add_var("mageia1", "Mageia 1 and later", distro="mageia", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, inputtype="tablet", inputbus="usb", parent="linux")
|
||||
_add_var("mageia1", "Mageia 1 and later", distro="mageia", supported=True, virtiodisk=True, virtionet=True, inputtype="tablet", inputbus="usb", parent="linux")
|
||||
|
||||
_add_var("altlinux", "ALT Linux", distro="altlinux", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, inputtype="tablet", inputbus="usb", parent="linux")
|
||||
_add_var("altlinux", "ALT Linux", distro="altlinux", supported=True, virtiodisk=True, virtionet=True, inputtype="tablet", inputbus="usb", parent="linux")
|
||||
|
||||
_add_var("debianetch", "Debian Etch", distro="debian", sortby="debian4", parent="linux")
|
||||
_add_var("debianlenny", "Debian Lenny", sortby="debian5", supported=True, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="debianetch")
|
||||
_add_var("debiansqueeze", "Debian Squeeze", sortby="debian6", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, inputtype="tablet", inputbus="usb", parent="debianlenny")
|
||||
_add_var("debianlenny", "Debian Lenny", sortby="debian5", supported=True, virtiodisk=True, virtionet=True, parent="debianetch")
|
||||
_add_var("debiansqueeze", "Debian Squeeze", sortby="debian6", virtiodisk=True, virtionet=True, inputtype="tablet", inputbus="usb", parent="debianlenny")
|
||||
_add_var("debianwheezy", "Debian Wheezy", sortby="debian7", parent="debiansqueeze")
|
||||
|
||||
_add_var("ubuntuhardy", "Ubuntu 8.04 LTS (Hardy Heron)", distro="ubuntu", netmodel=_NET_MODEL_VIRTIO, parent="linux")
|
||||
_add_var("ubuntuhardy", "Ubuntu 8.04 LTS (Hardy Heron)", distro="ubuntu", virtionet=True, parent="linux")
|
||||
_add_var("ubuntuintrepid", "Ubuntu 8.10 (Intrepid Ibex)", parent="ubuntuhardy")
|
||||
_add_var("ubuntujaunty", "Ubuntu 9.04 (Jaunty Jackalope)", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="ubuntuintrepid")
|
||||
_add_var("ubuntujaunty", "Ubuntu 9.04 (Jaunty Jackalope)", virtiodisk=True, parent="ubuntuintrepid")
|
||||
_add_var("ubuntukarmic", "Ubuntu 9.10 (Karmic Koala)", parent="ubuntujaunty")
|
||||
_add_var("ubuntulucid", "Ubuntu 10.04 LTS (Lucid Lynx)", supported=True, parent="ubuntukarmic")
|
||||
_add_var("ubuntumaverick", "Ubuntu 10.10 (Maverick Meerkat)", supported=False, parent="ubuntulucid")
|
||||
|
@ -307,17 +278,17 @@ _add_var("ubuntunatty", "Ubuntu 11.04 (Natty Narwhal)", parent="ubuntumaverick")
|
|||
_add_var("ubuntuoneiric", "Ubuntu 11.10 (Oneiric Ocelot)", parent="ubuntunatty")
|
||||
_add_var("ubuntuprecise", "Ubuntu 12.04 LTS (Precise Pangolin)", supported=True, parent="ubuntuoneiric")
|
||||
_add_var("ubuntuquantal", "Ubuntu 12.10 (Quantal Quetzal)", parent="ubuntuprecise")
|
||||
_add_var("ubunturaring", "Ubuntu 13.04 (Raring Ringtail)", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, videomodel="vmvga", parent="ubuntuquantal")
|
||||
_add_var("ubunturaring", "Ubuntu 13.04 (Raring Ringtail)", videomodel="vmvga", parent="ubuntuquantal")
|
||||
_add_var("ubuntusaucy", "Ubuntu 13.10 (Saucy Salamander)", parent="ubunturaring")
|
||||
|
||||
_add_var("generic24", "Generic 2.4.x kernel", parent="linux")
|
||||
_add_var("generic26", "Generic 2.6.x kernel", parent="generic24")
|
||||
_add_var("virtio26", "Generic 2.6.25 or later kernel with virtio", sortby="genericvirtio26", diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="generic26")
|
||||
_add_var("virtio26", "Generic 2.6.25 or later kernel with virtio", sortby="genericvirtio26", virtiodisk=True, virtionet=True, parent="generic26")
|
||||
|
||||
|
||||
_add_type("windows", "Windows", clock="localtime", three_stage_install=True, inputtype="tablet", inputbus="usb", videomodel="vga")
|
||||
_add_var("win2k", "Microsoft Windows 2000", sortby="mswin4", acpi=_ACPI_OLD_XEN, apic=_ACPI_OLD_XEN, parent="windows")
|
||||
_add_var("winxp", "Microsoft Windows XP", sortby="mswin5", supported=True, acpi=_ACPI_OLD_XEN, apic=_ACPI_OLD_XEN, parent="windows")
|
||||
_add_var("win2k", "Microsoft Windows 2000", sortby="mswin4", xen_disable_acpi=True, parent="windows")
|
||||
_add_var("winxp", "Microsoft Windows XP", sortby="mswin5", supported=True, xen_disable_acpi=True, parent="windows")
|
||||
_add_var("winxp64", "Microsoft Windows XP (x86_64)", supported=True, sortby="mswin564", parent="windows")
|
||||
_add_var("win2k3", "Microsoft Windows Server 2003", supported=True, sortby="mswinserv2003", parent="windows")
|
||||
_add_var("win2k8", "Microsoft Windows Server 2008", supported=True, sortby="mswinserv2008", parent="windows")
|
||||
|
@ -338,7 +309,7 @@ _add_var("freebsd6", "FreeBSD 6.x", netmodel="ne2k_pci", parent="unix")
|
|||
_add_var("freebsd7", "FreeBSD 7.x", parent="freebsd6")
|
||||
_add_var("freebsd8", "FreeBSD 8.x", supported=True, netmodel="e1000", parent="freebsd7")
|
||||
_add_var("freebsd9", "FreeBSD 9.x", parent="freebsd8")
|
||||
_add_var("freebsd10", "FreeBSD 10.x", supported=False, diskbus=_DISK_BUS_VIRTIO, netmodel=_NET_MODEL_VIRTIO, parent="freebsd9")
|
||||
_add_var("freebsd10", "FreeBSD 10.x", supported=False, virtiodisk=True, virtionet=True, parent="freebsd9")
|
||||
|
||||
# http: //calamari.reverse-dns.net: 980/cgi-bin/moin.cgi/OpenbsdOnQemu
|
||||
# https: //www.redhat.com/archives/et-mgmt-tools/2008-June/msg00018.html
|
||||
|
|
|
@ -75,6 +75,15 @@ class OSXML(XMLBuilder):
|
|||
def is_container(self):
|
||||
return self.os_type == "exe"
|
||||
|
||||
def is_x86(self):
|
||||
return self.arch == "x86_64" or self.arch == "i686"
|
||||
def is_arm(self):
|
||||
return self.arch == "armv7l"
|
||||
def is_ppc64(self):
|
||||
return self.arch == "ppc64"
|
||||
def is_pseries(self):
|
||||
return self.is_ppc64 and self.machine == "pseries"
|
||||
|
||||
_XML_ROOT_XPATH = "/domain/os"
|
||||
_XML_PROP_ORDER = ["arch", "os_type", "loader",
|
||||
"kernel", "initrd", "kernel_args", "dtb",
|
||||
|
|
|
@ -360,8 +360,6 @@ SUPPORT_INTERFACE_ISACTIVE = _make(function="virInterface.isActive", args=())
|
|||
|
||||
|
||||
# Conn HV checks
|
||||
SUPPORT_CONN_HV_VIRTIO = _make(drv_version=[("qemu", 0)],
|
||||
hv_version=[("kvm", 0)])
|
||||
SUPPORT_CONN_HV_SKIP_DEFAULT_ACPI = _make(drv_version=[("xen", -3001000)])
|
||||
SUPPORT_CONN_HV_SOUND_AC97 = _make(version=6000,
|
||||
force_version=True,
|
||||
|
|
Loading…
Reference in New Issue