Blame SOURCES/0048-v2v-Remove-dcpath-parameter-and-related-functionalit.patch

a30de4
From 8018cf4c1206253c0f58e79b9afc171b3855b826 Mon Sep 17 00:00:00 2001
a30de4
From: "Richard W.M. Jones" <rjones@redhat.com>
a30de4
Date: Fri, 13 Oct 2017 15:45:39 +0100
a30de4
Subject: [PATCH] v2v: Remove --dcpath parameter and related functionality.
a30de4
a30de4
With modern libvirt, when fetching the XML of a VMware guest libvirt
a30de4
passes us the datacenter path (dcpath).  However with older libvirt we
a30de4
had to guess this value, or else the user had to supply it on the
a30de4
command line.
a30de4
a30de4
This commit removes all the guessing code and the --dcpath parameter
a30de4
(which will now give an error).
a30de4
a30de4
This requires libvirt >= 1.2.20 for virt-v2v, released Oct 2015.
a30de4
a30de4
(cherry picked from commit 3fdd923ce2d31e21a441042f9ded3c45dec6bbcb)
a30de4
---
a30de4
 v2v/cmdline.ml                      |  6 +----
a30de4
 v2v/copy_to_local.ml                | 15 ++++++------
a30de4
 v2v/input_libvirt.ml                |  4 ++--
a30de4
 v2v/input_libvirt.mli               |  4 ++--
a30de4
 v2v/input_libvirt_vcenter_https.ml  | 31 +++++++-----------------
a30de4
 v2v/input_libvirt_vcenter_https.mli |  2 +-
a30de4
 v2v/test-v2v-docs.sh                |  2 +-
a30de4
 v2v/vCenter.ml                      | 47 +------------------------------------
a30de4
 v2v/vCenter.mli                     |  8 -------
a30de4
 v2v/virt-v2v.pod                    | 13 ----------
a30de4
 10 files changed, 24 insertions(+), 108 deletions(-)
a30de4
a30de4
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
a30de4
index 3050104d0..dfbb776ab 100644
a30de4
--- a/v2v/cmdline.ml
a30de4
+++ b/v2v/cmdline.ml
a30de4
@@ -54,7 +54,6 @@ let parse_cmdline () =
a30de4
   let print_source = ref false in
a30de4
   let qemu_boot = ref false in
a30de4
 
a30de4
-  let dcpath = ref None in
a30de4
   let input_conn = ref None in
a30de4
   let input_format = ref None in
a30de4
   let in_place = ref false in
a30de4
@@ -181,8 +180,6 @@ let parse_cmdline () =
a30de4
   let argspec = [
a30de4
     [ S 'b'; L"bridge" ],        Getopt.String ("in:out", add_bridge),     s_"Map bridge 'in' to 'out'";
a30de4
     [ L"compressed" ], Getopt.Set compressed,     s_"Compress output file (-of qcow2 only)";
a30de4
-    [ L"dcpath"; L"dcPath" ],  Getopt.String ("path", set_string_option_once "--dcpath" dcpath),
a30de4
-                                            s_"Override dcPath (for vCenter)";
a30de4
     [ L"debug-overlay"; L"debug-overlays" ], Getopt.Set debug_overlays, s_"Save overlay files";
a30de4
     [ S 'i' ],        Getopt.String (i_options, set_input_mode), s_"Set input mode (default: libvirt)";
a30de4
     [ M"ic" ],       Getopt.String ("uri", set_string_option_once "-ic" input_conn),
a30de4
@@ -268,7 +265,6 @@ read the man page virt-v2v(1).
a30de4
   (* Dereference the arguments. *)
a30de4
   let args = List.rev !args in
a30de4
   let compressed = !compressed in
a30de4
-  let dcpath = !dcpath in
a30de4
   let debug_overlays = !debug_overlays in
a30de4
   let do_copy = !do_copy in
a30de4
   let input_conn = !input_conn in
a30de4
@@ -367,7 +363,7 @@ read the man page virt-v2v(1).
a30de4
         | [guest] -> guest
a30de4
         | _ ->
a30de4
           error (f_"expecting a libvirt guest name on the command line") in
a30de4
-      Input_libvirt.input_libvirt dcpath vddk_options password input_conn guest
a30de4
+      Input_libvirt.input_libvirt vddk_options password input_conn guest
a30de4
 
a30de4
     | `LibvirtXML ->
a30de4
       (* -i libvirtxml: Expecting a filename (XML file). *)
a30de4
diff --git a/v2v/copy_to_local.ml b/v2v/copy_to_local.ml
a30de4
index 88fd9abde..ca5578f3f 100644
a30de4
--- a/v2v/copy_to_local.ml
a30de4
+++ b/v2v/copy_to_local.ml
a30de4
@@ -144,6 +144,11 @@ read the man page virt-v2v-copy-to-local(1).
a30de4
   let disks =
a30de4
     match source with
a30de4
     | ESXi server ->
a30de4
+       let dcpath =
a30de4
+         match dcpath with
a30de4
+         | Some dcpath -> dcpath
a30de4
+         | None ->
a30de4
+            error (f_"vcenter: <vmware:datacenterpath> was not found in the XML.  You need to upgrade to libvirt ≥ 1.2.20.") in
a30de4
        List.map (
a30de4
          fun (remote_disk, local_disk) ->
a30de4
            let url, sslverify =
a30de4
@@ -242,14 +247,10 @@ and parse_libvirt_xml guest_name xml =
a30de4
   let xpathctx = Xml.xpath_new_context doc in
a30de4
   Xml.xpath_register_ns xpathctx
a30de4
                         "vmware" "http://libvirt.org/schemas/domain/vmware/1.0";
a30de4
-  let xpath_string = xpath_string xpathctx
a30de4
-  and xpath_string_default = xpath_string_default xpathctx in
a30de4
+  let xpath_string = xpath_string xpathctx in
a30de4
 
a30de4
-  (* Get the dcpath, only present for libvirt >= 1.2.20 so use a
a30de4
-   * sensible default for older versions.
a30de4
-   *)
a30de4
-  let dcpath =
a30de4
-    xpath_string_default "/domain/vmware:datacenterpath" "ha-datacenter" in
a30de4
+  (* Get the dcpath, present in libvirt >= 1.2.20. *)
a30de4
+  let dcpath = xpath_string "/domain/vmware:datacenterpath" in
a30de4
 
a30de4
   (* Parse the disks. *)
a30de4
   let get_disks, add_disk =
a30de4
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
a30de4
index e8143b6ad..f4a8114f0 100644
a30de4
--- a/v2v/input_libvirt.ml
a30de4
+++ b/v2v/input_libvirt.ml
a30de4
@@ -27,7 +27,7 @@ open Types
a30de4
 open Utils
a30de4
 
a30de4
 (* Choose the right subclass based on the URI. *)
a30de4
-let input_libvirt dcpath vddk_options password libvirt_uri guest =
a30de4
+let input_libvirt vddk_options password libvirt_uri guest =
a30de4
   match libvirt_uri with
a30de4
   | None ->
a30de4
     Input_libvirt_other.input_libvirt_other password libvirt_uri guest
a30de4
@@ -54,7 +54,7 @@ let input_libvirt dcpath vddk_options password libvirt_uri guest =
a30de4
        (match vddk_options with
a30de4
         | None ->
a30de4
            Input_libvirt_vcenter_https.input_libvirt_vcenter_https
a30de4
-             dcpath password libvirt_uri parsed_uri scheme server guest
a30de4
+             password libvirt_uri parsed_uri scheme server guest
a30de4
         | Some vddk_options ->
a30de4
            Input_libvirt_vddk.input_libvirt_vddk vddk_options password
a30de4
                                                  libvirt_uri parsed_uri guest
a30de4
diff --git a/v2v/input_libvirt.mli b/v2v/input_libvirt.mli
a30de4
index 0a6aa3c54..acf2ca417 100644
a30de4
--- a/v2v/input_libvirt.mli
a30de4
+++ b/v2v/input_libvirt.mli
a30de4
@@ -18,7 +18,7 @@
a30de4
 
a30de4
 (** [-i libvirt] source. *)
a30de4
 
a30de4
-val input_libvirt : string option -> Types.vddk_options option -> string option -> string option -> string -> Types.input
a30de4
-(** [input_libvirt dcpath vddk_options password libvirt_uri guest] creates
a30de4
+val input_libvirt : Types.vddk_options option -> string option -> string option -> string -> Types.input
a30de4
+(** [input_libvirt vddk_options password libvirt_uri guest] creates
a30de4
     and returns a new {!Types.input} object specialized for reading input
a30de4
     from libvirt sources. *)
a30de4
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
a30de4
index df0e89315..497caca4f 100644
a30de4
--- a/v2v/input_libvirt_vcenter_https.ml
a30de4
+++ b/v2v/input_libvirt_vcenter_https.ml
a30de4
@@ -36,7 +36,7 @@ let readahead_for_copying = Some (64 * 1024 * 1024)
a30de4
 
a30de4
 (* Subclass specialized for handling VMware vCenter over https. *)
a30de4
 class input_libvirt_vcenter_https
a30de4
-  cmdline_dcPath password libvirt_uri parsed_uri scheme server guest =
a30de4
+        password libvirt_uri parsed_uri scheme server guest =
a30de4
 object
a30de4
   inherit input_libvirt password libvirt_uri guest
a30de4
 
a30de4
@@ -68,33 +68,18 @@ object
a30de4
     let xml = Libvirt_utils.dumpxml ?password ?conn:libvirt_uri guest in
a30de4
     let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
a30de4
 
a30de4
-    (* Find the <vmware:datacenterpath> element from the XML, if it
a30de4
-     * exists.  This was added in libvirt >= 1.2.20.
a30de4
+    (* Find the <vmware:datacenterpath> element from the XML.  This
a30de4
+     * was added in libvirt >= 1.2.20.
a30de4
      *)
a30de4
-    let xml_dcPath =
a30de4
+    dcPath <- (
a30de4
       let doc = Xml.parse_memory xml in
a30de4
       let xpathctx = Xml.xpath_new_context doc in
a30de4
       Xml.xpath_register_ns xpathctx
a30de4
         "vmware" "http://libvirt.org/schemas/domain/vmware/1.0";
a30de4
-      let xpath_string = xpath_string xpathctx in
a30de4
-      xpath_string "/domain/vmware:datacenterpath" in
a30de4
-
a30de4
-    (* Calculate the dcPath we're going to use. *)
a30de4
-    dcPath <- (
a30de4
-      match cmdline_dcPath, xml_dcPath with
a30de4
-      (* Command line --dcpath parameter overrides everything, allowing
a30de4
-       * users to correct any mistakes in v2v or libvirt.
a30de4
-       *)
a30de4
-      | Some p, (None|Some _) ->
a30de4
-         debug "vcenter: using --dcpath from the command line: %s" p;
a30de4
-         p
a30de4
-      | None, Some p ->
a30de4
-         debug "vcenter: using <vmware:datacenterpath> from libvirt: %s" p;
a30de4
-         p
a30de4
-      | None, None ->
a30de4
-         let p = VCenter.guess_dcPath parsed_uri scheme in
a30de4
-         debug "vcenter: guessed dcPath from URI: %s" p;
a30de4
-         p
a30de4
+      match xpath_string xpathctx "/domain/vmware:datacenterpath" with
a30de4
+      | Some dcPath -> dcPath
a30de4
+      | None ->
a30de4
+         error (f_"vcenter: <vmware:datacenterpath> was not found in the XML.  You need to upgrade to libvirt ≥ 1.2.20.")
a30de4
     );
a30de4
 
a30de4
     (* Save the original source paths, so that we can remap them again
a30de4
diff --git a/v2v/input_libvirt_vcenter_https.mli b/v2v/input_libvirt_vcenter_https.mli
a30de4
index 840b5a90f..d347f5fe6 100644
a30de4
--- a/v2v/input_libvirt_vcenter_https.mli
a30de4
+++ b/v2v/input_libvirt_vcenter_https.mli
a30de4
@@ -18,4 +18,4 @@
a30de4
 
a30de4
 (** [-i libvirt] when the source is VMware vCenter *)
a30de4
 
a30de4
-val input_libvirt_vcenter_https : string option -> string option -> string option -> Xml.uri -> string -> string -> string -> Types.input
a30de4
+val input_libvirt_vcenter_https : string option -> string option -> Xml.uri -> string -> string -> string -> Types.input
a30de4
diff --git a/v2v/test-v2v-docs.sh b/v2v/test-v2v-docs.sh
a30de4
index c5d98de7f..5e49d5240 100755
a30de4
--- a/v2v/test-v2v-docs.sh
a30de4
+++ b/v2v/test-v2v-docs.sh
a30de4
@@ -22,4 +22,4 @@ $TEST_FUNCTIONS
a30de4
 skip_if_skipped
a30de4
 
a30de4
 $top_srcdir/podcheck.pl virt-v2v.pod virt-v2v \
a30de4
-  --ignore=--dcPath,--debug-overlay,--ic,--if,--in-place,--no-trim,--oa,--oc,--of,--on,--os,--vmtype
a30de4
+  --ignore=--debug-overlay,--ic,--if,--in-place,--no-trim,--oa,--oc,--of,--on,--os,--vmtype
a30de4
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
a30de4
index f6e4288f2..2f7e32ad6 100644
a30de4
--- a/v2v/vCenter.ml
a30de4
+++ b/v2v/vCenter.ml
a30de4
@@ -99,7 +99,7 @@ let get_session_cookie password scheme uri sslverify url =
a30de4
 
a30de4
     if status = "404" then (
a30de4
       dump_response stderr;
a30de4
-      error (f_"vcenter: URL not found: %s\n\nThe '--dcpath' parameter may be useful.  See the explanation in the virt-v2v(1) man page OPTIONS section.") url
a30de4
+      error (f_"vcenter: URL not found: %s") url
a30de4
     );
a30de4
 
a30de4
     if status <> "200" then (
a30de4
@@ -126,51 +126,6 @@ let get_session_cookie password scheme uri sslverify url =
a30de4
       Some !session_cookie
a30de4
   )
a30de4
 
a30de4
-let multiple_slash = Str.regexp "/+"
a30de4
-let default_dc = "ha-datacenter"
a30de4
-
a30de4
-let guess_dcPath uri = function
a30de4
-  | "vpx" ->
a30de4
-     (match uri.uri_path with
a30de4
-      | None ->
a30de4
-         warning (f_"vcenter: URI (-ic parameter) contains no path, so we cannot determine the dcPath (datacenter name)");
a30de4
-         default_dc
a30de4
-      | Some path ->
a30de4
-         (* vCenter: URIs are *usually* '/Folder/Datacenter/esxi' so we can
a30de4
-          * just chop off the first '/' and final '/esxi' to get the dcPath.
a30de4
-          *
a30de4
-          * The libvirt driver allows things like '/DC///esxi////' so we also
a30de4
-          * have to handle trailing slashes and collapse multiple slashes into
a30de4
-          * single (RHBZ#1258342).
a30de4
-          *
a30de4
-          * However if there is a cluster involved then the URI may be
a30de4
-          * /Folder/Datacenter/Cluster/esxi but dcPath=Folder/Datacenter/Cluster
a30de4
-          * won't work.  In this case the user has to adjust the path to
a30de4
-          * remove the Cluster name (which still works in libvirt).
a30de4
-          *)
a30de4
-         (* Collapse multiple slashes to single slash. *)
a30de4
-         let path = Str.global_replace multiple_slash "/" path in
a30de4
-         (* Chop off the first and trailing '/' (if found). *)
a30de4
-         let path =
a30de4
-           let len = String.length path in
a30de4
-           if len > 0 && path.[0] = '/' then
a30de4
-             String.sub path 1 (len-1)
a30de4
-           else path in
a30de4
-         let path =
a30de4
-           let len = String.length path in
a30de4
-           if len > 0 && path.[len-1] = '/' then
a30de4
-             String.sub path 0 (len-1)
a30de4
-           else path in
a30de4
-         (* Chop off the final element (ESXi hostname). *)
a30de4
-         let len =
a30de4
-           try String.rindex path '/' with Not_found -> String.length path in
a30de4
-         String.sub path 0 len
a30de4
-     );
a30de4
-  | "esx" -> (* Connecting to an ESXi hypervisor directly, so it's fixed. *)
a30de4
-     default_dc
a30de4
-  | _ ->     (* Don't know, so guess. *)
a30de4
-     default_dc
a30de4
-
a30de4
 let source_re = Str.regexp "^\\[\\(.*\\)\\] \\(.*\\)\\.vmdk$"
a30de4
 
a30de4
 let map_source_to_https dcPath uri server path =
a30de4
diff --git a/v2v/vCenter.mli b/v2v/vCenter.mli
a30de4
index 224f45009..55d70b486 100644
a30de4
--- a/v2v/vCenter.mli
a30de4
+++ b/v2v/vCenter.mli
a30de4
@@ -35,14 +35,6 @@ val get_session_cookie : string option -> string -> Xml.uri -> bool -> string ->
a30de4
     The session cookie is memoized so you can call this function as
a30de4
     often as you want, and only a single log in is made. *)
a30de4
 
a30de4
-val guess_dcPath : Xml.uri -> string -> string
a30de4
-(** Try to guess the dcPath parameter from a URI.  The mapping is
a30de4
-    not precise.
a30de4
-
a30de4
-    This function is only used with [libvirt < 1.2.20] because later
a30de4
-    versions of libvirt provide the dcPath (see
a30de4
-    https://bugzilla.redhat.com/1263574). *)
a30de4
-
a30de4
 val map_source_to_uri : int option -> string -> string option -> Xml.uri -> string -> string -> string -> string
a30de4
 (** [map_source_to_uri readahead dcPath password uri scheme server path]
a30de4
     maps the [<source path=...>] string to a qemu URI.
a30de4
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
a30de4
index d713d0b1f..92ed147d7 100644
a30de4
--- a/v2v/virt-v2v.pod
a30de4
+++ b/v2v/virt-v2v.pod
a30de4
@@ -172,19 +172,6 @@ Write a compressed output file.  This is only allowed if the output
a30de4
 format is qcow2 (see I<-of> below), and is equivalent to the I<-c>
a30de4
 option of L<qemu-img(1)>.
a30de4
 
a30de4
-=item B<--dcpath> Folder/Datacenter
a30de4
-
a30de4
-B<NB:> You don't need to use this parameter if you have
a30de4
-S<libvirt E<ge> 1.2.20>.
a30de4
-
a30de4
-For VMware vCenter, override the C<dcPath=...> parameter used to
a30de4
-select the datacenter.  Virt-v2v can usually calculate this from the
a30de4
-C<vpx://> URI, but if it gets it wrong, then you can override it using
a30de4
-this setting.  Go to your vCenter web folder interface, eg.
a30de4
-C<https://vcenter.example.com/folder> (I<without> a trailing slash),
a30de4
-and examine the C<dcPath=> parameter in the URLs that appear on this
a30de4
-page.
a30de4
-
a30de4
 =item B<--debug-overlays>
a30de4
 
a30de4
 Save the overlay file(s) created during conversion.  This option is
a30de4
-- 
a30de4
2.14.3
a30de4