|
|
b66178 |
From 3a937f3fac910fa7109f7edd0608388f52bec95e Mon Sep 17 00:00:00 2001
|
|
|
b66178 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
b66178 |
Date: Fri, 9 Oct 2015 12:22:52 +0100
|
|
|
b66178 |
Subject: [PATCH] v2v: Use libvirt-supplied <vmware:datacenterpath> if
|
|
|
b66178 |
available.
|
|
|
b66178 |
|
|
|
b66178 |
In libvirt >= 1.2.20, the VMware libvirt driver supplies the correct
|
|
|
b66178 |
dcPath to use via <vmware:datacenterpath> in the libvirt XML. If
|
|
|
b66178 |
libvirt passes us this element, use it.
|
|
|
b66178 |
|
|
|
b66178 |
This code still allows the user to override dcPath using the --dcPath
|
|
|
b66178 |
option on the command line, but that's mainly for safety so we can fix
|
|
|
b66178 |
any problems in virt-v2v or libvirt in the field. As we get more
|
|
|
b66178 |
confident in libvirt and as libvirt 1.2.20 is more widely adopted, we
|
|
|
b66178 |
will be able to deprecate this parameter entirely.
|
|
|
b66178 |
|
|
|
b66178 |
Thanks: Matthias Bolte for adding the <vmware:datacenterpath> element
|
|
|
b66178 |
to libvirt in
|
|
|
b66178 |
https://libvirt.org/git/?p=libvirt.git;a=commit;h=636a99058758a0447482f3baad94de8de3ab1151
|
|
|
b66178 |
|
|
|
b66178 |
(cherry picked from commit ffea9f97926efc45c894a113b65b2ff467d91b04)
|
|
|
b66178 |
---
|
|
|
b66178 |
v2v/input_libvirt_vcenter_https.ml | 52 +++++++++++++++++++++++++-------------
|
|
|
b66178 |
v2v/virt-v2v.pod | 9 +++----
|
|
|
b66178 |
2 files changed, 38 insertions(+), 23 deletions(-)
|
|
|
b66178 |
|
|
|
b66178 |
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
|
|
|
b66178 |
index 684a7e4..25a8ee9 100644
|
|
|
b66178 |
--- a/v2v/input_libvirt_vcenter_https.ml
|
|
|
b66178 |
+++ b/v2v/input_libvirt_vcenter_https.ml
|
|
|
b66178 |
@@ -192,9 +192,7 @@ let get_dcPath uri scheme =
|
|
|
b66178 |
* However if there is a cluster involved then the URI may be
|
|
|
b66178 |
* /Folder/Datacenter/Cluster/esxi but dcPath=Folder/Datacenter/Cluster
|
|
|
b66178 |
* won't work. In this case the user has to adjust the path to
|
|
|
b66178 |
- * remove the Cluster name (which still works in libvirt). There
|
|
|
b66178 |
- * should be a way to ask the libvirt vpx driver for the correct
|
|
|
b66178 |
- * path, but there isn't. XXX See also RHBZ#1256823.
|
|
|
b66178 |
+ * remove the Cluster name (which still works in libvirt).
|
|
|
b66178 |
*)
|
|
|
b66178 |
(* Collapse multiple slashes to single slash. *)
|
|
|
b66178 |
let path = Str.global_replace multiple_slash "/" path in
|
|
|
b66178 |
@@ -242,19 +240,6 @@ let map_source_to_uri ?readahead verbose dcPath password uri scheme server path
|
|
|
b66178 |
let datastore = Str.matched_group 1 path
|
|
|
b66178 |
and path = Str.matched_group 2 path in
|
|
|
b66178 |
|
|
|
b66178 |
- (* Get the dcPath. *)
|
|
|
b66178 |
- let dcPath =
|
|
|
b66178 |
- match dcPath with
|
|
|
b66178 |
- | None ->
|
|
|
b66178 |
- let dcPath = get_dcPath uri scheme in
|
|
|
b66178 |
- if verbose then
|
|
|
b66178 |
- printf "vcenter: calculated dcPath as: %s\n" dcPath;
|
|
|
b66178 |
- dcPath
|
|
|
b66178 |
- | Some dcPath ->
|
|
|
b66178 |
- if verbose then
|
|
|
b66178 |
- printf "vcenter: using --dcpath from the command line: %s\n" dcPath;
|
|
|
b66178 |
- dcPath in
|
|
|
b66178 |
-
|
|
|
b66178 |
let port =
|
|
|
b66178 |
match uri.uri_port with
|
|
|
b66178 |
| 443 -> ""
|
|
|
b66178 |
@@ -317,11 +302,12 @@ let map_source_to_uri ?readahead verbose dcPath password uri scheme server path
|
|
|
b66178 |
|
|
|
b66178 |
(* Subclass specialized for handling VMware vCenter over https. *)
|
|
|
b66178 |
class input_libvirt_vcenter_https
|
|
|
b66178 |
- verbose dcPath password libvirt_uri parsed_uri scheme server guest =
|
|
|
b66178 |
+ verbose cmdline_dcPath password libvirt_uri parsed_uri scheme server guest =
|
|
|
b66178 |
object
|
|
|
b66178 |
inherit input_libvirt verbose password libvirt_uri guest
|
|
|
b66178 |
|
|
|
b66178 |
val saved_source_paths = Hashtbl.create 13
|
|
|
b66178 |
+ val mutable dcPath = ""
|
|
|
b66178 |
|
|
|
b66178 |
method source () =
|
|
|
b66178 |
if verbose then
|
|
|
b66178 |
@@ -336,6 +322,38 @@ object
|
|
|
b66178 |
let xml = Domainxml.dumpxml ?password ?conn:libvirt_uri guest in
|
|
|
b66178 |
let source, disks = parse_libvirt_xml ?conn:libvirt_uri ~verbose xml in
|
|
|
b66178 |
|
|
|
b66178 |
+ (* Find the <vmware:datacenterpath> element from the XML, if it
|
|
|
b66178 |
+ * exists. This was added in libvirt >= 1.2.20.
|
|
|
b66178 |
+ *)
|
|
|
b66178 |
+ let xml_dcPath =
|
|
|
b66178 |
+ let doc = Xml.parse_memory xml in
|
|
|
b66178 |
+ let xpathctx = Xml.xpath_new_context doc in
|
|
|
b66178 |
+ Xml.xpath_register_ns xpathctx
|
|
|
b66178 |
+ "vmware" "http://libvirt.org/schemas/domain/vmware/1.0";
|
|
|
b66178 |
+ let xpath_string = xpath_string xpathctx in
|
|
|
b66178 |
+ xpath_string "/domain/vmware:datacenterpath" in
|
|
|
b66178 |
+
|
|
|
b66178 |
+ (* Calculate the dcPath we're going to use. *)
|
|
|
b66178 |
+ dcPath <- (
|
|
|
b66178 |
+ match cmdline_dcPath, xml_dcPath with
|
|
|
b66178 |
+ (* Command line --dcpath parameter overrides everything, allowing
|
|
|
b66178 |
+ * users to correct any mistakes in v2v or libvirt.
|
|
|
b66178 |
+ *)
|
|
|
b66178 |
+ | Some p, (None|Some _) ->
|
|
|
b66178 |
+ if verbose then
|
|
|
b66178 |
+ printf "vcenter: using --dcpath from the command line: %s\n" p;
|
|
|
b66178 |
+ p
|
|
|
b66178 |
+ | None, Some p ->
|
|
|
b66178 |
+ if verbose then
|
|
|
b66178 |
+ printf "vcenter: using <vmware:datacenterpath> from libvirt: %s\n" p;
|
|
|
b66178 |
+ p
|
|
|
b66178 |
+ | None, None ->
|
|
|
b66178 |
+ let p = get_dcPath parsed_uri scheme in
|
|
|
b66178 |
+ if verbose then
|
|
|
b66178 |
+ printf "vcenter: guessed dcPath from URI: %s\n" p;
|
|
|
b66178 |
+ p
|
|
|
b66178 |
+ );
|
|
|
b66178 |
+
|
|
|
b66178 |
(* Save the original source paths, so that we can remap them again
|
|
|
b66178 |
* in [#adjust_overlay_parameters].
|
|
|
b66178 |
*)
|
|
|
b66178 |
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
|
|
|
b66178 |
index 2e257de..b8caebc 100644
|
|
|
b66178 |
--- a/v2v/virt-v2v.pod
|
|
|
b66178 |
+++ b/v2v/virt-v2v.pod
|
|
|
b66178 |
@@ -155,6 +155,9 @@ See I<--network> below.
|
|
|
b66178 |
|
|
|
b66178 |
=item B<--dcpath> Folder/Datacenter
|
|
|
b66178 |
|
|
|
b66178 |
+B<NB:> You don't need to use this parameter if you have
|
|
|
b66178 |
+S<libvirt E<ge> 1.2.17-13.el7_2.4>.
|
|
|
b66178 |
+
|
|
|
b66178 |
For VMware vCenter, override the C<dcPath=...> parameter used to
|
|
|
b66178 |
select the datacenter. Virt-v2v can usually calculate this from the
|
|
|
b66178 |
C<vpx://> URI, but if it gets it wrong, then you can override it using
|
|
|
b66178 |
@@ -845,12 +848,6 @@ added to the URI, eg:
|
|
|
b66178 |
|
|
|
b66178 |
vpx://user@server/Folder/Datacenter/esxi
|
|
|
b66178 |
|
|
|
b66178 |
-Virt-v2v needs to calculate the C<dcPath> parameter from the URI, and
|
|
|
b66178 |
-it does this by removing the final C</esxi> element, so in the above
|
|
|
b66178 |
-example C<dcPath=Folder/Datacenter>. As it is not always possible to
|
|
|
b66178 |
-correctly calculate C<dcPath> from the URI, you can override this
|
|
|
b66178 |
-using the I<--dcpath> parameter.
|
|
|
b66178 |
-
|
|
|
b66178 |
For full details of libvirt URIs, see: L<http://libvirt.org/drvesx.html>
|
|
|
b66178 |
|
|
|
b66178 |
Typical errors from libvirt / virsh when the URI is wrong include:
|
|
|
b66178 |
--
|
|
|
b66178 |
1.8.3.1
|
|
|
b66178 |
|