[gnome-boxes] vm-creator: get_storage_pool() -> Util.ensure_storage_pool()
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] vm-creator: get_storage_pool() -> Util.ensure_storage_pool()
- Date: Wed, 15 Jul 2015 16:48:04 +0000 (UTC)
commit 9ebdcf9caa95c75fdd7e03c0fd8d3810b37e4db1
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.
https://bugzilla.gnome.org/show_bug.cgi?id=752417
src/util-app.vala | 23 +++++++++++++++++++++++
src/vm-creator.vala | 27 ++-------------------------
src/vm-importer.vala | 2 +-
3 files changed, 26 insertions(+), 26 deletions(-)
---
diff --git a/src/util-app.vala b/src/util-app.vala
index 0f13a6b..0366fa8 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -102,6 +102,29 @@ 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);
+ }
+ pool.set_autostart (true);
+
+ 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 68f25be..9060ef3 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -189,29 +189,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);
- }
- pool.set_autostart (true);
-
- return pool;
- }
-
protected virtual async GVirConfig.Domain create_domain_config (string name,
string title,
StorageVol volume,
@@ -282,7 +259,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
@@ -294,7 +271,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 6f761ad..e1514c7 100644
--- a/src/vm-importer.vala
+++ b/src/vm-importer.vala
@@ -37,7 +37,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]