Blob Blame History Raw
From 763fa93d4cb13c819278dd942b536428ef75515d Mon Sep 17 00:00:00 2001
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 19 May 2017 14:26:49 +0200
Subject: virtManager.connection: introduce cb_add_new_pool

The cb_add_new_pool callback will add a newly created storage pool
into virt-manager's cache so we don't have to wait for the libvirt
event to be handled.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1435064

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 168651188674f35ce4afd8b3c0bac1a6be2317c0)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 virtManager/connection.py | 9 +++++++--
 virtinst/connection.py    | 1 +
 virtinst/storage.py       | 3 +++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/virtManager/connection.py b/virtManager/connection.py
index 49979182..12e36a13 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -286,6 +286,10 @@ class vmmConnection(vmmGObject):
             return ret
         self._backend.cb_fetch_all_vols = fetch_all_vols
 
+        def add_new_pool(obj, key):
+            self._new_object_cb(vmmStoragePool(self, obj, key), False, True)
+        self._backend.cb_add_new_pool = add_new_pool
+
         def clear_cache(pools=False):
             if not pools:
                 return
@@ -973,6 +977,7 @@ class vmmConnection(vmmGObject):
         self._backend.cb_fetch_all_nodedevs = None
         self._backend.cb_fetch_all_vols = None
         self._backend.cb_clear_cache = None
+        self._backend.cb_add_new_pool = None
 
     def open(self):
         if not self.is_disconnected():
@@ -1132,7 +1137,7 @@ class vmmConnection(vmmGObject):
                 self.emit("nodedev-removed", obj.get_connkey())
             obj.cleanup()
 
-    def _new_object_cb(self, obj, initialize_failed):
+    def _new_object_cb(self, obj, initialize_failed, skip_init=False):
         if not self._backend.is_open():
             return
 
@@ -1165,7 +1170,7 @@ class vmmConnection(vmmGObject):
             elif class_name == "nodedev":
                 self.emit("nodedev-added", obj.get_connkey())
         finally:
-            if self._init_object_event:
+            if self._init_object_event and not skip_init:
                 self._init_object_count -= 1
                 if self._init_object_count <= 0:
                     self._init_object_event.set()
diff --git a/virtinst/connection.py b/virtinst/connection.py
index e8d2378c..b2f37e67 100644
--- a/virtinst/connection.py
+++ b/virtinst/connection.py
@@ -86,6 +86,7 @@ class VirtualConnection(object):
         self.cb_fetch_all_vols = None
         self.cb_fetch_all_nodedevs = None
         self.cb_clear_cache = None
+        self.cb_add_new_pool = None
 
 
     ##############
diff --git a/virtinst/storage.py b/virtinst/storage.py
index 808891f3..647de931 100644
--- a/virtinst/storage.py
+++ b/virtinst/storage.py
@@ -560,6 +560,9 @@ class StoragePool(_StorageObject):
                               "%s" % str(e))
             raise RuntimeError(errmsg)
 
+        if self.conn.cb_add_new_pool:
+            self.conn.cb_add_new_pool(pool, self.name)
+
         return pool
 
 
-- 
2.13.0