domain: cpu: Rework vcpus setting slightly

Move it to Guest, where we have a more hollistic view of the issues.
This will be needed in later patches
This commit is contained in:
Cole Robinson 2019-06-10 18:58:34 -04:00
parent e859d17e1a
commit db4d348950
2 changed files with 17 additions and 14 deletions

View File

@ -208,10 +208,7 @@ class DomainCpu(XMLBuilder):
Determine the CPU count represented by topology, or 1 if
no topology is set
"""
self.set_topology_defaults()
if self.has_topology():
return self.sockets * self.cores * self.threads
return 1
return (self.sockets or 1) * (self.cores or 1) * (self.threads or 1)
def has_topology(self):
"""
@ -219,14 +216,11 @@ class DomainCpu(XMLBuilder):
"""
return bool(self.sockets or self.cores or self.threads)
def set_topology_defaults(self, vcpus=None):
def set_topology_defaults(self, vcpus):
"""
Fill in unset topology values, using the passed vcpus count if
required
"""
if not self.has_topology():
return
if vcpus is None:
if self.sockets is None:
self.sockets = 1
@ -306,8 +300,6 @@ class DomainCpu(XMLBuilder):
self._validate_default_host_model_only(guest)
def set_defaults(self, guest):
self.set_topology_defaults(guest.vcpus)
if not self.conn.is_test() and not self.conn.is_qemu():
return
if (self.get_xml().strip() or

View File

@ -657,14 +657,25 @@ class Guest(XMLBuilder):
logging.warning("KVM acceleration not available, using '%s'",
self.type)
def set_defaults(self, _guest):
if not self.uuid:
self.uuid = Guest.generate_uuid(self.conn)
if not self.vcpus and self.cpu.has_topology():
def sync_vcpus_topology(self):
"""
<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()
self.cpu.set_topology_defaults(self.vcpus)
def set_defaults(self, _guest):
self.set_capabilities_defaults()
if not self.uuid:
self.uuid = Guest.generate_uuid(self.conn)
self.sync_vcpus_topology()
self._set_default_resources()
self._set_default_machine()
self._set_default_uefi()