From 1b0f3258134fab6735aa7cb7f0f51e862ac360e5 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 1 Sep 2018 17:01:46 -0400 Subject: [PATCH] devices: video: Add set_defaults --- virtManager/addhardware.py | 5 +++-- virtinst/devices/video.py | 32 ++++++++++++++++++++++++++++---- virtinst/guest.py | 24 ------------------------ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index e7abbad6d..2f2ff01fc 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -610,11 +610,12 @@ class vmmAddHardware(vmmGObjectUI): @staticmethod - def build_video_combo(_vm, combo): + def build_video_combo(vm, combo): values = [] for m in DeviceVideo.MODELS: values.append([m, DeviceVideo.pretty_model(m)]) - _build_combo(combo, values) + default = DeviceVideo.default_model(vm.xmlobj) + _build_combo(combo, values, default_value=default) def _build_char_mode_combo(self): diff --git a/virtinst/devices/video.py b/virtinst/devices/video.py index 2b1d5134e..b172ded77 100644 --- a/virtinst/devices/video.py +++ b/virtinst/devices/video.py @@ -13,7 +13,6 @@ class DeviceVideo(Device): XML_NAME = "video" # Default models list - MODEL_DEFAULT = "default" MODELS = ["cirrus", "vga", "vmvga", "xen", "qxl", "virtio"] @staticmethod @@ -23,12 +22,37 @@ class DeviceVideo(Device): return model.capitalize() _XML_PROP_ORDER = ["model", "vram", "heads", "vgamem"] - model = XMLProperty("./model/@type", - default_cb=lambda s: "cirrus", - default_name=MODEL_DEFAULT) + model = XMLProperty("./model/@type") vram = XMLProperty("./model/@vram", is_int=True) vram64 = XMLProperty("./model/@vram64", is_int=True) ram = XMLProperty("./model/@ram", is_int=True) heads = XMLProperty("./model/@heads", is_int=True) vgamem = XMLProperty("./model/@vgamem", is_int=True) accel3d = XMLProperty("./model/acceleration/@accel3d", is_yesno=True) + + + ################## + # Default config # + ################## + + @staticmethod + def default_model(guest): + if guest.os.is_pseries(): + return "vga" + if guest.os.is_arm_machvirt(): + return "virtio" + if guest.has_spice() and guest.os.is_x86(): + if guest.has_gl(): + return "virtio" + return "qxl" + if guest.os.is_hvm(): + if guest.conn.is_qemu(): + return "qxl" + return "vga" + return None + + def set_defaults(self, guest): + if not self.model: + self.model = self.default_model(guest) + if self.model == 'virtio' and guest.has_gl(): + self.accel3d = True diff --git a/virtinst/guest.py b/virtinst/guest.py index 51d01d3e8..1bdec8fee 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -744,7 +744,6 @@ class Guest(XMLBuilder): self._set_graphics_defaults() self._add_spice_devices() self._set_net_defaults() - self._set_video_defaults() self._set_sound_defaults() def _is_full_os_container(self): @@ -1180,29 +1179,6 @@ class Guest(XMLBuilder): return True return False - def _default_videomodel(self): - if self.os.is_pseries(): - return "vga" - if self.os.is_arm_machvirt(): - return "virtio" - if self.has_spice() and self.os.is_x86(): - if self.has_gl(): - return "virtio" - return "qxl" - if self.os.is_hvm(): - if self.conn.is_qemu(): - return "qxl" - return "vga" - return None - - def _set_video_defaults(self): - video_model = self._default_videomodel() - for video in self.devices.video: - if video.model == video.MODEL_DEFAULT: - video.model = video_model - if video.model == 'virtio' and self.has_gl(): - video.accel3d = True - def _add_spice_devices(self): if not self.has_spice(): return