[Libguestfs] [PATCH 1/5] v2v: Remove --dcpath parameter and related functionality.

Richard W.M. Jones rjones at redhat.com
Fri Oct 13 16:27:17 UTC 2017


With modern libvirt, when fetching the XML of a VMware guest libvirt
passes us the datacenter path (dcpath).  However with older libvirt we
had to guess this value, or else the user had to supply it on the
command line.

This commit removes all the guessing code and the --dcpath parameter
(which will now give an error).

This requires libvirt >= 1.2.20 for virt-v2v, released Oct 2015.
---
 v2v/cmdline.ml                      |  6 +----
 v2v/copy_to_local.ml                |  6 +++--
 v2v/input_libvirt.ml                |  4 ++--
 v2v/input_libvirt.mli               |  4 ++--
 v2v/input_libvirt_vcenter_https.ml  | 31 +++++++-----------------
 v2v/input_libvirt_vcenter_https.mli |  2 +-
 v2v/test-v2v-docs.sh                |  2 +-
 v2v/vCenter.ml                      | 47 +------------------------------------
 v2v/vCenter.mli                     |  8 -------
 v2v/virt-v2v.pod                    | 13 ----------
 10 files changed, 20 insertions(+), 103 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 1ae018bcd..a5f4f7846 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -55,7 +55,6 @@ let parse_cmdline () =
   let print_source = ref false in
   let qemu_boot = ref false in
 
-  let dcpath = ref None in
   let input_conn = ref None in
   let input_format = ref None in
   let in_place = ref false in
@@ -182,8 +181,6 @@ let parse_cmdline () =
   let argspec = [
     [ S 'b'; L"bridge" ],        Getopt.String ("in:out", add_bridge),     s_"Map bridge ‘in’ to ‘out’";
     [ L"compressed" ], Getopt.Set compressed,     s_"Compress output file (-of qcow2 only)";
-    [ L"dcpath"; L"dcPath" ],  Getopt.String ("path", set_string_option_once "--dcpath" dcpath),
-                                            s_"Override dcPath (for vCenter)";
     [ L"debug-overlay"; L"debug-overlays" ], Getopt.Set debug_overlays, s_"Save overlay files";
     [ S 'i' ],        Getopt.String (i_options, set_input_mode), s_"Set input mode (default: libvirt)";
     [ M"ic" ],       Getopt.String ("uri", set_string_option_once "-ic" input_conn),
@@ -270,7 +267,6 @@ read the man page virt-v2v(1).
   (* Dereference the arguments. *)
   let args = List.rev !args in
   let compressed = !compressed in
-  let dcpath = !dcpath in
   let debug_overlays = !debug_overlays in
   let do_copy = !do_copy in
   let input_conn = !input_conn in
@@ -368,7 +364,7 @@ read the man page virt-v2v(1).
         | [guest] -> guest
         | _ ->
           error (f_"expecting a libvirt guest name on the command line") in
-      Input_libvirt.input_libvirt dcpath vddk_options password input_conn guest
+      Input_libvirt.input_libvirt vddk_options password input_conn guest
 
     | `LibvirtXML ->
       (* -i libvirtxml: Expecting a filename (XML file). *)
diff --git a/v2v/copy_to_local.ml b/v2v/copy_to_local.ml
index 8a64f3a58..63e1ea310 100644
--- a/v2v/copy_to_local.ml
+++ b/v2v/copy_to_local.ml
@@ -245,8 +245,10 @@ and parse_libvirt_xml guest_name xml =
                         "vmware" "http://libvirt.org/schemas/domain/vmware/1.0";
   let xpath_string = xpath_string xpathctx in
 
-  (* Get the dcpath, only present for libvirt >= 1.2.20 so use a
-   * sensible default for older versions.
+  (* Get the dcpath, present in libvirt >= 1.2.20.
+   * XXX Unfortunately when testing virt-v2v-copy-to-local against a
+   * local libvirt test XML file, we cannot pass in the vmware namespace.
+   * So we must keep the default here until we can resolve that somehow.
    *)
   let dcpath =
     Option.default "ha-datacenter"
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
index 708feccc7..d05116ac6 100644
--- a/v2v/input_libvirt.ml
+++ b/v2v/input_libvirt.ml
@@ -27,7 +27,7 @@ open Types
 open Utils
 
 (* Choose the right subclass based on the URI. *)
-let input_libvirt dcpath vddk_options password libvirt_uri guest =
+let input_libvirt vddk_options password libvirt_uri guest =
   match libvirt_uri with
   | None ->
     Input_libvirt_other.input_libvirt_other password libvirt_uri guest
@@ -54,7 +54,7 @@ let input_libvirt dcpath vddk_options password libvirt_uri guest =
        (match vddk_options with
         | None ->
            Input_libvirt_vcenter_https.input_libvirt_vcenter_https
-             dcpath password libvirt_uri parsed_uri scheme server guest
+             password libvirt_uri parsed_uri scheme server guest
         | Some vddk_options ->
            Input_libvirt_vddk.input_libvirt_vddk vddk_options password
                                                  libvirt_uri parsed_uri guest
diff --git a/v2v/input_libvirt.mli b/v2v/input_libvirt.mli
index 0a6aa3c54..acf2ca417 100644
--- a/v2v/input_libvirt.mli
+++ b/v2v/input_libvirt.mli
@@ -18,7 +18,7 @@
 
 (** [-i libvirt] source. *)
 
-val input_libvirt : string option -> Types.vddk_options option -> string option -> string option -> string -> Types.input
-(** [input_libvirt dcpath vddk_options password libvirt_uri guest] creates
+val input_libvirt : Types.vddk_options option -> string option -> string option -> string -> Types.input
+(** [input_libvirt vddk_options password libvirt_uri guest] creates
     and returns a new {!Types.input} object specialized for reading input
     from libvirt sources. *)
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
index fef64583f..4c2fb3cc1 100644
--- a/v2v/input_libvirt_vcenter_https.ml
+++ b/v2v/input_libvirt_vcenter_https.ml
@@ -36,7 +36,7 @@ let readahead_for_copying = Some (64 * 1024 * 1024)
 
 (* Subclass specialized for handling VMware vCenter over https. *)
 class input_libvirt_vcenter_https
-  cmdline_dcPath password libvirt_uri parsed_uri scheme server guest =
+        password libvirt_uri parsed_uri scheme server guest =
 object
   inherit input_libvirt password libvirt_uri guest
 
@@ -67,33 +67,18 @@ object
     let xml = Libvirt_utils.dumpxml ?password ?conn:libvirt_uri guest in
     let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
 
-    (* Find the <vmware:datacenterpath> element from the XML, if it
-     * exists.  This was added in libvirt >= 1.2.20.
+    (* Find the <vmware:datacenterpath> element from the XML.  This
+     * was added in libvirt >= 1.2.20.
      *)
-    let xml_dcPath =
+    dcPath <- (
       let doc = Xml.parse_memory xml in
       let xpathctx = Xml.xpath_new_context doc in
       Xml.xpath_register_ns xpathctx
         "vmware" "http://libvirt.org/schemas/domain/vmware/1.0";
-      let xpath_string = xpath_string xpathctx in
-      xpath_string "/domain/vmware:datacenterpath" in
-
-    (* Calculate the dcPath we're going to use. *)
-    dcPath <- (
-      match cmdline_dcPath, xml_dcPath with
-      (* Command line --dcpath parameter overrides everything, allowing
-       * users to correct any mistakes in v2v or libvirt.
-       *)
-      | Some p, (None|Some _) ->
-         debug "vcenter: using --dcpath from the command line: %s" p;
-         p
-      | None, Some p ->
-         debug "vcenter: using <vmware:datacenterpath> from libvirt: %s" p;
-         p
-      | None, None ->
-         let p = VCenter.guess_dcPath parsed_uri scheme in
-         debug "vcenter: guessed dcPath from URI: %s" p;
-         p
+      match xpath_string xpathctx "/domain/vmware:datacenterpath" with
+      | Some dcPath -> dcPath
+      | None ->
+         error (f_"vcenter: <vmware:datacenterpath> was not found in the XML.  You need to upgrade to libvirt ≥ 1.2.20.")
     );
 
     (* Save the original source paths, so that we can remap them again
diff --git a/v2v/input_libvirt_vcenter_https.mli b/v2v/input_libvirt_vcenter_https.mli
index 840b5a90f..d347f5fe6 100644
--- a/v2v/input_libvirt_vcenter_https.mli
+++ b/v2v/input_libvirt_vcenter_https.mli
@@ -18,4 +18,4 @@
 
 (** [-i libvirt] when the source is VMware vCenter *)
 
-val input_libvirt_vcenter_https : string option -> string option -> string option -> Xml.uri -> string -> string -> string -> Types.input
+val input_libvirt_vcenter_https : string option -> string option -> Xml.uri -> string -> string -> string -> Types.input
diff --git a/v2v/test-v2v-docs.sh b/v2v/test-v2v-docs.sh
index d341852b7..8bd03f68e 100755
--- a/v2v/test-v2v-docs.sh
+++ b/v2v/test-v2v-docs.sh
@@ -22,4 +22,4 @@ $TEST_FUNCTIONS
 skip_if_skipped
 
 $top_srcdir/podcheck.pl virt-v2v.pod virt-v2v \
-  --ignore=--dcPath,--debug-overlay,--ic,--if,--no-trim,--oa,--oc,--of,--on,--os,--vmtype
+  --ignore=--debug-overlay,--ic,--if,--no-trim,--oa,--oc,--of,--on,--os,--vmtype
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
index 41bdbdd01..e244ff4d5 100644
--- a/v2v/vCenter.ml
+++ b/v2v/vCenter.ml
@@ -86,7 +86,7 @@ let get_session_cookie password scheme uri sslverify url =
 
     if status = "404" then (
       dump_response stderr;
-      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
+      error (f_"vcenter: URL not found: %s") url
     );
 
     if status <> "200" then (
@@ -113,51 +113,6 @@ let get_session_cookie password scheme uri sslverify url =
       Some !session_cookie
   )
 
-let multiple_slash = PCRE.compile "/{2,}"
-let default_dc = "ha-datacenter"
-
-let guess_dcPath uri = function
-  | "vpx" ->
-     (match uri.uri_path with
-      | None ->
-         warning (f_"vcenter: URI (-ic parameter) contains no path, so we cannot determine the dcPath (datacenter name)");
-         default_dc
-      | Some path ->
-         (* vCenter: URIs are *usually* '/Folder/Datacenter/esxi' so we can
-          * just chop off the first '/' and final '/esxi' to get the dcPath.
-          *
-          * The libvirt driver allows things like '/DC///esxi////' so we also
-          * have to handle trailing slashes and collapse multiple slashes into
-          * single (RHBZ#1258342).
-          *
-          * However if there is a cluster involved then the URI may be
-          * /Folder/Datacenter/Cluster/esxi but dcPath=Folder/Datacenter/Cluster
-          * won't work.  In this case the user has to adjust the path to
-          * remove the Cluster name (which still works in libvirt).
-          *)
-         (* Collapse multiple slashes to single slash. *)
-         let path = PCRE.replace ~global:true multiple_slash "/" path in
-         (* Chop off the first and trailing '/' (if found). *)
-         let path =
-           let len = String.length path in
-           if len > 0 && path.[0] = '/' then
-             String.sub path 1 (len-1)
-           else path in
-         let path =
-           let len = String.length path in
-           if len > 0 && path.[len-1] = '/' then
-             String.sub path 0 (len-1)
-           else path in
-         (* Chop off the final element (ESXi hostname). *)
-         let len =
-           try String.rindex path '/' with Not_found -> String.length path in
-         String.sub path 0 len
-     );
-  | "esx" -> (* Connecting to an ESXi hypervisor directly, so it's fixed. *)
-     default_dc
-  | _ ->     (* Don't know, so guess. *)
-     default_dc
-
 let source_re = PCRE.compile "^\\[(.*)\\] (.*)\\.vmdk$"
 
 let map_source_to_https dcPath uri server path =
diff --git a/v2v/vCenter.mli b/v2v/vCenter.mli
index 224f45009..55d70b486 100644
--- a/v2v/vCenter.mli
+++ b/v2v/vCenter.mli
@@ -35,14 +35,6 @@ val get_session_cookie : string option -> string -> Xml.uri -> bool -> string ->
     The session cookie is memoized so you can call this function as
     often as you want, and only a single log in is made. *)
 
-val guess_dcPath : Xml.uri -> string -> string
-(** Try to guess the dcPath parameter from a URI.  The mapping is
-    not precise.
-
-    This function is only used with [libvirt < 1.2.20] because later
-    versions of libvirt provide the dcPath (see
-    https://bugzilla.redhat.com/1263574). *)
-
 val map_source_to_uri : int option -> string -> string option -> Xml.uri -> string -> string -> string -> string
 (** [map_source_to_uri readahead dcPath password uri scheme server path]
     maps the [<source path=...>] string to a qemu URI.
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 28292f6e3..199a7dd8b 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -282,19 +282,6 @@ Write a compressed output file.  This is only allowed if the output
 format is qcow2 (see I<-of> below), and is equivalent to the I<-c>
 option of L<qemu-img(1)>.
 
-=item B<--dcpath> Folder/Datacenter
-
-B<NB:> You don’t need to use this parameter if you have
-S<libvirt E<ge> 1.2.20>.
-
-For VMware vCenter, override the C<dcPath=...> parameter used to
-select the datacenter.  Virt-v2v can usually calculate this from the
-C<vpx://> URI, but if it gets it wrong, then you can override it using
-this setting.  Go to your vCenter web folder interface, eg.
-C<https://vcenter.example.com/folder> (I<without> a trailing slash),
-and examine the C<dcPath=> parameter in the URLs that appear on this
-page.
-
 =item B<--debug-overlays>
 
 Save the overlay file(s) created during conversion.  This option is
-- 
2.13.2




More information about the Libguestfs mailing list