[gnome-boxes/wip/image-import: 1/8] Add support for importing ready-made VMs
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/image-import: 1/8] Add support for importing ready-made VMs
- Date: Thu, 6 Jun 2013 20:48:23 +0000 (UTC)
commit 6ecf0372a07db24d2c0ccd90979a3896a7f0f943
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jun 5 04:27:04 2013 +0300
Add support for importing ready-made VMs
Currently only 'qcow2' and 'raw' images are supported.
Issues/TODO:
* Report progress of import.
* We don't really cancel the import if box is deleted.
src/libvirt-broker.vala | 3 +++
src/media-manager.vala | 19 +++++++++++++++----
src/vm-configurator.vala | 8 ++++++++
src/wizard-source.vala | 2 ++
4 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/src/libvirt-broker.vala b/src/libvirt-broker.vala
index 2a71768..2073570 100644
--- a/src/libvirt-broker.vala
+++ b/src/libvirt-broker.vala
@@ -56,6 +56,9 @@ private class Boxes.LibvirtBroker : Boxes.Broker {
if (VMConfigurator.is_install_config (config) || VMConfigurator.is_live_config (config)) {
debug ("Continuing installation/live session for '%s', ..", machine.name);
new VMCreator.for_install_completion (machine); // This instance will take care of its own
lifecycle
+ } else if (VMConfigurator.is_import_config (config)) {
+ debug ("Continuing import of '%s', ..", machine.name);
+ new VMImporter.for_import_completion (machine); // This instance will take care of its own
lifecycle
}
} catch (GLib.Error error) {
warning ("Failed to create source '%s': %s", source.name, error.message);
diff --git a/src/media-manager.vala b/src/media-manager.vala
index 902f1b3..270bd76 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -25,21 +25,32 @@ private class Boxes.MediaManager : Object {
public async InstallerMedia create_installer_media_for_path (string path,
Cancellable? cancellable = null) throws
GLib.Error {
- var media = yield new InstallerMedia.for_path (path, this, cancellable);
+ var media = is_mime_type (path, "application/x-cd-image") ?
+ yield new InstallerMedia.for_path (path, this, cancellable) :
+ new InstalledMedia (path);
return create_installer_media_from_media (media);
}
public async InstallerMedia? create_installer_media_from_config (GVirConfig.Domain config) {
var path = VMConfigurator.get_source_media_path (config);
+ if (path == null)
+ return null;
+
+ if (VMConfigurator.is_import_config (config))
+ try {
+ return new InstalledMedia (path);
+ } catch (GLib.Error error) {
+ debug ("%s", error.message);
+
+ return null;
+ }
+
var label = config.title;
Os? os = null;
Media? os_media = null;
- if (path == null)
- return null;
-
try {
var os_id = VMConfigurator.get_os_id (config);
if (os_id != null) {
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index afd1f10..5150517 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -13,9 +13,11 @@ private class Boxes.VMConfigurator {
private const string BOXES_XML = "<gnome-boxes>%s</gnome-boxes>";
private const string LIVE_STATE = "live";
private const string INSTALLATION_STATE = "installation";
+ private const string IMPORT_STATE = "importing";
private const string INSTALLED_STATE = "installed";
private const string LIVE_XML = "<os-state>" + LIVE_STATE + "</os-state>";
private const string INSTALLATION_XML = "<os-state>" + INSTALLATION_STATE + "</os-state>";
+ private const string IMPORT_XML = "<os-state>" + IMPORT_STATE + "</os-state>";
private const string INSTALLED_XML = "<os-state>" + INSTALLED_STATE + "</os-state>";
private const string OS_ID_XML = "<os-id>%s</os-id>";
@@ -125,6 +127,10 @@ private class Boxes.VMConfigurator {
return get_os_state (domain) == LIVE_STATE;
}
+ public static bool is_import_config (Domain domain) {
+ return get_os_state (domain) == IMPORT_STATE;
+ }
+
public static StorageVol create_volume_config (string name, int64 storage) throws GLib.Error {
var volume = new StorageVol ();
volume.set_name (name);
@@ -330,6 +336,8 @@ private class Boxes.VMConfigurator {
if (installed)
custom_xml = INSTALLED_XML;
+ else if (install_media is InstalledMedia)
+ custom_xml = IMPORT_XML;
else
custom_xml = (install_media.live) ? LIVE_XML : INSTALLATION_XML;
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 591223e..36f6043 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -309,6 +309,8 @@ private class Boxes.WizardSource: GLib.Object {
dialog.local_only = true;
dialog.filter = new Gtk.FileFilter ();
dialog.filter.add_mime_type ("application/x-cd-image");
+ dialog.filter.add_pattern ("*.img");
+ dialog.filter.add_pattern ("*.qcow2");
var ret = false;
if (dialog.run () == Gtk.ResponseType.ACCEPT) {
uri = dialog.get_uri ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]