[gnome-boxes/wip/kalev/ovf-support] Add support for loading .ova files



commit 5816cc41960214612d39e13bf7abb22100a59c79
Author: Kalev Lember <klember redhat com>
Date:   Wed Mar 30 15:10:03 2016 +0100

    Add support for loading .ova files
    
    This makes use of libovf-glib to load .ova files in the Open
    Virtualization Format.
    
    XXX: don't hardcode output disk image path, support multiple disks

 configure.ac             |    3 +++
 src/Makefile.am          |    1 +
 src/installed-media.vala |   21 ++++++++++++++++++++-
 3 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6dfa38c..3e18c2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,7 @@ TRACKER_SPARQL=0.13.1
 UUID_REQUIRED=1.41.3
 LIBSOUP_REQUIRED=2.38
 LIBARCHIVE_MIN_VERSION=3.0.0
+LIBOVF_GLIB_MIN_VERSION=0.1
 
 PKG_CHECK_MODULES(BOXES, [
   glib-2.0 >= $GLIB_MIN_VERSION
@@ -81,6 +82,7 @@ PKG_CHECK_MODULES(BOXES, [
   uuid >= $UUID_REQUIRED
   libsoup-2.4 >= $LIBSOUP_REQUIRED
   libarchive >= $LIBARCHIVE_MIN_VERSION
+  libovf-glib-0.1 >= $LIBOVF_GLIB_MIN_VERSION
 ])
 
 
@@ -140,6 +142,7 @@ VALA_CHECK([0.28.0.16], [
   gudev-1.0
   libarchive
   libosinfo-1.0
+  libovf-glib-0.1
   libsoup-2.4
   libvirt-gconfig-1.0
   libvirt-gobject-1.0
diff --git a/src/Makefile.am b/src/Makefile.am
index 4f3e43e..2f9a478 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,7 @@ AM_VALAFLAGS =                                                \
        --pkg libarchive                                \
        --pkg libsoup-2.4                               \
        --pkg libosinfo-1.0                             \
+       --pkg libovf-glib-0.1                           \
        --pkg libvirt-gconfig-1.0                       \
        --pkg libvirt-gobject-1.0                       \
        --pkg libxml-2.0                                \
diff --git a/src/installed-media.vala b/src/installed-media.vala
index e1102b9..60594b4 100644
--- a/src/installed-media.vala
+++ b/src/installed-media.vala
@@ -7,6 +7,7 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
                                                    ".qcow", ".qcow.gz",
                                                    ".img", ".img.gz",
                                                    ".cow", ".cow.gz",
+                                                   ".ova", ".ova.gz",
                                                    ".vdi", ".vdi.gz",
                                                    ".vmdk", ".vmdk.gz",
                                                    ".vpc", ".vpc.gz",
@@ -79,6 +80,7 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
     // Also converts to native format (QCOW2)
     public async void copy (string destination_path) throws GLib.Error {
         var decompressed = yield decompress ();
+        var extracted = yield extract_ovf ();
 
         string[] argv = { "qemu-img", "convert", "-O", "qcow2", device_file, destination_path };
 
@@ -91,7 +93,7 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
         yield exec (argv, null);
         debug ("Finished copying '%s' to '%s'", device_file, destination_path);
 
-        if (decompressed) {
+        if (decompressed || extracted) {
             // We decompressed into a temporary location
             var file = File.new_for_path (device_file);
             delete_file (file);
@@ -155,6 +157,23 @@ private class Boxes.InstalledMedia : Boxes.InstallerMedia {
         return date;
     }
 
+    private async bool extract_ovf () throws GLib.Error {
+        if (!device_file.has_suffix (".ova"))
+            return false;
+
+        var ovf_package = new Ovf.Package ();
+        ovf_package.load_from_ova_file (device_file);
+        var disks = ovf_package.get_disks ();
+        var extracted_path = "/var/tmp/Fedora_23.vmdk";
+        ovf_package.extract_disk (disks [0], extracted_path);
+
+        debug ("Extracted '%s' from '%s'.", extracted_path, device_file);
+
+        device_file = extracted_path;
+
+        return true;
+    }
+
     private async bool decompress () throws GLib.Error {
         if (!device_file.has_suffix (".gz"))
             return false;


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