summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2021-10-29 13:31:12 +0100
committerCole Robinson <crobinso@redhat.com>2022-01-20 14:16:39 -0500
commit883419c2144cf8d236589d873f016e0472774ace (patch)
treef79a2bbdf75ef97668c4bbe62a4b7c8e12f8b7f6
parent9a578e1ac58eccd7b7a8123ce7fe22cbf8080b3a (diff)
downloadvirt-manager-883419c2144cf8d236589d873f016e0472774ace.tar.gz
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>
-rw-r--r--tests/test_misc.py4
-rw-r--r--virtinst/domain/cpu.py9
2 files changed, 9 insertions, 4 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 25e12f94..07cd484f 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -31,6 +31,10 @@ def test_misc_cpu_topology():
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)
assert get_top(cpu) == [2, 1, 3, 1]
diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py
index f6f9eabb..22a90d3a 100644
--- a/virtinst/domain/cpu.py
+++ b/virtinst/domain/cpu.py
@@ -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)