From 00f8dea370ae0874dc655d3718978a6a8e397a34 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 3 Apr 2019 15:17:08 +0200 Subject: domcapabilities: add caching of CPU security features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé --- virtinst/domcapabilities.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'virtinst/domcapabilities.py') 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" -- cgit v1.2.1