devices: video: Add set_defaults

This commit is contained in:
Cole Robinson 2018-09-01 17:01:46 -04:00
parent d25ce81439
commit 1b0f325813
3 changed files with 31 additions and 30 deletions

View File

@ -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):

View File

@ -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

View File

@ -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