From 8b371b6e22d86da94d3996584fbdf496bbf41d63 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 8 Dec 2010 12:17:14 -0500 Subject: [PATCH] Domain: Pass pre-parsed capabilities to virtinst objects Saves us from continually refetching caps and parsing. Also, only refresh connection caps when we launch the create wizard: changing caps shouldn't be common, and are really only important when creating guests. --- src/virtManager/connection.py | 23 ++++++++--------------- src/virtManager/create.py | 1 + src/virtManager/domain.py | 4 +++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/virtManager/connection.py b/src/virtManager/connection.py index f6aefc0c2..8c57ab7bf 100644 --- a/src/virtManager/connection.py +++ b/src/virtManager/connection.py @@ -261,30 +261,24 @@ class vmmConnection(gobject.GObject): def get_uri(self): return self.uri - def _invalidate_caps(self): + def invalidate_caps(self): self._caps_xml = None self._caps = None def _check_caps(self): - self._caps_xml = self.vmm.getCapabilities() - self._caps = virtinst.CapabilitiesParser.parse(self._caps_xml) + if not (self._caps_xml or self._caps): + self._caps_xml = self.vmm.getCapabilities() + self._caps = virtinst.CapabilitiesParser.parse(self._caps_xml) def get_capabilities_xml(self): - xml = None - while xml == None: + if not self._caps_xml: self._check_caps() - xml = self._caps_xml - - return xml + return self._caps_xml def get_capabilities(self): - # Make sure we aren't returning None - caps = None - while caps == None: + if not self._caps: self._check_caps() - caps = self._caps - - return caps + return self._caps def get_max_vcpus(self, _type=None): return virtinst.util.get_max_vcpus(self.vmm, _type) @@ -1453,7 +1447,6 @@ class vmmConnection(gobject.GObject): return self.hostinfo = self.vmm.getInfo() - self._invalidate_caps() # Poll for new virtual network objects (startNets, stopNets, newNets, diff --git a/src/virtManager/create.py b/src/virtManager/create.py index 8225d9e6e..f12046dc6 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -399,6 +399,7 @@ class vmmCreate(gobject.GObject): # A bit out of order, but populate arch + hv lists so we can # determine a default + self.conn.invalidate_caps() self.caps = self.conn.get_capabilities() self.change_caps() self.populate_hv() diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py index 8335901fe..b790e5fbc 100644 --- a/src/virtManager/domain.py +++ b/src/virtManager/domain.py @@ -1112,7 +1112,9 @@ class vmmDomain(vmmDomainBase): return self._guest def _build_guest(self, xml): - return virtinst.Guest(connection=self.connection.vmm, parsexml=xml) + return virtinst.Guest(connection=self.connection.vmm, + parsexml=xml, + caps=self.connection.get_capabilities()) def _reparse_xml(self, ignore=None): self._guest = self._build_guest(self._get_domain_xml())