[gnome-boxes/wip/dont-create-pool-dir] vm-creator: get_storage_pool() -> Util.ensure_storage_pool()



commit 697c1467c17a0b92b47f515b64f4dcd8f0165dac
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Jul 15 17:10:01 2015 +0100

    vm-creator: get_storage_pool() -> Util.ensure_storage_pool()
    
    Make protected function of VMCreator that ensures storage pool exists, a
    public utility function so other modules can use it too.

 src/util-app.vala    |   22 ++++++++++++++++++++++
 src/vm-creator.vala  |   26 ++------------------------
 src/vm-importer.vala |    2 +-
 3 files changed, 25 insertions(+), 25 deletions(-)
---
diff --git a/src/util-app.vala b/src/util-app.vala
index 202f0cf..2432f20 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -102,6 +102,28 @@ namespace Boxes {
         }
     }
 
+    public async GVir.StoragePool ensure_storage_pool (GVir.Connection connection) throws GLib.Error {
+        var pool = get_storage_pool (connection);
+        if (pool == null) {
+            debug ("Creating storage pool..");
+            var config = VMConfigurator.get_pool_config ();
+            pool = connection.create_storage_pool (config, 0);
+            yield pool.build_async (0, null);
+            debug ("Created storage pool.");
+        }
+
+        // Ensure pool directory exists in case user deleted it after pool creation
+        var pool_path = get_user_pkgdata ("images");
+        ensure_directory (pool_path);
+
+        if (pool.get_info ().state == GVir.StoragePoolState.INACTIVE) {
+            yield pool.start_async (0, null);
+            yield pool.refresh_async (null);
+        }
+
+        return pool;
+    }
+
     public GVir.StoragePool? get_storage_pool (GVir.Connection connection) {
         return connection.find_storage_pool_by_name (Config.PACKAGE_TARNAME);
     }
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 66cb6e7..1bbbfa1 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -203,28 +203,6 @@ private class Boxes.VMCreator {
         }
     }
 
-    protected async StoragePool get_storage_pool () throws GLib.Error {
-        var pool = Boxes.get_storage_pool (connection);
-        if (pool == null) {
-            debug ("Creating storage pool..");
-            var config = VMConfigurator.get_pool_config ();
-            pool = connection.create_storage_pool (config, 0);
-            yield pool.build_async (0, null);
-            debug ("Created storage pool.");
-        }
-
-        // Ensure pool directory exists in case user deleted it after pool creation
-        var pool_path = get_user_pkgdata ("images");
-        ensure_directory (pool_path);
-
-        if (pool.get_info ().state == StoragePoolState.INACTIVE) {
-            yield pool.start_async (0, null);
-            yield pool.refresh_async (null);
-        }
-
-        return pool;
-    }
-
     protected virtual async GVirConfig.Domain create_domain_config (string       name,
                                                                     string       title,
                                                                     StorageVol   volume,
@@ -361,7 +339,7 @@ private class Boxes.VMCreator {
 
         name = base_name;
         title = base_title;
-        var pool = yield get_storage_pool ();
+        var pool = yield Boxes.ensure_storage_pool (connection);
         for (var i = 2;
              connection.find_domain_by_name (name) != null ||
              connection.find_domain_by_name (title) != null || // We used to use title as name
@@ -373,7 +351,7 @@ private class Boxes.VMCreator {
     }
 
     private async StorageVol create_target_volume (string name, int64 storage) throws GLib.Error {
-        var pool = yield get_storage_pool ();
+        var pool = yield Boxes.ensure_storage_pool (connection);
 
         var config = VMConfigurator.create_volume_config (name, storage);
         debug ("Creating volume '%s'..", name);
diff --git a/src/vm-importer.vala b/src/vm-importer.vala
index c158540..0417593 100644
--- a/src/vm-importer.vala
+++ b/src/vm-importer.vala
@@ -43,7 +43,7 @@ private class Boxes.VMImporter : Boxes.VMCreator {
             yield source_media.copy (destination_path);
 
             // Without refreshing the pool, libvirt will not know of changes to volume we just made
-            var pool = yield get_storage_pool ();
+            var pool = yield Boxes.ensure_storage_pool (connection);
             yield pool.refresh_async (null);
         } catch (GLib.Error error) {
             warning ("Failed to import box '%s' from file '%s': %s",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]