mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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