Blame SOURCES/0029-v2v-o-rhv-upload-add-oo-rhv-disk-uuid-option.patch

46b2f6
From 9d7503382f33a7721378ec586ea718c63a0ec3b6 Mon Sep 17 00:00:00 2001
46b2f6
From: Pino Toscano <ptoscano@redhat.com>
46b2f6
Date: Thu, 19 Sep 2019 12:19:09 +0200
46b2f6
Subject: [PATCH] v2v: -o rhv-upload: add -oo rhv-disk-uuid option
46b2f6
46b2f6
This way it is possible to override the UUIDs of the uploaded disks,
46b2f6
instead of letting RHV generate them.
46b2f6
46b2f6
This can be useful to force certain UUIDs, and to specify the disks in
46b2f6
--no-copy mode (which now can be used).
46b2f6
46b2f6
(cherry picked from commit 537ba8357e44ca3aa8878a2ac98e9476a570d3f4)
46b2f6
---
46b2f6
 v2v/output_rhv_upload.ml    | 43 ++++++++++++++++++++++++++++++++-----
46b2f6
 v2v/rhv-upload-plugin.py    |  2 ++
46b2f6
 v2v/virt-v2v-output-rhv.pod | 24 +++++++++++++++++++++
46b2f6
 3 files changed, 64 insertions(+), 5 deletions(-)
46b2f6
46b2f6
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
46b2f6
index 382ad0d93..206657a2b 100644
46b2f6
--- a/v2v/output_rhv_upload.ml
46b2f6
+++ b/v2v/output_rhv_upload.ml
46b2f6
@@ -32,6 +32,7 @@ type rhv_options = {
46b2f6
   rhv_cluster : string option;
46b2f6
   rhv_direct : bool;
46b2f6
   rhv_verifypeer : bool;
46b2f6
+  rhv_disk_uuids : string list option;
46b2f6
 }
46b2f6
 
46b2f6
 let print_output_options () =
46b2f6
@@ -41,6 +42,11 @@ let print_output_options () =
46b2f6
   -oo rhv-cluster=CLUSTERNAME     Set RHV cluster name.
46b2f6
   -oo rhv-direct[=true|false]     Use direct transfer mode (default: false).
46b2f6
   -oo rhv-verifypeer[=true|false] Verify server identity (default: false).
46b2f6
+
46b2f6
+You can override the UUIDs of the disks, instead of using autogenerated UUIDs
46b2f6
+after their uploads (if you do, you must supply one for each disk):
46b2f6
+
46b2f6
+  -oo rhv-disk-uuid=UUID          Disk UUID
46b2f6
 ")
46b2f6
 
46b2f6
 let parse_output_options options =
46b2f6
@@ -48,6 +54,7 @@ let parse_output_options options =
46b2f6
   let rhv_cluster = ref None in
46b2f6
   let rhv_direct = ref false in
46b2f6
   let rhv_verifypeer = ref false in
46b2f6
+  let rhv_disk_uuids = ref None in
46b2f6
 
46b2f6
   List.iter (
46b2f6
     function
46b2f6
@@ -63,6 +70,8 @@ let parse_output_options options =
46b2f6
     | "rhv-direct", v -> rhv_direct := bool_of_string v
46b2f6
     | "rhv-verifypeer", "" -> rhv_verifypeer := true
46b2f6
     | "rhv-verifypeer", v -> rhv_verifypeer := bool_of_string v
46b2f6
+    | "rhv-disk-uuid", v ->
46b2f6
+       rhv_disk_uuids := Some (v :: (Option.default [] !rhv_disk_uuids))
46b2f6
     | k, _ ->
46b2f6
        error (f_"-o rhv-upload: unknown output option ‘-oo %s’") k
46b2f6
   ) options;
46b2f6
@@ -75,8 +84,9 @@ let parse_output_options options =
46b2f6
   let rhv_cluster = !rhv_cluster in
46b2f6
   let rhv_direct = !rhv_direct in
46b2f6
   let rhv_verifypeer = !rhv_verifypeer in
46b2f6
+  let rhv_disk_uuids = Option.map List.rev !rhv_disk_uuids in
46b2f6
 
46b2f6
-  { rhv_cafile; rhv_cluster; rhv_direct; rhv_verifypeer }
46b2f6
+  { rhv_cafile; rhv_cluster; rhv_direct; rhv_verifypeer; rhv_disk_uuids }
46b2f6
 
46b2f6
 let nbdkit_python_plugin = Config.virt_v2v_nbdkit_python_plugin
46b2f6
 let pidfile_timeout = 30
46b2f6
@@ -270,6 +280,16 @@ object
46b2f6
   method install_rhev_apt = true
46b2f6
 
46b2f6
   method prepare_targets source overlays _ _ _ _ =
46b2f6
+    let uuids =
46b2f6
+      match rhv_options.rhv_disk_uuids with
46b2f6
+      | None ->
46b2f6
+        List.map (fun _ -> None) overlays
46b2f6
+      | Some uuids ->
46b2f6
+        if List.length uuids <> List.length overlays then
46b2f6
+          error (f_"the number of ‘-oo rhv-disk-uuid’ parameters passed on the command line has to match the number of guest disk images (for this guest: %d)")
46b2f6
+            (List.length overlays);
46b2f6
+        List.map (fun uuid -> Some uuid) uuids in
46b2f6
+
46b2f6
     let output_name = source.s_name in
46b2f6
     let json_params =
46b2f6
       ("output_name", JSON.String output_name) :: json_params in
46b2f6
@@ -284,7 +304,7 @@ object
46b2f6
      * target URI to point to the NBD socket.
46b2f6
      *)
46b2f6
     List.map (
46b2f6
-      fun (target_format, ov) ->
46b2f6
+      fun ((target_format, ov), uuid) ->
46b2f6
         let id = ov.ov_source.s_disk_id in
46b2f6
         let disk_name = sprintf "%s-%03d" output_name id in
46b2f6
         let json_params =
46b2f6
@@ -310,6 +330,12 @@ object
46b2f6
         let json_params =
46b2f6
           ("diskid_file", JSON.String diskid_file) :: json_params in
46b2f6
 
46b2f6
+        let json_params =
46b2f6
+          match uuid with
46b2f6
+          | None -> json_params
46b2f6
+          | Some uuid ->
46b2f6
+            ("rhv_disk_uuid", JSON.String uuid) :: json_params in
46b2f6
+
46b2f6
         (* Write the JSON parameters to a file. *)
46b2f6
         let json_param_file = tmpdir // sprintf "params%d.json" id in
46b2f6
         with_open_out
46b2f6
@@ -379,7 +405,7 @@ If the messages above are not sufficient to diagnose the problem then add the 
46b2f6
           "file.export", JSON.String "/";
46b2f6
         ] in
46b2f6
         TargetURI ("json:" ^ JSON.string_of_doc json_params)
46b2f6
-    ) overlays
46b2f6
+    ) (List.combine overlays uuids)
46b2f6
 
46b2f6
   method disk_copied t i nr_disks =
46b2f6
     (* Get the UUID of the disk image.  This file is written
46b2f6
@@ -395,7 +421,14 @@ If the messages above are not sufficient to diagnose the problem then add the 
46b2f6
     disks_uuids <- disks_uuids @ [diskid];
46b2f6
 
46b2f6
   method create_metadata source targets _ guestcaps inspect target_firmware =
46b2f6
-    assert (List.length disks_uuids = List.length targets);
46b2f6
+    let image_uuids =
46b2f6
+      match rhv_options.rhv_disk_uuids, disks_uuids with
46b2f6
+      | None, [] ->
46b2f6
+          error (f_"there must be ‘-oo rhv-disk-uuid’ parameters passed on the command line to specify the UUIDs of guest disk images (for this guest: %d)")
46b2f6
+            (List.length targets)
46b2f6
+      | Some uuids, _ -> uuids
46b2f6
+      | None, uuids -> uuids in
46b2f6
+    assert (List.length image_uuids = List.length targets);
46b2f6
 
46b2f6
     (* The storage domain UUID. *)
46b2f6
     let sd_uuid =
46b2f6
@@ -411,7 +444,7 @@ If the messages above are not sufficient to diagnose the problem then add the 
46b2f6
     let ovf =
46b2f6
       Create_ovf.create_ovf source targets guestcaps inspect
46b2f6
                             target_firmware output_alloc
46b2f6
-                            sd_uuid disks_uuids vol_uuids vm_uuid
46b2f6
+                            sd_uuid image_uuids vol_uuids vm_uuid
46b2f6
                             OVirt in
46b2f6
     let ovf = DOM.doc_to_string ovf in
46b2f6
 
46b2f6
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
46b2f6
index 4d61a089b..6ec74a5d4 100644
46b2f6
--- a/v2v/rhv-upload-plugin.py
46b2f6
+++ b/v2v/rhv-upload-plugin.py
46b2f6
@@ -135,6 +135,8 @@ def open(readonly):
46b2f6
         disk_format = types.DiskFormat.COW
46b2f6
     disk = disks_service.add(
46b2f6
         disk = types.Disk(
46b2f6
+            # The ID is optional.
46b2f6
+            id = params.get('rhv_disk_uuid'),
46b2f6
             name = params['disk_name'],
46b2f6
             description = "Uploaded by virt-v2v",
46b2f6
             format = disk_format,
46b2f6
diff --git a/v2v/virt-v2v-output-rhv.pod b/v2v/virt-v2v-output-rhv.pod
46b2f6
index 651f61dae..e840ca78d 100644
46b2f6
--- a/v2v/virt-v2v-output-rhv.pod
46b2f6
+++ b/v2v/virt-v2v-output-rhv.pod
46b2f6
@@ -9,6 +9,7 @@ virt-v2v-output-rhv - Using virt-v2v to convert guests to oVirt or RHV
46b2f6
                         [-oo rhv-cafile=FILE]
46b2f6
                         [-oo rhv-cluster=CLUSTER]
46b2f6
                         [-oo rhv-direct]
46b2f6
+                        [-oo rhv-disk-uuid=UUID ...]
46b2f6
                         [-oo rhv-verifypeer]
46b2f6
 
46b2f6
  virt-v2v [-i* options] -o rhv -os [esd:/path|/path]
46b2f6
@@ -104,6 +105,29 @@ F</etc/pki/ovirt-engine/ca.pem> on the oVirt engine.
46b2f6
 
46b2f6
 Set the RHV Cluster Name.  If not given it uses C<Default>.
46b2f6
 
46b2f6
+=item I<-oo rhv-disk-uuid=>C<UUID>
46b2f6
+
46b2f6
+This option can used to manually specify UUIDs for the disks when
46b2f6
+creating the virtual machine.  If not specified, the oVirt engine will
46b2f6
+generate random UUIDs for the disks.  Please note that:
46b2f6
+
46b2f6
+=over 4
46b2f6
+
46b2f6
+=item *
46b2f6
+
46b2f6
+you B<must> pass as many I<-oo rhv-disk-uuid=UUID> options as the
46b2f6
+amount of disks in the guest
46b2f6
+
46b2f6
+=item *
46b2f6
+
46b2f6
+the specified UUIDs are used as they are, without checking whether
46b2f6
+they are already used by other disks
46b2f6
+
46b2f6
+=back
46b2f6
+
46b2f6
+This option is considered advanced, and to be used mostly in
46b2f6
+combination with I<--no-copy>.
46b2f6
+
46b2f6
 =item I<-oo rhv-direct>
46b2f6
 
46b2f6
 If this option is given then virt-v2v will attempt to directly upload
46b2f6
-- 
b155d0
2.26.2
46b2f6