On Tue, Oct 20, 2015 at 04:08:13PM +0300, Roman Kagan wrote:
Factor out perfoming the actual convertion of the guest, which includes determinig the appropriate guest os specific conversion module and running its conversion routine.
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com> --- v2v/v2v.ml | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml index a2b6f52..633c29f 100644 --- a/v2v/v2v.ml +++ b/v2v/v2v.ml @@ -84,35 +84,8 @@ let rec main () = check_free_space mpstats; check_target_free_space mpstats source targets output;
- (* Conversion. *) - let guestcaps = - (match inspect.i_product_name with - | "unknown" -> - message (f_"Converting the guest to run on KVM") - | prod -> - message (f_"Converting %s to run on KVM") prod - ); - - (* 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; - let guestcaps = convert ~keep_serial_console g inspect source in - if verbose () then printf "%s%!" (string_of_guestcaps guestcaps); - guestcaps in - - (* Did we manage to install virtio drivers? *) - if not (quiet ()) then ( - if guestcaps.gcaps_block_bus = Virtio_blk then - info (f_"This guest has virtio drivers installed.") - else - info (f_"This guest does not have virtio drivers installed."); - ); + let keep_serial_console = output#keep_serial_console in + let guestcaps = do_convert g inspect source keep_serial_console in
g#umount_all ();
@@ -819,6 +792,34 @@ and check_target_free_space mpstats source targets output =
output#check_target_free_space source targets
+and do_convert g inspect source keep_serial_console = + (* Conversion. *) + (match inspect.i_product_name with + | "unknown" -> + message (f_"Converting the guest to run on KVM") + | prod -> + message (f_"Converting %s to run on KVM") prod + ); + + 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; + let guestcaps = convert ~keep_serial_console g inspect source in + if verbose () then printf "%s%!" (string_of_guestcaps guestcaps); + + (* Did we manage to install virtio drivers? *) + if not (quiet ()) then ( + if guestcaps.gcaps_block_bus = Virtio_blk then + info (f_"This guest has virtio drivers installed.") + else + info (f_"This guest does not have virtio drivers installed."); + ); + + guestcaps + (* Update the target_actual_size field in the target structure. *) and actual_target_size target = { target with target_actual_size = du target.target_file }
Straightforward refactoring, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org