devices: panic: Add set_defaults

Move default handling out of Guest and default_cb callbacks, and
make implement it in a standard set_defaults function
This commit is contained in:
Cole Robinson 2018-09-01 15:58:26 -04:00
parent c3515fa469
commit 7738b8f407
3 changed files with 17 additions and 22 deletions

View File

@ -734,8 +734,7 @@ class vmmAddHardware(vmmGObjectUI):
for m in DevicePanic.get_models(self.vm.get_xmlobj().os):
values.append([m, DevicePanic.get_pretty_model(m)])
default = DevicePanic.get_default_model(
self.vm.get_xmlobj().os)
default = DevicePanic.get_default_model(self.vm.get_xmlobj())
_build_combo(self.widget("panic-model"), values, default_value=default)

View File

@ -12,7 +12,6 @@ from ..xmlbuilder import XMLProperty
class DevicePanic(Device):
XML_NAME = "panic"
MODEL_DEFAULT = "default"
MODEL_ISA = "isa"
MODEL_PSERIES = "pseries"
MODEL_HYPERV = "hyperv"
@ -44,21 +43,24 @@ class DevicePanic(Device):
return [DevicePanic.MODEL_S390]
return []
model = XMLProperty("./@model")
type = XMLProperty("./address/@type")
iobase = XMLProperty("./address/@iobase")
##################
# Default config #
##################
@staticmethod
def get_default_model(os):
models = DevicePanic.get_models(os)
def get_default_model(guest):
models = DevicePanic.get_models(guest.os)
if models:
return models[0]
return None
def _get_default_address_type(self):
if self.iobase:
return DevicePanic.ISA_ADDRESS_TYPE
return None
model = XMLProperty("./@model",
default_cb=lambda s: DevicePanic.MODEL_ISA,
default_name=MODEL_DEFAULT)
type = XMLProperty("./address/@type",
default_cb=_get_default_address_type)
iobase = XMLProperty("./address/@iobase")
def set_defaults(self, guest):
if not self.type and self.iobase:
self.type = DevicePanic.ISA_ADDRESS_TYPE
if not self.model:
self.model = self.get_default_model(guest)

View File

@ -746,7 +746,6 @@ class Guest(XMLBuilder):
self._set_net_defaults()
self._set_video_defaults()
self._set_sound_defaults()
self._set_panic_defaults()
def _is_full_os_container(self):
if not self.os.is_container():
@ -1212,8 +1211,3 @@ class Guest(XMLBuilder):
video.model = video_model
if video.model == 'virtio' and self.has_gl():
video.accel3d = True
def _set_panic_defaults(self):
for panic in self.devices.panic:
if panic.model == DevicePanic.MODEL_DEFAULT:
panic.model = DevicePanic.get_default_model(self.os)