[gnome-boxes/wip/system-libvirt-import2: 3/3] tmp
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/system-libvirt-import2: 3/3] tmp
- Date: Sun, 10 Nov 2013 21:41:39 +0000 (UTC)
commit a191d53cc88bf77ad898d520e878bea547951d9e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Oct 15 20:49:41 2013 -0400
tmp
src/libvirt-system-importer.vala | 56 +++++++++++++++++++++++++++++++++++
src/libvirt-system-media.vala | 26 ++++++++++++++++
src/libvirt-system-vm-importer.vala | 38 +++++++++++++++++++++++
src/vm-importer.vala | 12 +++++--
4 files changed, 128 insertions(+), 4 deletions(-)
---
diff --git a/src/libvirt-system-importer.vala b/src/libvirt-system-importer.vala
new file mode 100644
index 0000000..8da58eb
--- /dev/null
+++ b/src/libvirt-system-importer.vala
@@ -0,0 +1,56 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using GVir;
+
+private class Boxes.LibvirtSystemImporter: GLib.Object {
+ public bool import_needed {
+ get {
+ return (domains.length () + pools.length ()) != 0;
+ }
+ }
+
+ private GVir.Connection connection;
+ private GLib.List<GVir.Domain> domains;
+ private GLib.List<GVir.StoragePool> pools;
+
+ public LibvirtSystemImporter () throws GLib.Error {
+ connection = new GVir.Connection ("qemu+unix:///system");
+
+ yield connection.open_read_only_async (null);
+ yield connection.fetch_domains_async (null);
+
+ domains = connection.get_domains ();
+ }
+
+ public void import () {
+ foreach (var domain in domains) {
+ string device_file = null;
+
+ var config = domain.get_config (DomainXMLFlags.INACTIVE);
+ var devices = config.get_devices ();
+ foreach (var device in devices) {
+ if (!(device is DomainDisk))
+ continue;
+
+ var disk = device as DomainDisk;
+ if (disk.get_guest_device_type () == DomainDiskGuestDeviceType.DISK) {
+ device_file = disk.get_source ();
+
+ break;
+ }
+ }
+
+ if (device_file == null) {
+ warning ("Failed to find suitable disk to import for ''", config.name);
+
+ break;
+ }
+
+ var media = new InstalledMedia (device_file);
+ var vm_importer = _media.get_vm_creator ();
+ vm_creator.create_vm.begin (null, (obj, result) => {
+ machine = vm_creator.create_vm.end (result);
+ vm_importer.lauch_vm.begin (machine);
+ });
+ }
+ }
+}
diff --git a/src/libvirt-system-media.vala b/src/libvirt-system-media.vala
new file mode 100644
index 0000000..9fd033c
--- /dev/null
+++ b/src/libvirt-system-media.vala
@@ -0,0 +1,26 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+using GVirConfig;
+
+private class Boxes.LibvirtSystemMedia : Boxes.InstalledMedia {
+ private string _architecture;
+ protected override string? architecture {
+ owned get {
+ domain_config.get_os ().get_arch ();
+ }
+ }
+
+ private Domain domain_config;
+
+ public async InstalledMedia (string path, Domain domain_config) throws GLib.Error {
+ device_file = path;
+ this.domain_config = domain_config;
+ from_image = true;
+
+ label = domain_config.title?? domain_config.name;
+ }
+
+ public override VMCreator get_vm_creator () {
+ return new LibvirtSystemVMImporter (this);
+ }
+}
diff --git a/src/libvirt-system-vm-importer.vala b/src/libvirt-system-vm-importer.vala
new file mode 100644
index 0000000..71cfc1f
--- /dev/null
+++ b/src/libvirt-system-vm-importer.vala
@@ -0,0 +1,38 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+using Osinfo;
+using GVirConfig;
+
+private class Boxes.LibvirtSystemVMImporter : Boxes.VMImporter {
+ public LibvirtSystemVMImporter (InstalledMedia source_media) {
+ base (source_media);
+ start_after_import = false;
+ }
+
+ public LibvirtSystemVMImporter.for_import_completion (LibvirtMachine machine) {
+ base.for_install_completion (machine);
+ start_after_import = false;
+ }
+
+ protected override async Domain create_domain_config (string name,
+ string title,
+ GVir.StorageVol volume,
+ Cancellable? cancellable) throws GLib.Error {
+ var media = install_media as LibvirtSystemMedia;
+ var devices = install_media.domain_config.get_devices ();
+ foreach (var device in devices) {
+ if (!(device is DomainDisk))
+ continue;
+
+ var disk = device as DomainDisk;
+ if (disk.get_source () == media.device_file) {
+ disk.set_source (volume.get_path ());
+
+ break;
+ }
+ }
+ install_media.domain_config.set_devices (devices);
+
+ return domain_config;
+ }
+}
diff --git a/src/vm-importer.vala b/src/vm-importer.vala
index c96aa79..38dbb7c 100644
--- a/src/vm-importer.vala
+++ b/src/vm-importer.vala
@@ -6,6 +6,8 @@ using GVir;
private class Boxes.VMImporter : Boxes.VMCreator {
public InstalledMedia source_media { get { return install_media as InstalledMedia; } }
+ protected bool start_after_import = true;
+
public VMImporter (InstalledMedia source_media) {
base (source_media);
}
@@ -56,10 +58,12 @@ private class Boxes.VMImporter : Boxes.VMCreator {
}
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);
+ if (start_after_import) {
+ 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;
machine.vm_creator = null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]