[gnome-boxes/wip/kalev/ovf-support: 6/8] installed-media: Support .ova files



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

    installed-media: Support .ova files
    
    This makes use of libovf-glib to load .ova files in the Open
    Virtualization Format.

 src/installed-media.vala | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/src/installed-media.vala b/src/installed-media.vala
index 09ceffdf..789dadc1 100644
--- a/src/installed-media.vala
+++ b/src/installed-media.vala
@@ -1,12 +1,14 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 
 using GVirConfig;
+using Govf;
 
 private class Boxes.InstalledMedia : Boxes.InstallerMedia {
     public const string[] supported_extensions = { ".qcow2", ".qcow2.gz",
                                                    ".qcow", ".qcow.gz",
                                                    ".img", ".img.gz",
                                                    ".cow", ".cow.gz",
+                                                   ".ova", ".ova.gz",
                                                    ".vdi", ".vdi.gz",
                                                    ".vmdk", ".vmdk.gz",
                                                    ".vpc", ".vpc.gz",
@@ -81,6 +83,7 @@ public InstalledMedia (string path, bool known_qcow2 = false) throws GLib.Error
     // 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 };
 
@@ -93,7 +96,7 @@ public async void copy (string destination_path) throws GLib.Error {
         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);
@@ -157,6 +160,25 @@ public override VMCreator get_vm_creator () {
         return date;
     }
 
+    private async bool extract_ovf () throws GLib.Error {
+        if (!device_file.has_suffix (".ova"))
+            return false;
+
+        var ova_file = File.new_for_path (device_file);
+        var ovf_package = new Govf.Package ();
+        ovf_package.load_from_ova_file (device_file);
+
+        var disks = ovf_package.get_disks ();
+        var extracted_path = get_user_pkgcache (ova_file.get_basename () + ".vmkd");
+        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]