From d5bff2c987fed055997911f6645609e19b69ef2d Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 2 Sep 2018 10:26:20 -0400 Subject: [PATCH] guest: Remove default_cb usage This lets us simplify things in create.py a bit, since we don't need to manually encode a UUID --- virtManager/create.py | 35 ++++++++++++++++------------------- virtManager/domain.py | 4 ---- virtinst/guest.py | 19 +++++++------------ 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/virtManager/create.py b/virtManager/create.py index fd2fe54b3..a014b8148 100644 --- a/virtManager/create.py +++ b/virtManager/create.py @@ -1566,13 +1566,6 @@ class vmmCreate(vmmGObjectUI): if machine: guest.os.machine = machine - # Generate UUID (makes customize dialog happy) - try: - guest.uuid = util.randomUUID(guest.conn) - except Exception as e: - self.err.show_err(_("Error setting UUID: %s") % str(e)) - return None - # OS distro/variant validation try: if variant: @@ -2142,19 +2135,22 @@ class vmmCreate(vmmGObjectUI): return False logging.debug("Starting create finish() sequence") - guest = self._guest - - # Start the install self._failed_guest = None - self.set_finish_cursor() - if not self.widget("summary-customize").get_active(): - self._start_install(guest) - return - - logging.debug("User requested 'customize', launching dialog") try: - self._show_customize_dialog(guest) + self.set_finish_cursor() + + # This encodes all the virtinst defaults up front, so the customize + # dialog actually shows disk buses, cache values, default devices, + # etc. Not required for straight start_install but doesn't hurt. + self._guest.set_install_defaults() + + if not self.widget("summary-customize").get_active(): + self._start_install(self._guest) + return + + logging.debug("User requested 'customize', launching dialog") + self._show_customize_dialog() except Exception as e: self.reset_finish_cursor() self.err.show_err(_("Error starting installation: ") + str(e)) @@ -2169,8 +2165,9 @@ class vmmCreate(vmmGObjectUI): self._customize_window = None window.cleanup() - def _show_customize_dialog(self, guest): - virtinst_guest = vmmDomainVirtinst(self.conn, guest, self._guest.uuid) + def _show_customize_dialog(self): + guest = self._guest + virtinst_guest = vmmDomainVirtinst(self.conn, guest, guest.uuid) def start_install_wrapper(ignore, guest): if not self.is_visible(): diff --git a/virtManager/domain.py b/virtManager/domain.py index f62ef254f..1d04adff0 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -1909,10 +1909,6 @@ class vmmDomainVirtinst(vmmDomain): vmmDomain.__init__(self, conn, backend, key) self._orig_xml = None - # This encodes all the virtinst defaults up front, so the customize - # dialog actually shows disk buses, cache values, default devices, etc. - backend.set_install_defaults() - self._refresh_status() logging.debug("%s initialized with XML=\n%s", self, self._XMLDesc(0)) diff --git a/virtinst/guest.py b/virtinst/guest.py index b74a6a96c..8810db1cb 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -138,7 +138,6 @@ class Guest(XMLBuilder): self.x86_cpu_default = self.cpu.SPECIAL_MODE_HOST_MODEL_ONLY self.__osinfo = None - self._random_uuid = None self._install_cdrom_device = None self._defaults_are_set = False @@ -169,7 +168,6 @@ class Guest(XMLBuilder): self.maxmemory = val return val memory = XMLProperty("./currentMemory", is_int=True, - default_cb=lambda s: 1, set_converter=_set_memory) maxmemory = XMLProperty("./memory", is_int=True) hotplugmemorymax = XMLProperty("./maxMemory", is_int=True) @@ -184,21 +182,14 @@ class Guest(XMLBuilder): self.curvcpus = val return val vcpus = XMLProperty("./vcpu", is_int=True, - set_converter=_set_vcpus, - default_cb=lambda s: 1) + set_converter=_set_vcpus) curvcpus = XMLProperty("./vcpu/@current", is_int=True) vcpu_placement = XMLProperty("./vcpu/@placement") cpuset = XMLProperty("./vcpu/@cpuset") - def _get_default_uuid(self): - if self._random_uuid is None: - self._random_uuid = util.generate_uuid(self.conn) - return self._random_uuid - uuid = XMLProperty("./uuid", default_cb=_get_default_uuid) - - + uuid = XMLProperty("./uuid") id = XMLProperty("./@id", is_int=True) - type = XMLProperty("./@type", default_cb=lambda s: "xen") + type = XMLProperty("./@type") bootloader = XMLProperty("./bootloader") description = XMLProperty("./description") title = XMLProperty("./title") @@ -749,6 +740,10 @@ class Guest(XMLBuilder): dev.path = None def _set_defaults(self): + if not self.uuid: + self.uuid = util.generate_uuid(self.conn) + if not self.vcpus: + self.vcpus = 1 if self.os.is_xenpv() or self.type == "vz": self.emulator = None