diff --git a/tests/test_misc.py b/tests/test_misc.py index 25e12f947..07cd484f3 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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) diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py index f6f9eabb9..22a90d3a3 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)