[Pkg-libvirt-commits] [libguestfs] 84/266: v2v: Allow RHEV UUIDs to be specified on the command line.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 295086e93491db2edb0c4f6d4364118f5f0267dc
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Tue Aug 12 16:35:05 2014 +0100

    v2v: Allow RHEV UUIDs to be specified on the command line.
    
    Currently various UUIDs used by `-o rhev' are generated randomly.
    This means they are different on every run of the program.
    
    Allow some of them to be specified on the command line.  (If not
    specified they are still generated randomly).
    
    This allows RHEV-M to run virt-v2v several times (eg to examine the
    OVF output) while having paths to files and OVF be stable across runs.
---
 v2v/cmdline.ml     | 21 ++++++++++++++++++-
 v2v/target_RHEV.ml | 60 ++++++++++++++++++++++++++++++++++++++++++------------
 v2v/types.ml       |  3 +++
 v2v/types.mli      |  3 +++
 v2v/virt-v2v.pod   | 38 ++++++++++++++++++++++++++++++++++
 5 files changed, 111 insertions(+), 14 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index fe99f17..bcc9740 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -40,6 +40,8 @@ let parse_cmdline () =
   let output_storage = ref "" in
   let machine_readable = ref false in
   let quiet = ref false in
+  let rhev_image_uuid = ref "" in
+  let rhev_vm_uuid = ref "" in
   let verbose = ref false in
   let trace = ref false in
   let vmtype = ref "" in
@@ -79,6 +81,9 @@ let parse_cmdline () =
       error (f_"unknown --root option: %s") s
   in
 
+  let rhev_vol_uuids = ref [] in
+  let add_rhev_vol_uuid s = rhev_vol_uuids := s :: !rhev_vol_uuids in
+
   let ditto = " -\"-" in
   let argspec = Arg.align [
     "--debug-gc",Arg.Set debug_gc,          " " ^ s_"Debug GC and memory allocations";
@@ -94,6 +99,12 @@ let parse_cmdline () =
     "-os",       Arg.Set_string output_storage, "storage " ^ s_"Set output storage location";
     "-q",        Arg.Set quiet,             " " ^ s_"Quiet output";
     "--quiet",   Arg.Set quiet,             ditto;
+    "--rhev-image-uuid",
+                 Arg.Set_string rhev_image_uuid, "uuid " ^ s_"Output image UUID";
+    "--rhev-vol-uuid",
+                 Arg.String add_rhev_vol_uuid, "uuid " ^ s_"Output vol UUID(s)";
+    "--rhev-vm-uuid",
+                 Arg.Set_string rhev_vm_uuid, "uuid " ^ s_"Output VM UUID";
     "--root",    Arg.String set_root_choice,"ask|... " ^ s_"How to choose root filesystem";
     "-v",        Arg.Set verbose,           " " ^ s_"Enable debugging messages";
     "--verbose", Arg.Set verbose,           ditto;
@@ -138,6 +149,9 @@ read the man page virt-v2v(1).
   let output_name = match !output_name with "" -> None | s -> Some s in
   let output_storage = !output_storage in
   let quiet = !quiet in
+  let rhev_image_uuid = match !rhev_image_uuid with "" -> None | s -> Some s in
+  let rhev_vol_uuids = List.rev !rhev_vol_uuids in
+  let rhev_vm_uuid = match !rhev_vm_uuid with "" -> None | s -> Some s in
   let root_choice = !root_choice in
   let verbose = !verbose in
   let trace = !trace in
@@ -201,7 +215,12 @@ read the man page virt-v2v(1).
     | `RHEV ->
       if output_storage = "" then
         error (f_"-o rhev: output storage was not specified, use '-os'");
-      let rhev_params = { vmtype = vmtype } in
+      let rhev_params = {
+        image_uuid = rhev_image_uuid;
+        vol_uuids = rhev_vol_uuids;
+        vm_uuid = rhev_vm_uuid;
+        vmtype = vmtype;
+      } in
       OutputRHEV (output_storage, rhev_params) in
 
   input, output,
diff --git a/v2v/target_RHEV.ml b/v2v/target_RHEV.ml
index d34827b..d2f3846 100644
--- a/v2v/target_RHEV.ml
+++ b/v2v/target_RHEV.ml
@@ -40,8 +40,10 @@ type export_storage_domain = {
 (* Export Storage Domain mountpoint. *)
 let esd = ref { mp = ""; uuid = "" }
 (* Target image directory, UUID. *)
-let image_uuid = ref ""
 let image_dir = ref ""
+let image_uuid = ref ""
+(* Target VM UUID. *)
+let vm_uuid = ref ""
 (* Flag to indicate if the target image (image_dir) should be
  * deleted.  This is set to false once we know the conversion was
  * successful.
@@ -75,14 +77,17 @@ let rec initialize ~verbose os rhev_params source output_alloc overlays =
   if verbose then
     eprintf "RHEV: ESD mountpoint: %s\nRHEV: ESD UUID: %s\n%!" !esd.mp !esd.uuid;
 
-  (* Create a unique UUID for the final image. *)
-  image_uuid := uuidgen ~prog ();
-  image_dir := !esd.mp // !esd.uuid // "images" // !image_uuid;
+  let overlays =
+    let _image_uuid, _vm_uuid, overlays = create_uuids rhev_params overlays in
+    image_uuid := _image_uuid;
+    vm_uuid := _vm_uuid;
+    overlays in
 
   (* We need to create the target image directory so there's a place
    * for the main program to copy the images to.  However if image
    * conversion fails for any reason then we delete this directory.
    *)
+  image_dir := !esd.mp // !esd.uuid // "images" // !image_uuid;
   mkdir !image_dir 0o755;
   at_exit (fun () ->
     if !delete_target_directory then (
@@ -113,8 +118,7 @@ let rec initialize ~verbose os rhev_params source output_alloc overlays =
 
     List.map (
       fun ov ->
-        let vol_uuid = uuidgen ~prog () in
-        let target_file = !image_dir // vol_uuid in
+        let target_file = !image_dir // ov.ov_vol_uuid in
 
         if verbose then
           eprintf "RHEV: will export %s to %s\n%!" ov.ov_sd target_file;
@@ -155,8 +159,7 @@ let rec initialize ~verbose os rhev_params source output_alloc overlays =
         close_out chan;
 
         { ov with
-          ov_target_file_tmp = target_file; ov_target_file = target_file;
-          ov_vol_uuid = vol_uuid }
+          ov_target_file_tmp = target_file; ov_target_file = target_file }
     ) overlays in
 
   (* Return the list of overlays. *)
@@ -242,11 +245,42 @@ and check_export_storage_domain os mp =
   (* Looks good, so return the ESD object. *)
   { mp = mp; uuid = uuid }
 
+(* Create unique UUIDs for everything, either based on the command
+ * line parameters or else we invent them here.
+ *)
+and create_uuids rhev_params overlays =
+  let image_uuid =
+    match rhev_params.image_uuid with
+    | Some uuid -> uuid
+    | None -> uuidgen ~prog () in
+  let vm_uuid =
+    match rhev_params.vm_uuid with
+    | Some uuid -> uuid
+    | None -> uuidgen ~prog () in
+
+  (* ... and for volumes. *)
+  let overlays =
+    match rhev_params.vol_uuids with
+    | [] ->
+      List.map (
+        fun ov ->
+          let uuid = uuidgen ~prog () in
+          { ov with ov_vol_uuid = uuid }
+      ) overlays
+    | uuids ->
+      try
+        List.map (
+          fun (ov, uuid) -> { ov with ov_vol_uuid = uuid }
+        ) (List.combine overlays uuids)
+      with Invalid_argument _ ->
+        error (f_"the number of '--rhev-vol-uuid' parameters passed on the command line has to match the number of guest disk images (for this guest: %d)")
+          (List.length overlays) in
+
+  image_uuid, vm_uuid, overlays
+
 (* This is called after conversion to write the OVF metadata. *)
 let rec create_metadata os rhev_params source output_alloc
     overlays inspect guestcaps =
-  let vm_uuid = uuidgen ~prog () in
-
   let memsize_mb = source.s_memory /^ 1024L /^ 1024L in
 
   let vmtype =
@@ -286,7 +320,7 @@ let rec create_metadata os rhev_params source output_alloc
         e "VmType" [] [PCData vmtype];
         e "DefaultDisplayType" [] [PCData "1"];
 
-        e "Section" ["ovf:id", vm_uuid; "ovf:required", "false";
+        e "Section" ["ovf:id", !vm_uuid; "ovf:required", "false";
                      "xsi:type", "ovf:OperatingSystemSection_Type"] [
           e "Info" [] [PCData "Guest Operating System"];
           e "Description" [] [PCData ostype];
@@ -341,9 +375,9 @@ let rec create_metadata os rhev_params source output_alloc
 
 
   (* Write it to the metadata file. *)
-  let dir = !esd.mp // !esd.uuid // "master" // "vms" // vm_uuid in
+  let dir = !esd.mp // !esd.uuid // "master" // "vms" // !vm_uuid in
   mkdir dir 0o755;
-  let file = dir // vm_uuid ^ ".ovf" in
+  let file = dir // !vm_uuid ^ ".ovf" in
   let chan = open_out file in
   doc_to_chan chan ovf;
   close_out chan;
diff --git a/v2v/types.ml b/v2v/types.ml
index ecb4b35..0231c66 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -30,6 +30,9 @@ type output =
 | OutputRHEV of string * output_rhev_params
 
 and output_rhev_params = {
+  image_uuid : string option;
+  vol_uuids : string list;
+  vm_uuid : string option;
   vmtype : [`Server|`Desktop] option;
 }
 
diff --git a/v2v/types.mli b/v2v/types.mli
index 8ba47fe..433aa06 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -30,6 +30,9 @@ type output =
 (** The output arguments as specified on the command line. *)
 
 and output_rhev_params = {
+  image_uuid : string option;           (* --rhev-image-uuid *)
+  vol_uuids : string list;              (* --rhev-vol-uuid (multiple) *)
+  vm_uuid : string option;              (* --rhev-vm-uuid *)
   vmtype : [`Server|`Desktop] option;   (* --vmtype *)
 }
 (** Miscellaneous extra command line parameters used by RHEV. *)
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 2a93957..505894d 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -159,6 +159,44 @@ Export Storage Domain.
 
 This disables progress bars and other unnecessary output.
 
+=item B<--rhev-image-uuid> UUID
+
+=item B<--rhev-vol-uuid> UUID
+
+=item B<--rhev-vm-uuid> UUID
+
+Normally the RHEV output mode chooses a random UUID for each of:
+
+=over 4
+
+=item *
+
+the image directory (I<--rhev-image-uuid>)
+
+=item *
+
+once for each guest disk (I<--rhev-vol-uuid>)
+
+=item *
+
+the VM and OVF file (I<--rhev-vm-uuid>).
+
+=back
+
+However you can force specific UUIDs instead by using these options.
+
+You can use I<--rhev-image-uuid> and I<--rhev-vm-uuid> on the command
+line at most once.
+
+If the guest has more than one virtual disk, then you should use
+I<--rhev-vol-uuid> multiple times to change the UUID of each guest
+disk.
+
+The format of UUIDs is: C<12345678-1234-1234-1234-123456789abc> (each
+hex digit can be C<0-9> or C<a-f>), conforming to S<OSF DCE 1.1>.
+
+These options can only be used with I<-o rhev>.
+
 =item B<--root ask>
 
 =item B<--root single>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list