diff options
author | Daniel P. Berrangé <berrange@redhat.com> | 2021-10-29 14:39:33 +0100 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2022-01-20 14:16:39 -0500 |
commit | 5622854d8ca97d8b7f8c556107f32c19a2d06973 (patch) | |
tree | 03824ed7e99759c46fe834b2fb052e2c8a4b55ff | |
parent | 883419c2144cf8d236589d873f016e0472774ace (diff) | |
download | virt-manager-5622854d8ca97d8b7f8c556107f32c19a2d06973.tar.gz |
virtinst: refactor setting of default vcpus count
The sync_vcpus_topology method will sometimes set the self.vcpus prop,
but other times leave it unset. This is confusing an unhelpful
behaviour. Both callers have logic to set the self.vcpus prop
to a default value of sync_vcpus_topology failed to do so. It makes
more sense to just pass this default value in.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
-rw-r--r-- | virtinst/guest.py | 16 | ||||
-rw-r--r-- | virtinst/virtinstall.py | 6 |
2 files changed, 7 insertions, 15 deletions
diff --git a/virtinst/guest.py b/virtinst/guest.py index e123fa22..f11a105e 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -692,16 +692,17 @@ class Guest(XMLBuilder): log.warning( # pragma: no cover "KVM acceleration not available, using '%s'", self.type) - def sync_vcpus_topology(self): + def sync_vcpus_topology(self, defCPUs): """ <cpu> topology count and <vcpus> always need to match. Handle the syncing here since we are less constrained then doing it in CPU set_defaults """ - if not self.cpu.has_topology(): - return if not self.vcpus: - self.vcpus = self.cpu.vcpus_from_topology() + if self.cpu.has_topology(): + self.vcpus = self.cpu.vcpus_from_topology() + else: + self.vcpus = defCPUs self.cpu.set_topology_defaults(self.vcpus) def set_defaults(self, _guest): @@ -710,12 +711,7 @@ class Guest(XMLBuilder): if not self.uuid: self.uuid = Guest.generate_uuid(self.conn) - self.sync_vcpus_topology() - if not self.vcpus: - # Typically if omitted libvirt will fill this value in for us - # However if user specified cpuset= or placement=, libvirt - # will error if <vcpus>X is also unset. So keep this for safety - self.vcpus = 1 + self.sync_vcpus_topology(1) self._set_default_machine() self._set_default_uefi() diff --git a/virtinst/virtinstall.py b/virtinst/virtinstall.py index 2bb52d78..55190115 100644 --- a/virtinst/virtinstall.py +++ b/virtinst/virtinstall.py @@ -489,11 +489,7 @@ def set_cli_defaults(options, guest): if ncpus: # We need to do this upfront, so we don't incorrectly set guest.vcpus - guest.sync_vcpus_topology() - if not guest.vcpus: - # I don't think we need to print anything here as this was never - # a required value. - guest.vcpus = ncpus + guest.sync_vcpus_topology(ncpus) if storage and not storage_specified(options, guest): diskstr = 'size=%d' % (storage // (1024 ** 3)) |