[Pkg-libvirt-commits] [libguestfs] 07/40: v2v: Abstract Convert_* modules from core v2v code.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:44:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.44-1
in repository libguestfs.
commit 3d2e2bb44556a218ad4cc4d4d4e6b90cd43d60cf
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Tue Sep 9 23:58:17 2014 +0100
v2v: Abstract Convert_* modules from core v2v code.
Previously the core virt-v2v code had to know which Convert_* module
to call for each guest type (based on inspection). After this change
the core code doesn't need to know that, but instead Convert_* modules
register their interest in particular guest types.
---
v2v/convert_linux.ml | 13 +++++++++++--
v2v/convert_linux.mli | 2 --
v2v/convert_windows.ml | 9 ++++++++-
v2v/convert_windows.mli | 2 --
v2v/modules_list.ml | 17 +++++++++++++++++
v2v/modules_list.mli | 16 +++++++++++++++-
v2v/v2v.ml | 23 ++++++++++-------------
7 files changed, 61 insertions(+), 21 deletions(-)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index 1ef8ba5..baff68e 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -56,8 +56,7 @@ let string_of_kernel_info ki =
ki.ki_supports_virtio ki.ki_is_xen_kernel
(* The conversion function. *)
-let rec convert ~keep_serial_console verbose (g : G.guestfs)
- inspect source =
+let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
(*----------------------------------------------------------------------*)
(* Inspect the guest first. We already did some basic inspection in
* the common v2v.ml code, but that has to deal with generic guests
@@ -1242,3 +1241,13 @@ let rec convert ~keep_serial_console verbose (g : G.guestfs)
} in
guestcaps
+
+let () =
+ let matching = function
+ | { i_type = "linux";
+ i_distro = ("fedora"
+ | "rhel" | "centos" | "scientificlinux" | "redhat-based"
+ | "sles" | "suse-based" | "opensuse") } -> true
+ | _ -> false
+ in
+ Modules_list.register_convert_module matching "enterprise-linux" convert
diff --git a/v2v/convert_linux.mli b/v2v/convert_linux.mli
index 71c6435..d470281 100644
--- a/v2v/convert_linux.mli
+++ b/v2v/convert_linux.mli
@@ -15,5 +15,3 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-
-val convert : keep_serial_console:bool -> bool -> Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 563070a..9399770 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -41,7 +41,7 @@ module G = Guestfs
type ('a, 'b) maybe = Either of 'a | Or of 'b
-let convert verbose (g : G.guestfs) inspect source =
+let convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
(* Get the data directory. *)
let virt_tools_data_dir =
try Sys.getenv "VIRT_TOOLS_DATA_DIR"
@@ -477,3 +477,10 @@ echo uninstalling Xen PV driver
} in
guestcaps
+
+let () =
+ let matching = function
+ | { i_type = "windows" } -> true
+ | _ -> false
+ in
+ Modules_list.register_convert_module matching "windows" convert
diff --git a/v2v/convert_windows.mli b/v2v/convert_windows.mli
index 1ea07c4..d470281 100644
--- a/v2v/convert_windows.mli
+++ b/v2v/convert_windows.mli
@@ -15,5 +15,3 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-
-val convert : bool -> Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps
diff --git a/v2v/modules_list.ml b/v2v/modules_list.ml
index 7fedc77..18f5557 100644
--- a/v2v/modules_list.ml
+++ b/v2v/modules_list.ml
@@ -26,3 +26,20 @@ and register_output_module name =
let input_modules () = List.sort compare !input_modules
and output_modules () = List.sort compare !output_modules
+
+type conversion_fn =
+ verbose:bool -> keep_serial_console:bool ->
+ Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps
+
+let convert_modules = ref []
+
+let register_convert_module inspect_fn name conversion_fn =
+ convert_modules := (inspect_fn, (name, conversion_fn)) :: !convert_modules
+
+let find_convert_module inspect =
+ let rec loop = function
+ | [] -> raise Not_found
+ | (inspect_fn, ret) :: _ when inspect_fn inspect -> ret
+ | _ :: rest -> loop rest
+ in
+ loop !convert_modules
diff --git a/v2v/modules_list.mli b/v2v/modules_list.mli
index 805ba8d..4c41cc5 100644
--- a/v2v/modules_list.mli
+++ b/v2v/modules_list.mli
@@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-(** List of input and output modules. *)
+(** List of input, output and conversion modules. *)
val register_input_module : string -> unit
(** Register an input module by name. *)
@@ -29,3 +29,17 @@ val input_modules : unit -> string list
val output_modules : unit -> string list
(** Return the list of output modules. *)
+
+type conversion_fn =
+ verbose:bool -> keep_serial_console:bool ->
+ Guestfs.guestfs -> Types.inspect -> Types.source -> Types.guestcaps
+
+val register_convert_module : (Types.inspect -> bool) -> string -> conversion_fn -> unit
+(** [register_convert_module inspect_fn name fn] registers a
+ conversion function [fn] that can accept any guest that matches
+ the [inspect_fn] function. *)
+
+val find_convert_module : Types.inspect -> string * conversion_fn
+(** [find_convert_module inspect] returns the name and conversion
+ function for the guest with inspection data in [inspect], else
+ throws [Not_found]. *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 8138b53..cff5562 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -192,19 +192,16 @@ let rec main () =
msg (f_"Converting %s to run on KVM") prod
);
- match inspect.i_type, inspect.i_distro with
- | "linux", ("fedora"
- | "rhel" | "centos" | "scientificlinux" | "redhat-based"
- | "sles" | "suse-based" | "opensuse") ->
- (* RHEV doesn't support serial console so remove any on conversion. *)
- let keep_serial_console = output#keep_serial_console in
- Convert_linux.convert ~keep_serial_console verbose g inspect source
-
- | "windows", _ -> Convert_windows.convert verbose g inspect source
-
- | typ, distro ->
- error (f_"virt-v2v is unable to convert this guest type (%s/%s)")
- typ distro in
+ (* RHEV doesn't support serial console so remove any on conversion. *)
+ let keep_serial_console = output#keep_serial_console in
+
+ let conversion_name, convert =
+ try Modules_list.find_convert_module inspect
+ with Not_found ->
+ error (f_"virt-v2v is unable to convert this guest type (%s/%s)")
+ inspect.i_type inspect.i_distro in
+ if verbose then printf "picked conversion module %s\n%!" conversion_name;
+ convert ~verbose ~keep_serial_console g inspect source in
if do_copy then (
(* Doing fstrim on all the filesystems reduces the transfer size
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list