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
This commit is contained in:
Cole Robinson 2018-09-01 11:44:36 -04:00
parent b902fbd54f
commit 8a87c91888
2 changed files with 19 additions and 21 deletions

View File

@ -1078,22 +1078,26 @@ class Guest(XMLBuilder):
disk.cli_generated_target = False disk.cli_generated_target = False
used_targets.append(disk.generate_target(used_targets)) used_targets.append(disk.generate_target(used_targets))
def _set_net_defaults(self): def _default_netmodel(self):
net_model = None
if not self.os.is_hvm(): if not self.os.is_hvm():
net_model = None return None
elif self._supports_virtio(self._os_object.supports_virtionet()): if self._supports_virtio(self._os_object.supports_virtionet()):
net_model = "virtio" return "virtio"
else: if self.os.is_q35():
net_model = self._os_object.default_netmodel() return "e1000e"
if not net_model and self.os.is_q35(): prefs = ["e1000", "rtl8139", "ne2k_pci", "pcnet"]
net_model = "e1000e" supported_models = self._os_object.supported_netmodels()
for pref in prefs:
if pref in supported_models:
return pref
return None
if net_model: def _set_net_defaults(self):
for net in self.devices.interface: default_model = self._default_netmodel()
if not net.model: for net in self.devices.interface:
net.model = net_model if not net.model:
net.model = default_model
def _set_sound_defaults(self): def _set_sound_defaults(self):
if self.os.is_q35(): if self.os.is_q35():

View File

@ -340,14 +340,8 @@ class _OsVariant(object):
return self._is_related_to( return self._is_related_to(
["debian8", "fedora18", "rhel6.0", "sles11sp4"]) ["debian8", "fedora18", "rhel6.0", "sles11sp4"])
def default_netmodel(self): def supported_netmodels(self):
""" return self._device_filter(cls="net")
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 supports_usbtablet(self): def supports_usbtablet(self):
return bool(self._device_filter(cls="input", name="tablet", bus="usb")) return bool(self._device_filter(cls="input", name="tablet", bus="usb"))