Blame SOURCES/0240-v2v-glance-Allow-Glance-backend-to-import-multiple-d.patch

b66178
From 7997ac9e9ee0b041c54d20f5e3a6c6aa68f5c2e7 Mon Sep 17 00:00:00 2001
b66178
From: "Richard W.M. Jones" <rjones@redhat.com>
b66178
Date: Tue, 16 Feb 2016 12:30:00 +0000
b66178
Subject: [PATCH] v2v: glance: Allow Glance backend to import multiple disks
b66178
 (RHBZ#1308769).
b66178
b66178
(cherry picked from commit 6200ae7204f4db3b93707acf7356083e121f854f)
b66178
---
b66178
 v2v/output_glance.ml | 133 ++++++++++++++++++++++++++-------------------------
b66178
 v2v/virt-v2v.pod     |  24 ++++++++++
b66178
 2 files changed, 93 insertions(+), 64 deletions(-)
b66178
b66178
diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml
b66178
index f8c8806..1ca37eb 100644
b66178
--- a/v2v/output_glance.ml
b66178
+++ b/v2v/output_glance.ml
b66178
@@ -51,11 +51,7 @@ object
b66178
     if Sys.command "glance image-list > /dev/null" <> 0 then
b66178
       error (f_"glance: glance client is not installed or set up correctly.  You may need to set environment variables or source a script to enable authentication.  See preceding messages for details.");
b66178
 
b66178
-    (* OpenStack only supports single image VMs, I think? *)
b66178
-    let nr_targets = List.length targets in
b66178
-    if nr_targets <> 1 then
b66178
-      error (f_"glance: OpenStack conversion only supports virtual machines with a single disk image.  This VM has %d") nr_targets;
b66178
-
b66178
+    (* Write targets to a temporary local file - see above for reason. *)
b66178
     List.map (
b66178
       fun t ->
b66178
         let target_file = tmpdir // t.target_overlay.ov_sd in
b66178
@@ -66,68 +62,77 @@ object
b66178
     (* See #supported_firmware above. *)
b66178
     assert (target_firmware = TargetBIOS);
b66178
 
b66178
-    (* Upload the disk image (there should only be one - see above). *)
b66178
-    let { target_file = target_file; target_format = target_format } =
b66178
-      List.hd targets in
b66178
-    let cmd =
b66178
-      sprintf "glance image-create --name %s --disk-format=%s --container-format=bare --file %s"
b66178
-        (quote source.s_name) (quote target_format) target_file in
b66178
-    if verbose then printf "%s\n%!" cmd;
b66178
-    if Sys.command cmd <> 0 then
b66178
-      error (f_"glance: image upload to glance failed, see earlier errors");
b66178
+    (* The first disk, assumed to be the system, will be called
b66178
+     * "guestname".  Subsequent disks, assumed to be data disks,
b66178
+     * will be called "guestname-disk2" etc.  The manual strongly
b66178
+     * hints you should import the data disks to Cinder.
b66178
+     *)
b66178
+    List.iteri (
b66178
+      fun i { target_file = target_file; target_format = target_format } ->
b66178
+        let name =
b66178
+          if i == 0 then source.s_name
b66178
+          else sprintf "%s-disk%d" source.s_name (i+1) in
b66178
 
b66178
-    (* Set the properties (ie. metadata). *)
b66178
-    let min_ram = source.s_memory /^ 1024L /^ 1024L in
b66178
-    let properties = [
b66178
-      "hw_disk_bus",
b66178
-      (match guestcaps.gcaps_block_bus with
b66178
-      | Virtio_blk -> "virtio"
b66178
-      | IDE -> "ide");
b66178
-      "hw_vif_model",
b66178
-      (match guestcaps.gcaps_net_bus with
b66178
-      | Virtio_net -> "virtio"
b66178
-      | E1000 -> "e1000"
b66178
-      | RTL8139 -> "rtl8139");
b66178
-      "architecture", guestcaps.gcaps_arch;
b66178
-      "hypervisor_type", "kvm";
b66178
-      "vm_mode", "hvm";
b66178
-      "os_type", inspect.i_type;
b66178
-      "os_distro",
b66178
-      (match inspect.i_distro with
b66178
-      (* http://docs.openstack.org/cli-reference/glance.html#image-service-property-keys *)
b66178
-      | "archlinux" -> "arch"
b66178
-      | "sles" -> "sled"
b66178
-      | x -> x (* everything else is the same in libguestfs and OpenStack *)
b66178
-      )
b66178
-    ] in
b66178
-    let properties =
b66178
-      match inspect.i_major_version, inspect.i_minor_version with
b66178
-      | 0, 0 -> properties
b66178
-      | x, 0 -> ("os_version", string_of_int x) :: properties
b66178
-      | x, y -> ("os_version", sprintf "%d.%d" x y) :: properties in
b66178
+        let cmd =
b66178
+          sprintf "glance image-create --name %s --disk-format=%s --container-format=bare --file %s"
b66178
+                  (quote name) (quote target_format) target_file in
b66178
+        if verbose then printf "%s\n%!" cmd;
b66178
+        if Sys.command cmd <> 0 then
b66178
+          error (f_"glance: image upload to glance failed, see earlier errors");
b66178
 
b66178
-    (* Glance doesn't appear to check the properties. *)
b66178
-    let cmd =
b66178
-      sprintf "glance image-update --min-ram %Ld %s %s"
b66178
-        min_ram
b66178
-        (String.concat " " (
b66178
-          List.map (
b66178
-            fun (k, v) ->
b66178
-              sprintf "--property %s=%s" (quote k) (quote v)
b66178
+        (* Set the properties (ie. metadata). *)
b66178
+        let min_ram = source.s_memory /^ 1024L /^ 1024L in
b66178
+        let properties = [
b66178
+          "hw_disk_bus",
b66178
+          (match guestcaps.gcaps_block_bus with
b66178
+           | Virtio_blk -> "virtio"
b66178
+           | IDE -> "ide");
b66178
+          "hw_vif_model",
b66178
+          (match guestcaps.gcaps_net_bus with
b66178
+           | Virtio_net -> "virtio"
b66178
+           | E1000 -> "e1000"
b66178
+           | RTL8139 -> "rtl8139");
b66178
+          "architecture", guestcaps.gcaps_arch;
b66178
+          "hypervisor_type", "kvm";
b66178
+          "vm_mode", "hvm";
b66178
+          "os_type", inspect.i_type;
b66178
+          "os_distro",
b66178
+          (match inspect.i_distro with
b66178
+          (* http://docs.openstack.org/cli-reference/glance.html#image-service-property-keys *)
b66178
+           | "archlinux" -> "arch"
b66178
+           | "sles" -> "sled"
b66178
+           | x -> x (* everything else is the same in libguestfs and OpenStack*)
b66178
+          )
b66178
+        ] in
b66178
+        let properties =
b66178
+          match inspect.i_major_version, inspect.i_minor_version with
b66178
+          | 0, 0 -> properties
b66178
+          | x, 0 -> ("os_version", string_of_int x) :: properties
b66178
+          | x, y -> ("os_version", sprintf "%d.%d" x y) :: properties in
b66178
+
b66178
+        (* Glance doesn't appear to check the properties. *)
b66178
+        let cmd =
b66178
+          sprintf "glance image-update --min-ram %Ld %s %s"
b66178
+                  min_ram
b66178
+                  (String.concat " "
b66178
+                    (List.map (
b66178
+                       fun (k, v) ->
b66178
+                         sprintf "--property %s=%s" (quote k) (quote v)
b66178
+                    ) properties
b66178
+                  ))
b66178
+                  (quote name) in
b66178
+        if verbose then printf "%s\n%!" cmd;
b66178
+        if Sys.command cmd <> 0 then (
b66178
+          warning ~prog (f_"glance: failed to set image properties (ignored)");
b66178
+          (* Dump out the image properties so the user can set them. *)
b66178
+          printf "Image properties:\n";
b66178
+          printf "  --min-ram %Ld\n" min_ram;
b66178
+          List.iter (
b66178
+	    fun (k, v) ->
b66178
+	      printf "  --property %s=%s" (quote k) (quote v)
b66178
           ) properties
b66178
-        ))
b66178
-        (quote source.s_name) in
b66178
-    if verbose then printf "%s\n%!" cmd;
b66178
-    if Sys.command cmd <> 0 then (
b66178
-      warning ~prog (f_"glance: failed to set image properties (ignored)");
b66178
-      (* Dump out the image properties so the user can set them. *)
b66178
-      printf "Image properties:\n";
b66178
-      printf "  --min-ram %Ld\n" min_ram;
b66178
-      List.iter (
b66178
-	fun (k, v) ->
b66178
-	  printf "  --property %s=%s" (quote k) (quote v)
b66178
-      ) properties
b66178
-    )
b66178
+        )
b66178
+      ) targets
b66178
 end
b66178
 
b66178
 let output_glance = new output_glance
b66178
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
b66178
index 876d5f6..d4fdf5d 100644
b66178
--- a/v2v/virt-v2v.pod
b66178
+++ b/v2v/virt-v2v.pod
b66178
@@ -1158,6 +1158,30 @@ Glance image upload doesn't appear to correctly handle sparseness.
b66178
 For this reason, using qcow2 will be faster and use less space on the
b66178
 Glance server.  Use the virt-v2v S<I<-of qcow2>> option.
b66178
 
b66178
+=head2 Glance and multiple disks
b66178
+
b66178
+If the guest has a single disk, then the name of the disk in Glance
b66178
+will be the name of the guest.  You can control this using the I<-on>
b66178
+option.
b66178
+
b66178
+Glance doesn't have a concept of associating multiple disks with a
b66178
+single guest, and Nova doesn't allow you to boot a guest from multiple
b66178
+Glance disks either.  If the guest has multiple disks, then the first
b66178
+(assumed to be the system disk) will have the name of the guest, and
b66178
+the second and subsequent data disks will be called
b66178
+C<I<guestname>-disk2>, C<I<guestname>-disk3> etc.  It may be best to
b66178
+leave the system disk in Glance, and import the data disks to Cinder
b66178
+(see next section).
b66178
+
b66178
+=head2 Importing disks into Cinder
b66178
+
b66178
+Since most virt-v2v guests are "pets", Glance is perhaps not the best
b66178
+place to store them.  There is no way for virt-v2v to upload directly
b66178
+to Cinder (L<https://bugzilla.redhat.com/1155229>), so instead you
b66178
+must import them yourself by doing:
b66178
+
b66178
+ cinder create --image-id <GLANCE-IMAGE-UUID> <SIZE>
b66178
+
b66178
 =head1 RESOURCE REQUIREMENTS
b66178
 
b66178
 =head2 Network
b66178
-- 
b66178
1.8.3.1
b66178