[virt-tools-list] [virt-manager PATCH 4/5] domcapabilities: add caching of CPU security features

Pavel Hrdina phrdina at redhat.com
Wed Apr 3 13:52:50 UTC 2019


We will call this function multiple times so it makes sense to cache the
result so we don't have to call libvirt APIs every time we will check
what security features are available on the host.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 virtinst/domcapabilities.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
index 3e203c5a..922a4c21 100644
--- a/virtinst/domcapabilities.py
+++ b/virtinst/domcapabilities.py
@@ -272,6 +272,8 @@ class DomainCapabilities(XMLBuilder):
 
         return DomainCpu(self.conn, expandedXML)
 
+    _features = None
+
     def get_cpu_security_features(self):
         sec_features = [
                 'spec-ctrl',
@@ -279,7 +281,10 @@ class DomainCapabilities(XMLBuilder):
                 'ibpb',
                 'virt-ssbd']
 
-        features = []
+        if self._features:
+            return self._features
+
+        self._features = []
 
         for m in self.cpu.modes:
             if m.name != "host-model" or not m.supported:
@@ -293,9 +298,9 @@ class DomainCapabilities(XMLBuilder):
 
             for feature in cpu.features:
                 if feature.name in sec_features:
-                    features.append(feature.name)
+                    self._features.append(feature.name)
 
-        return features
+        return self._features
 
 
     XML_NAME = "domainCapabilities"
-- 
2.20.1




More information about the virt-tools-list mailing list