Blame SOURCES/0217-v2v-vcenter-Calculate-dcPath-correctly-RHBZ-1256823.patch

ffd6ed
From 8e92a862de0eafa7ce2851808b5314c45fa3aef0 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Fri, 28 Aug 2015 12:20:45 +0100
ffd6ed
Subject: [PATCH] v2v: vcenter: Calculate dcPath correctly (RHBZ#1256823).
ffd6ed
ffd6ed
Previously given a path such as:
ffd6ed
ffd6ed
  vpx://vcenter/Folder/Datacenter/esxi
ffd6ed
ffd6ed
we calculated dcPath=Folder.  However this is obviously wrong.  We
ffd6ed
should chop the path at the final (esxi) element to give
ffd6ed
dcPath=Folder/Datacenter.
ffd6ed
ffd6ed
(cherry picked from commit 20f1eb400b13be8733b6586769c4845b99a70722)
ffd6ed
---
ffd6ed
 v2v/input_libvirt_vcenter_https.ml | 18 ++++++++++++++----
ffd6ed
 v2v/virt-v2v.pod                   | 19 ++++++++++++++++---
ffd6ed
 2 files changed, 30 insertions(+), 7 deletions(-)
ffd6ed
ffd6ed
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
ffd6ed
index 3ccbc17..295dded 100644
ffd6ed
--- a/v2v/input_libvirt_vcenter_https.ml
ffd6ed
+++ b/v2v/input_libvirt_vcenter_https.ml
ffd6ed
@@ -174,19 +174,29 @@ and run_curl_get_lines curl_args =
ffd6ed
 let get_dcPath uri scheme =
ffd6ed
   let default_dc = "ha-datacenter" in
ffd6ed
   match scheme with
ffd6ed
-  | "vpx" ->           (* Hopefully the first part of the path. *)
ffd6ed
+  | "vpx" ->
ffd6ed
     (match uri.uri_path with
ffd6ed
     | None ->
ffd6ed
       warning ~prog (f_"vcenter: URI (-ic parameter) contains no path, so we cannot determine the dcPath (datacenter name)");
ffd6ed
       default_dc
ffd6ed
     | Some path ->
ffd6ed
-      let path =
ffd6ed
+      (* vCenter: URIs are *usually* '/Folder/Datacenter/esxi' so we can
ffd6ed
+       * just chop off the first '/' and final '/esxi' to get the dcPath.
ffd6ed
+       *
ffd6ed
+       * However if there is a cluster involved then the URI may be
ffd6ed
+       * /Folder/Datacenter/Cluster/esxi but dcPath=Folder/Datacenter/Cluster
ffd6ed
+       * won't work.  In this case the user has to adjust the path to
ffd6ed
+       * remove the Cluster name (which still works in libvirt).  There
ffd6ed
+       * should be a way to ask the libvirt vpx driver for the correct
ffd6ed
+       * path, but there isn't. XXX  See also RHBZ#1256823.
ffd6ed
+       *)
ffd6ed
+      let path =                (* chop off the first '/' *)
ffd6ed
         let len = String.length path in
ffd6ed
         if len > 0 && path.[0] = '/' then
ffd6ed
           String.sub path 1 (len-1)
ffd6ed
         else path in
ffd6ed
-      let len =
ffd6ed
-        try String.index path '/' with Not_found -> String.length path in
ffd6ed
+      let len =                 (* chop off the final element (ESXi hostname) *)
ffd6ed
+        try String.rindex path '/' with Not_found -> String.length path in
ffd6ed
       String.sub path 0 len
ffd6ed
     );
ffd6ed
   | "esx" -> (* Connecting to an ESXi hypervisor directly, so it's fixed. *)
ffd6ed
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
ffd6ed
index e841a43..eb7ee38 100644
ffd6ed
--- a/v2v/virt-v2v.pod
ffd6ed
+++ b/v2v/virt-v2v.pod
ffd6ed
@@ -830,10 +830,23 @@ is the name of the ESXi hypervisor running the guest.
ffd6ed
 
ffd6ed
 =back
ffd6ed
 
ffd6ed
-If the VMware deployment is using clusters and/or folders, then these
ffd6ed
-may need to be added to the URI, eg:
ffd6ed
+If the VMware deployment is using folders, then these may need to be
ffd6ed
+added to the URI, eg:
ffd6ed
 
ffd6ed
- vpx://user@server/Datacenter/cluster1/esxi
ffd6ed
+ vpx://user@server/Folder/Datacenter/esxi
ffd6ed
+
ffd6ed
+If the deployment uses a cluster before the hostname, then you
ffd6ed
+may need to remove it, ie. change this:
ffd6ed
+
ffd6ed
+ vpx://user@server/Folder/Datacenter/Cluster/esxi
ffd6ed
+
ffd6ed
+to this:
ffd6ed
+
ffd6ed
+ vpx://user@server/Folder/Datacenter/esxi
ffd6ed
+
ffd6ed
+Virt-v2v needs to calculate the C<dcPath> parameter from the URI, and
ffd6ed
+it does this by removing the final C</esxi> element, so in the above
ffd6ed
+example C<dcPath=Folder/Datacenter>.
ffd6ed
 
ffd6ed
 For full details of libvirt URIs, see: L<http://libvirt.org/drvesx.html>
ffd6ed
 
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed