Blob Blame History Raw
From 8e92a862de0eafa7ce2851808b5314c45fa3aef0 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 28 Aug 2015 12:20:45 +0100
Subject: [PATCH] v2v: vcenter: Calculate dcPath correctly (RHBZ#1256823).

Previously given a path such as:

  vpx://vcenter/Folder/Datacenter/esxi

we calculated dcPath=Folder.  However this is obviously wrong.  We
should chop the path at the final (esxi) element to give
dcPath=Folder/Datacenter.

(cherry picked from commit 20f1eb400b13be8733b6586769c4845b99a70722)
---
 v2v/input_libvirt_vcenter_https.ml | 18 ++++++++++++++----
 v2v/virt-v2v.pod                   | 19 ++++++++++++++++---
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
index 3ccbc17..295dded 100644
--- a/v2v/input_libvirt_vcenter_https.ml
+++ b/v2v/input_libvirt_vcenter_https.ml
@@ -174,19 +174,29 @@ and run_curl_get_lines curl_args =
 let get_dcPath uri scheme =
   let default_dc = "ha-datacenter" in
   match scheme with
-  | "vpx" ->           (* Hopefully the first part of the path. *)
+  | "vpx" ->
     (match uri.uri_path with
     | None ->
       warning ~prog (f_"vcenter: URI (-ic parameter) contains no path, so we cannot determine the dcPath (datacenter name)");
       default_dc
     | Some path ->
-      let path =
+      (* vCenter: URIs are *usually* '/Folder/Datacenter/esxi' so we can
+       * just chop off the first '/' and final '/esxi' to get the dcPath.
+       *
+       * 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).  There
+       * should be a way to ask the libvirt vpx driver for the correct
+       * path, but there isn't. XXX  See also RHBZ#1256823.
+       *)
+      let path =                (* chop off the first '/' *)
         let len = String.length path in
         if len > 0 && path.[0] = '/' then
           String.sub path 1 (len-1)
         else path in
-      let len =
-        try String.index path '/' with Not_found -> String.length path in
+      let len =                 (* chop off the final element (ESXi hostname) *)
+        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. *)
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index e841a43..eb7ee38 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -830,10 +830,23 @@ is the name of the ESXi hypervisor running the guest.
 
 =back
 
-If the VMware deployment is using clusters and/or folders, then these
-may need to be added to the URI, eg:
+If the VMware deployment is using folders, then these may need to be
+added to the URI, eg:
 
- vpx://user@server/Datacenter/cluster1/esxi
+ vpx://user@server/Folder/Datacenter/esxi
+
+If the deployment uses a cluster before the hostname, then you
+may need to remove it, ie. change this:
+
+ vpx://user@server/Folder/Datacenter/Cluster/esxi
+
+to this:
+
+ vpx://user@server/Folder/Datacenter/esxi
+
+Virt-v2v needs to calculate the C<dcPath> parameter from the URI, and
+it does this by removing the final C</esxi> element, so in the above
+example C<dcPath=Folder/Datacenter>.
 
 For full details of libvirt URIs, see: L<http://libvirt.org/drvesx.html>
 
-- 
1.8.3.1