From 8a87c91888d9a992fbc9b2ba9e13073b16ffdc6f Mon Sep 17 00:00:00 2001 From: Cole Robinson <crobinso@redhat.com> Date: Sat, 1 Sep 2018 11:44:36 -0400 Subject: [PATCH] osdict: Move default_netmodel logic to Guest Make the entry point just return a list of libosinfo device names, and have Guest choose the preference. This is more future proof --- virtinst/guest.py | 30 +++++++++++++++++------------- virtinst/osdict.py | 10 ++-------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/virtinst/guest.py b/virtinst/guest.py index 496dd0f6f..0384eff82 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -1078,22 +1078,26 @@ class Guest(XMLBuilder): disk.cli_generated_target = False used_targets.append(disk.generate_target(used_targets)) - def _set_net_defaults(self): - net_model = None + def _default_netmodel(self): if not self.os.is_hvm(): - net_model = None - elif self._supports_virtio(self._os_object.supports_virtionet()): - net_model = "virtio" - else: - net_model = self._os_object.default_netmodel() + return None + if self._supports_virtio(self._os_object.supports_virtionet()): + return "virtio" + if self.os.is_q35(): + return "e1000e" - if not net_model and self.os.is_q35(): - net_model = "e1000e" + prefs = ["e1000", "rtl8139", "ne2k_pci", "pcnet"] + supported_models = self._os_object.supported_netmodels() + for pref in prefs: + if pref in supported_models: + return pref + return None - if net_model: - for net in self.devices.interface: - if not net.model: - net.model = net_model + def _set_net_defaults(self): + default_model = self._default_netmodel() + for net in self.devices.interface: + if not net.model: + net.model = default_model def _set_sound_defaults(self): if self.os.is_q35(): diff --git a/virtinst/osdict.py b/virtinst/osdict.py index 87b2672df..d5db5f16d 100644 --- a/virtinst/osdict.py +++ b/virtinst/osdict.py @@ -340,14 +340,8 @@ class _OsVariant(object): return self._is_related_to( ["debian8", "fedora18", "rhel6.0", "sles11sp4"]) - def default_netmodel(self): - """ - Default non-virtio net-model, since we check for that separately - """ - for devname in self._device_filter(cls="net"): - if devname in ["pcnet", "ne2k_pci", "rtl8139", "e1000"]: - return devname - return None + def supported_netmodels(self): + return self._device_filter(cls="net") def supports_usbtablet(self): return bool(self._device_filter(cls="input", name="tablet", bus="usb"))