diff --git a/tests/cli-test-xml/compare/virt-install-default-f27.xml b/tests/cli-test-xml/compare/virt-install-default-f27.xml index a04459f5..81623d06 100644 --- a/tests/cli-test-xml/compare/virt-install-default-f27.xml +++ b/tests/cli-test-xml/compare/virt-install-default-f27.xml @@ -8,7 +8,7 @@ 65536 65536 - 2 + 1 exe /bin/sh diff --git a/virt-install b/virt-install index 7c258519..bbd24d03 100755 --- a/virt-install +++ b/virt-install @@ -519,18 +519,26 @@ def build_installer(options, guest): def set_resources_from_osinfo(options, guest): if guest.os.is_container(): return - if options.disk: - return + + # We need to do this upfront, so we don't incorrectly set guest.vcpus + guest.sync_vcpus_topology() res = guest.osinfo.get_recommended_resources() storage = res.get_recommended_storage(guest.os.arch) - if not storage: - return + ram = res.get_recommended_ram(guest.os.arch) + ncpus = res.get_recommended_ncpus(guest.os.arch) - diskstr = 'size=%d' % (storage // (1024 ** 3)) - logging.debug("Generated default libosinfo '--disk %s'", diskstr) - options.disk = [diskstr] - cli.ParserDisk(diskstr, guest=guest).parse(None) + if ram and not guest.currentMemory: + guest.currentMemory = ram // 1024 + + if ncpus and not guest.vcpus: + guest.vcpus = ncpus + + if storage and not options.disk: + diskstr = 'size=%d' % (storage // (1024 ** 3)) + logging.debug("Generated default libosinfo '--disk %s'", diskstr) + options.disk = [diskstr] + cli.ParserDisk(diskstr, guest=guest).parse(None) def build_guest_instance(conn, options): diff --git a/virtinst/guest.py b/virtinst/guest.py index 341dd87c..a752997a 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -676,7 +676,9 @@ class Guest(XMLBuilder): self.uuid = Guest.generate_uuid(self.conn) self.sync_vcpus_topology() - self._set_default_resources() + if not self.vcpus: + self.vcpus = 1 + self._set_default_machine() self._set_default_uefi() @@ -708,19 +710,6 @@ class Guest(XMLBuilder): # Private xml routines # ######################## - def _set_default_resources(self): - res = self.osinfo.get_recommended_resources() - - if not self.currentMemory: - ram = res.get_recommended_ram(self.os.arch) - if ram: - self.currentMemory = ram // 1024 - - if not self.vcpus: - ncpus = res.get_recommended_ncpus(self.os.arch) - self.vcpus = ncpus or 1 - - def _set_default_machine(self): if self.os.machine: return