mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]. *)
|
||||
|
||||
21
v2v/v2v.ml
21
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
|
||||
(* RHEV doesn't support serial console so remove any on conversion. *)
|
||||
let keep_serial_console = output#keep_serial_console in
|
||||
|
||||
| "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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user