|
|
0d20ef |
From 98cff1393866cf8df62c559bbc8abdaed515b91c Mon Sep 17 00:00:00 2001
|
|
|
0d20ef |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
0d20ef |
Date: Mon, 20 Oct 2014 17:37:04 +0100
|
|
|
0d20ef |
Subject: [PATCH] v2v: -i libvirt: Create three specialized subclasses for
|
|
|
0d20ef |
handling vCenter/Xen/other.
|
|
|
0d20ef |
|
|
|
0d20ef |
Previously we had one class ('input_libvirt') which handled all three
|
|
|
0d20ef |
cases. Now we have one superclass ('input_libvirt') and three
|
|
|
0d20ef |
subclasses of that ('input_libvirt_vcenter_https',
|
|
|
0d20ef |
'input_libvirt_xen_ssh', 'input_libvirt_other') which handle the three
|
|
|
0d20ef |
cases separately.
|
|
|
0d20ef |
|
|
|
0d20ef |
This is just code motion, and should be functionally equivalent to
|
|
|
0d20ef |
what was here before.
|
|
|
0d20ef |
|
|
|
0d20ef |
(cherry picked from commit 9596fc44ff522f5f993a3c5ef9bb24a9a1b4a996)
|
|
|
0d20ef |
---
|
|
|
0d20ef |
v2v/input_libvirt.ml | 138 ++++++++++++++++++++++++++++++++++-----------------
|
|
|
0d20ef |
1 file changed, 92 insertions(+), 46 deletions(-)
|
|
|
0d20ef |
|
|
|
0d20ef |
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
|
|
|
0d20ef |
index def58bd..e8b1345 100644
|
|
|
0d20ef |
--- a/v2v/input_libvirt.ml
|
|
|
0d20ef |
+++ b/v2v/input_libvirt.ml
|
|
|
0d20ef |
@@ -42,7 +42,8 @@ let error_if_no_ssh_agent () =
|
|
|
0d20ef |
with Not_found ->
|
|
|
0d20ef |
error (f_"ssh-agent authentication has not been set up ($SSH_AUTH_SOCK is not set). Please read \"INPUT FROM RHEL 5 XEN\" in the virt-v2v(1) man page.")
|
|
|
0d20ef |
|
|
|
0d20ef |
-class input_libvirt verbose libvirt_uri guest =
|
|
|
0d20ef |
+(* Superclass. *)
|
|
|
0d20ef |
+class virtual input_libvirt verbose libvirt_uri guest =
|
|
|
0d20ef |
object
|
|
|
0d20ef |
inherit input verbose
|
|
|
0d20ef |
|
|
|
0d20ef |
@@ -52,61 +53,106 @@ object
|
|
|
0d20ef |
| None -> ""
|
|
|
0d20ef |
| Some uri -> " -ic " ^ uri)
|
|
|
0d20ef |
guest
|
|
|
0d20ef |
+end
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+(* Subclass specialized for handling anything that's *not* VMware vCenter
|
|
|
0d20ef |
+ * or Xen.
|
|
|
0d20ef |
+ *)
|
|
|
0d20ef |
+class input_libvirt_other verbose libvirt_uri guest =
|
|
|
0d20ef |
+object
|
|
|
0d20ef |
+ inherit input_libvirt verbose libvirt_uri guest
|
|
|
0d20ef |
|
|
|
0d20ef |
method source () =
|
|
|
0d20ef |
+ if verbose then printf "input_libvirt_other: source()\n%!";
|
|
|
0d20ef |
+
|
|
|
0d20ef |
(* Get the libvirt XML. This also checks (as a side-effect)
|
|
|
0d20ef |
* that the domain is not running. (RHBZ#1138586)
|
|
|
0d20ef |
*)
|
|
|
0d20ef |
let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
|
|
|
0d20ef |
|
|
|
0d20ef |
- (* Depending on the libvirt URI we may need to convert <source/>
|
|
|
0d20ef |
- * paths so we can access them remotely (if that is possible). This
|
|
|
0d20ef |
- * is only true for remote, non-NULL URIs. (We assume the user
|
|
|
0d20ef |
- * doesn't try setting $LIBVIRT_URI. If they do that then all bets
|
|
|
0d20ef |
- * are off).
|
|
|
0d20ef |
+ Input_libvirtxml.parse_libvirt_xml ~verbose xml
|
|
|
0d20ef |
+end
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+(* Subclass specialized for handling VMware vCenter over https. *)
|
|
|
0d20ef |
+class input_libvirt_vcenter_https
|
|
|
0d20ef |
+ verbose libvirt_uri parsed_uri scheme server guest =
|
|
|
0d20ef |
+object
|
|
|
0d20ef |
+ inherit input_libvirt verbose libvirt_uri guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ method source () =
|
|
|
0d20ef |
+ if verbose then printf "input_libvirt_vcenter_https: source()\n%!";
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ (* Get the libvirt XML. This also checks (as a side-effect)
|
|
|
0d20ef |
+ * that the domain is not running. (RHBZ#1138586)
|
|
|
0d20ef |
*)
|
|
|
0d20ef |
- let map_source_file, map_source_dev =
|
|
|
0d20ef |
- match libvirt_uri with
|
|
|
0d20ef |
- | None -> None, None
|
|
|
0d20ef |
- | Some orig_uri ->
|
|
|
0d20ef |
- let { Xml.uri_server = server; uri_scheme = scheme } as uri =
|
|
|
0d20ef |
- try Xml.parse_uri orig_uri
|
|
|
0d20ef |
- with Invalid_argument msg ->
|
|
|
0d20ef |
- error (f_"could not parse '-ic %s'. Original error message was: %s")
|
|
|
0d20ef |
- orig_uri msg in
|
|
|
0d20ef |
-
|
|
|
0d20ef |
- match server, scheme with
|
|
|
0d20ef |
- | None, _
|
|
|
0d20ef |
- | Some "", _ -> (* Not a remote URI. *)
|
|
|
0d20ef |
- None, None
|
|
|
0d20ef |
-
|
|
|
0d20ef |
- | Some _, None (* No scheme? *)
|
|
|
0d20ef |
- | Some _, Some "" ->
|
|
|
0d20ef |
- None, None
|
|
|
0d20ef |
-
|
|
|
0d20ef |
- | Some server, Some ("esx"|"gsx"|"vpx" as scheme) -> (* ESX *)
|
|
|
0d20ef |
- error_if_libvirt_backend ();
|
|
|
0d20ef |
- let f = VCenter.map_path_to_uri verbose uri scheme server in
|
|
|
0d20ef |
- Some f, Some f
|
|
|
0d20ef |
-
|
|
|
0d20ef |
- | Some server, Some ("xen+ssh" as scheme) -> (* Xen over SSH *)
|
|
|
0d20ef |
- error_if_libvirt_backend ();
|
|
|
0d20ef |
- error_if_no_ssh_agent ();
|
|
|
0d20ef |
- let f = Xen.map_path_to_uri verbose uri scheme server in
|
|
|
0d20ef |
- Some f, Some f
|
|
|
0d20ef |
-
|
|
|
0d20ef |
- (* Old virt-v2v also supported qemu+ssh://. However I am
|
|
|
0d20ef |
- * deliberately not supporting this in new virt-v2v. Don't
|
|
|
0d20ef |
- * use virt-v2v if a guest already runs on KVM.
|
|
|
0d20ef |
- *)
|
|
|
0d20ef |
- | Some _, Some _ -> (* Unknown remote scheme. *)
|
|
|
0d20ef |
- warning ~prog (f_"no support for remote libvirt connections to '-ic %s'. The conversion may fail when it tries to read the source disks.")
|
|
|
0d20ef |
- orig_uri;
|
|
|
0d20ef |
- None, None in
|
|
|
0d20ef |
+ let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
|
|
|
0d20ef |
|
|
|
0d20ef |
+ error_if_libvirt_backend ();
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ let mapf = VCenter.map_path_to_uri verbose parsed_uri scheme server in
|
|
|
0d20ef |
Input_libvirtxml.parse_libvirt_xml ~verbose
|
|
|
0d20ef |
- ?map_source_file ?map_source_dev xml
|
|
|
0d20ef |
+ ~map_source_file:mapf ~map_source_dev:mapf xml
|
|
|
0d20ef |
end
|
|
|
0d20ef |
|
|
|
0d20ef |
-let input_libvirt = new input_libvirt
|
|
|
0d20ef |
+(* Subclass specialized for handling Xen over SSH. *)
|
|
|
0d20ef |
+class input_libvirt_xen_ssh
|
|
|
0d20ef |
+ verbose libvirt_uri parsed_uri scheme server guest =
|
|
|
0d20ef |
+object
|
|
|
0d20ef |
+ inherit input_libvirt verbose libvirt_uri guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ method source () =
|
|
|
0d20ef |
+ if verbose then printf "input_libvirt_xen_ssh: source()\n%!";
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ (* Get the libvirt XML. This also checks (as a side-effect)
|
|
|
0d20ef |
+ * that the domain is not running. (RHBZ#1138586)
|
|
|
0d20ef |
+ *)
|
|
|
0d20ef |
+ let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ error_if_libvirt_backend ();
|
|
|
0d20ef |
+ error_if_no_ssh_agent ();
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ let mapf = Xen.map_path_to_uri verbose parsed_uri scheme server in
|
|
|
0d20ef |
+ Input_libvirtxml.parse_libvirt_xml ~verbose
|
|
|
0d20ef |
+ ~map_source_file:mapf ~map_source_dev:mapf xml
|
|
|
0d20ef |
+end
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+(* Choose the right subclass based on the URI. *)
|
|
|
0d20ef |
+let input_libvirt verbose libvirt_uri guest =
|
|
|
0d20ef |
+ match libvirt_uri with
|
|
|
0d20ef |
+ | None ->
|
|
|
0d20ef |
+ new input_libvirt_other verbose libvirt_uri guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ | Some orig_uri ->
|
|
|
0d20ef |
+ let { Xml.uri_server = server; uri_scheme = scheme } as parsed_uri =
|
|
|
0d20ef |
+ try Xml.parse_uri orig_uri
|
|
|
0d20ef |
+ with Invalid_argument msg ->
|
|
|
0d20ef |
+ error (f_"could not parse '-ic %s'. Original error message was: %s")
|
|
|
0d20ef |
+ orig_uri msg in
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ match server, scheme with
|
|
|
0d20ef |
+ | None, _
|
|
|
0d20ef |
+ | Some "", _ (* Not a remote URI. *)
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ | Some _, None (* No scheme? *)
|
|
|
0d20ef |
+ | Some _, Some "" ->
|
|
|
0d20ef |
+ new input_libvirt_other verbose libvirt_uri guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ | Some server, Some ("esx"|"gsx"|"vpx" as scheme) -> (* vCenter over https *)
|
|
|
0d20ef |
+ new input_libvirt_vcenter_https
|
|
|
0d20ef |
+ verbose libvirt_uri parsed_uri scheme server guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ | Some server, Some ("xen+ssh" as scheme) -> (* Xen over SSH *)
|
|
|
0d20ef |
+ new input_libvirt_xen_ssh
|
|
|
0d20ef |
+ verbose libvirt_uri parsed_uri scheme server guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ (* Old virt-v2v also supported qemu+ssh://. However I am
|
|
|
0d20ef |
+ * deliberately not supporting this in new virt-v2v. Don't
|
|
|
0d20ef |
+ * use virt-v2v if a guest already runs on KVM.
|
|
|
0d20ef |
+ *)
|
|
|
0d20ef |
+
|
|
|
0d20ef |
+ | Some _, Some _ -> (* Unknown remote scheme. *)
|
|
|
0d20ef |
+ warning ~prog (f_"no support for remote libvirt connections to '-ic %s'. The conversion may fail when it tries to read the source disks.")
|
|
|
0d20ef |
+ orig_uri;
|
|
|
0d20ef |
+ new input_libvirt_other verbose libvirt_uri guest
|
|
|
0d20ef |
+
|
|
|
0d20ef |
let () = Modules_list.register_input_module "libvirt"
|
|
|
0d20ef |
--
|
|
|
0d20ef |
1.8.3.1
|
|
|
0d20ef |
|