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

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