virtinst: allow to force create topology from scratch

When setting CPU defaults we want to force create the topology even if
the user has not specified anything. In particular this allows for
overriding the QEMU defaults, to expose vCPUs as cores instead of
sockets which is a much saner default for Windows.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-10-29 13:31:12 +01:00 committed by Cole Robinson
parent 9a578e1ac5
commit 883419c214
2 changed files with 9 additions and 4 deletions

View File

@ -30,6 +30,10 @@ def test_misc_cpu_topology():
cpu.set_topology_defaults(6)
assert cpu.topology.sockets is None
cpu = virtinst.DomainCpu(conn)
cpu.set_topology_defaults(6, create=True)
assert get_top(cpu) == [1, 1, 6, 1]
cpu = virtinst.DomainCpu(conn)
cpu.topology.sockets = "2"
cpu.set_topology_defaults(6)

View File

@ -401,13 +401,14 @@ class DomainCpu(XMLBuilder):
"""
return bool(self.topology.get_xml())
def set_topology_defaults(self, vcpus):
def set_topology_defaults(self, vcpus, create=False):
"""
Fill in unset topology values, using the passed vcpus count.
Will not set topology from scratch, this just fills in missing
topology values.
If @create is False, this will not set topology from scratch,
just fill in missing topology values.
If @create is True, this will create topology from scratch.
"""
if not self.has_topology():
if not self.has_topology() and not create:
return
self.topology.set_defaults_from_vcpus(vcpus)