[gnome-boxes] Add LibvirtVMCloner



commit 755ac35afa6f308ece50089668e2f3aff2c71c68
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue May 3 21:58:44 2016 +0100

    Add LibvirtVMCloner
    
    This subclass of LibvirtVMImporter will be handling the cloning of
    libvirt VMs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710307

 src/Makefile.am            |    1 +
 src/libvirt-vm-cloner.vala |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3ac0208..52bfd4c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -149,6 +149,7 @@ gnome_boxes_SOURCES =                               \
        vm-creator.vala                         \
        vm-importer.vala                        \
        libvirt-system-importer.vala            \
+       libvirt-vm-cloner.vala                  \
        libvirt-vm-importer.vala                \
        vnc-display.vala                        \
        wizard-window.vala                      \
diff --git a/src/libvirt-vm-cloner.vala b/src/libvirt-vm-cloner.vala
new file mode 100644
index 0000000..5df27f9
--- /dev/null
+++ b/src/libvirt-vm-cloner.vala
@@ -0,0 +1,30 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+private class Boxes.LibvirtVMCloner : Boxes.LibvirtVMImporter {
+    public LibvirtVMCloner (InstalledMedia source_media) {
+        base (source_media);
+    }
+
+    public LibvirtVMCloner.for_cloning_completion (LibvirtMachine machine) {
+        base.for_import_completion (machine);
+    }
+
+    protected override async void post_import_setup (LibvirtMachine machine) {
+        try {
+            var image_path = machine.storage_volume.get_path ();
+            var argv = new string[] { "virt-sysprep", "-a", image_path };
+            string std_output, std_error;
+
+            yield exec (argv, null, out std_output, out std_error);
+
+            if (std_error != "")
+                debug ("Error output from virt-sysprep command: %s", std_error);
+            debug ("Standard output from virt-sysprep command: %s", std_output);
+        } catch (GLib.Error error) {
+            // We don't want hard dep on libguestfs-tools so it's OK if virt-sysprep command fails
+            debug ("Failed to run virt-sysprep: %s. You're on your own.", error.message);
+        }
+
+        yield base.post_import_setup (machine);
+    }
+}


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