diff options
author | Cole Robinson <crobinso@redhat.com> | 2020-08-27 18:02:10 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2020-08-27 19:41:28 -0400 |
commit | 34c6d1c7eaffdfd52d740524481e69145e657b5e (patch) | |
tree | 2705c71f5f40d652df70524bc03255f76ce3bccd /virtinst/domain | |
parent | ade6c34a963699a5b36a444cc68e6f9889826f66 (diff) | |
download | virt-manager-34c6d1c7eaffdfd52d740524481e69145e657b5e.tar.gz |
virtinst: cpu: Move topology elements to their own class
This is a no-op but will help with a future bug fix
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst/domain')
-rw-r--r-- | virtinst/domain/cpu.py | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py index 0e6f4f1e..670a9dd3 100644 --- a/virtinst/domain/cpu.py +++ b/virtinst/domain/cpu.py @@ -57,13 +57,43 @@ class _CPUFeature(XMLBuilder): policy = XMLProperty("./@policy") +class _CPUTopology(XMLBuilder): + """ + Class for generating <cpu> <topology> XML + """ + XML_NAME = "topology" + _XML_PROP_ORDER = ["sockets", "cores", "threads"] + + sockets = XMLProperty("./@sockets", is_int=True) + cores = XMLProperty("./@cores", is_int=True) + threads = XMLProperty("./@threads", is_int=True) + + def set_defaults_from_vcpus(self, vcpus): + if not self.sockets: + if not self.cores: + self.sockets = vcpus // self.threads + else: + self.sockets = vcpus // self.cores + + if not self.cores: + if not self.threads: + self.cores = vcpus // self.sockets + else: + self.cores = vcpus // (self.sockets * self.threads) + + if not self.threads: + self.threads = vcpus // (self.sockets * self.cores) + + return + + class DomainCpu(XMLBuilder): """ Class for generating <cpu> XML """ XML_NAME = "cpu" _XML_PROP_ORDER = ["mode", "match", "model", "vendor", - "sockets", "cores", "threads", "features"] + "topology", "features"] secure = True @@ -207,13 +237,15 @@ class DomainCpu(XMLBuilder): Determine the CPU count represented by topology, or 1 if no topology is set """ - return (self.sockets or 1) * (self.cores or 1) * (self.threads or 1) + return ((self.topology.sockets or 1) * + (self.topology.cores or 1) * + (self.topology.threads or 1)) def has_topology(self): """ Return True if any topology info is set """ - return bool(self.sockets or self.cores or self.threads) + return bool(self.topology.get_xml()) def set_topology_defaults(self, vcpus): """ @@ -223,29 +255,15 @@ class DomainCpu(XMLBuilder): """ if not self.has_topology(): return - - if not self.sockets: - if not self.cores: - self.sockets = vcpus // self.threads - else: - self.sockets = vcpus // self.cores - - if not self.cores: - if not self.threads: - self.cores = vcpus // self.sockets - else: - self.cores = vcpus // (self.sockets * self.threads) - - if not self.threads: - self.threads = vcpus // (self.sockets * self.cores) - - return + self.topology.set_defaults_from_vcpus(vcpus) ################## # XML properties # ################## + topology = XMLChildProperty(_CPUTopology, is_single=True) + model = XMLProperty("./model") model_fallback = XMLProperty("./model/@fallback") @@ -253,10 +271,6 @@ class DomainCpu(XMLBuilder): vendor = XMLProperty("./vendor") mode = XMLProperty("./@mode") - sockets = XMLProperty("./topology/@sockets", is_int=True) - cores = XMLProperty("./topology/@cores", is_int=True) - threads = XMLProperty("./topology/@threads", is_int=True) - ################## # Default config # |