[gnome-boxes/wip/image-import: 8/9] Add VMImporter class
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/image-import: 8/9] Add VMImporter class
- Date: Wed, 5 Jun 2013 01:38:22 +0000 (UTC)
commit 7bcecddce2ff64c67d9b8a403d25158f94dc73f2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jun 5 04:25:28 2013 +0300
Add VMImporter class
This subclass of VMCreator will be responsible for importing the VM
after its creation.
src/Makefile.am | 1 +
src/vm-creator.vala | 10 ++++----
src/vm-importer.vala | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 5 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5035778..12c41db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -112,6 +112,7 @@ gnome_boxes_SOURCES = \
util-app.vala \
vm-configurator.vala \
vm-creator.vala \
+ vm-importer.vala \
vnc-display.vala \
wizard-source.vala \
wizard.vala \
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 7bf43c4..e1951f8 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -8,7 +8,7 @@ private class Boxes.VMCreator {
// of error. Its better to report '100%' done while its not exactly 100% than reporting '99%' done
forever..
private const int INSTALL_COMPLETE_PERCENT = 99;
- public InstallerMedia? install_media { get; private set; }
+ public InstallerMedia? install_media { get; protected set; }
protected virtual string target_volume_format { get { return "qcow2"; } }
private Connection? connection { owned get { return App.app.default_connection; } }
@@ -61,7 +61,7 @@ private class Boxes.VMCreator {
return LibvirtBroker.get_default ().add_domain (App.app.default_source, App.app.default_connection,
domain);
}
- public void launch_vm (LibvirtMachine machine) throws GLib.Error {
+ public virtual void launch_vm (LibvirtMachine machine) throws GLib.Error {
if (!(install_media is UnattendedInstaller) || !(install_media as
UnattendedInstaller).express_install) {
ulong signal_id = 0;
@@ -83,7 +83,7 @@ private class Boxes.VMCreator {
update_machine_info (machine);
}
- private async void continue_installation (LibvirtMachine machine) {
+ protected virtual async void continue_installation (LibvirtMachine machine) {
install_media = yield MediaManager.get_instance ().create_installer_media_from_config
(machine.domain_config);
num_reboots = VMConfigurator.get_num_reboots (machine.domain_config);
var name = machine.domain.get_name ();
@@ -172,7 +172,7 @@ private class Boxes.VMCreator {
}
}
- private void update_machine_info (LibvirtMachine machine) {
+ protected virtual void update_machine_info (LibvirtMachine machine) {
if (VMConfigurator.is_install_config (machine.domain_config)) {
machine.info = _("Installing...");
@@ -181,7 +181,7 @@ private class Boxes.VMCreator {
machine.info = _("Live");
}
- private void set_post_install_config (LibvirtMachine machine) {
+ protected void set_post_install_config (LibvirtMachine machine) {
debug ("Setting post-installation configuration on '%s'", machine.name);
try {
var config = machine.domain.get_config (GVir.DomainXMLFlags.INACTIVE);
diff --git a/src/vm-importer.vala b/src/vm-importer.vala
new file mode 100644
index 0000000..90da806
--- /dev/null
+++ b/src/vm-importer.vala
@@ -0,0 +1,65 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+using Osinfo;
+using GVir;
+
+private class Boxes.VMImporter : Boxes.VMCreator {
+ public InstalledMedia source_media { get { return install_media as InstalledMedia; } }
+ protected override string target_volume_format { get { return source_media.format; } }
+
+ public VMImporter (InstalledMedia source_media) {
+ base (source_media);
+ }
+
+ public VMImporter.for_import_completion (LibvirtMachine machine) {
+ base.for_install_completion (machine);
+ }
+
+ public override void launch_vm (LibvirtMachine machine) throws GLib.Error {
+ machine.vm_creator = this;
+ machine.config.access_last_time = get_real_time ();
+ update_machine_info (machine);
+
+ import_vm.begin (machine);
+ }
+
+ protected override async void continue_installation (LibvirtMachine machine) {
+ install_media = yield MediaManager.get_instance ().create_installer_media_from_config
(machine.domain_config);
+ machine.vm_creator = this;
+ update_machine_info (machine);
+
+ yield import_vm (machine);
+ }
+
+ protected override void update_machine_info (LibvirtMachine machine) {
+ machine.info = _("Importing...");
+ }
+
+ private async void import_vm (LibvirtMachine machine) {
+ try {
+ var source = File.new_for_path (source_media.device_file);
+ var destination_path = machine.storage_volume.get_path ();
+ var destination = File.new_for_path (destination_path);
+
+ yield source.copy_async (destination, FileCopyFlags.OVERWRITE, Priority.DEFAULT, null);
+ } catch (GLib.Error error) {
+ warning ("Failed to import box '%s' from file '%s': %s",
+ machine.name,
+ source_media.device_file,
+ error.message);
+ var ui_message = _("Box import from file '%s' failed.").printf (source_media.device_file);
+ App.app.notificationbar.display_error (ui_message);
+ machine.delete ();
+
+ return;
+ }
+
+ set_post_install_config (machine);
+ try {
+ machine.domain.start (0);
+ } catch (GLib.Error error) {
+ warning ("Failed to start domain '%s': %s", machine.domain.get_name (), error.message);
+ }
+ machine.info = null;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]