v2v: Add --print-target to display overlay and target information.

This is analogous to --print-source, except that it prints the overlay
and target disk information.

The output looks like below.  Note there is one overlay and one target
section per disk.

Overlay and Target information (--print-target option):

             overlay file: /home/rjones/d/libguestfs/tmp/v2vovlc687fe.qcow2
      overlay device name: sda
overlay virtual disk size: 6442450944
  overlay source qemu URI: /var/tmp/fedora-27.img

          target file: [qemu] json:{ "file.driver": "nbd", "file.path": "/home/rjones/d/libguestfs/tmp/rhvupload.IWrzO6/nbdkit0.sock", "file.export": "/" }
        target format: raw
target estimated size: 2274060540
This commit is contained in:
Richard W.M. Jones
2018-03-15 17:12:47 +00:00
parent 777701a738
commit 9ac4f99fdc
5 changed files with 43 additions and 14 deletions

View File

@@ -44,6 +44,7 @@ type cmdline = {
output_format : string option;
output_name : string option;
print_source : bool;
print_target : bool;
root_choice : root_choice;
}
@@ -53,6 +54,7 @@ let parse_cmdline () =
let do_copy = ref true in
let machine_readable = ref false in
let print_source = ref false in
let print_target = ref false in
let qemu_boot = ref false in
let input_conn = ref None in
@@ -228,6 +230,8 @@ let parse_cmdline () =
s_"Use password from file";
[ L"print-source" ], Getopt.Set print_source,
s_"Print source and stop";
[ L"print-target" ], Getopt.Set print_target,
s_"Print target and stop";
[ L"qemu-boot" ], Getopt.Set qemu_boot, s_"Boot in qemu (-o qemu only)";
[ L"root" ], Getopt.String ("ask|... ", set_root_choice),
s_"How to choose root filesystem";
@@ -321,6 +325,7 @@ read the man page virt-v2v(1).
let output_storage = !output_storage in
let password_file = !password_file in
let print_source = !print_source in
let print_target = !print_target in
let qemu_boot = !qemu_boot in
let root_choice = !root_choice in
let vddk_options =
@@ -359,6 +364,12 @@ read the man page virt-v2v(1).
exit 0
);
(* Some options cannot be used with --in-place. *)
if in_place then (
if print_target then
error (f_"--in-place and --print-target cannot be used together")
);
(* Parse out the password from the password file. *)
let password =
match password_file with
@@ -579,6 +590,7 @@ read the man page virt-v2v(1).
do_copy = do_copy; in_place = in_place; network_map = network_map;
output_alloc = output_alloc; output_format = output_format;
output_name = output_name;
print_source = print_source; root_choice = root_choice;
print_source = print_source; print_target;
root_choice = root_choice;
},
input, output

View File

@@ -42,6 +42,7 @@ type cmdline = {
output_format : string option;
output_name : string option;
print_source : bool;
print_target : bool;
root_choice : Types.root_choice;
}

View File

@@ -281,11 +281,10 @@ type overlay = {
}
let string_of_overlay ov =
sprintf "\
ov_overlay_file = %s
ov_sd = %s
ov_virtual_size = %Ld
ov_source = %s
sprintf " overlay file: %s
overlay device name: %s
overlay virtual disk size: %Ld
overlay source qemu URI: %s
"
ov.ov_overlay_file
ov.ov_sd
@@ -304,12 +303,9 @@ and target_file =
| TargetURI of string
let string_of_target t =
sprintf "\
target_file = %s
target_format = %s
target_estimated_size = %s
target_overlay = %s
target_overlay.ov_source = %s
sprintf " target file: %s
target format: %s
target estimated size: %s
"
(match t.target_file with
| TargetFile s -> "[file] " ^ s
@@ -317,8 +313,6 @@ target_overlay.ov_source = %s
t.target_format
(match t.target_estimated_size with
| None -> "None" | Some i -> Int64.to_string i)
t.target_overlay.ov_overlay_file
t.target_overlay.ov_source.s_qemu_uri
type target_firmware = TargetBIOS | TargetUEFI

View File

@@ -150,6 +150,22 @@ let rec main () =
g#shutdown ();
g#close ();
(match conversion_mode with
| In_place -> ()
| Copying (overlays, targets) ->
(* Print overlays/targets and stop. *)
if cmdline.print_target then (
printf (f_"Overlay and Target information (--print-target option):\n");
printf "\n";
List.iter (
fun (ov, t) ->
printf "%s\n" (string_of_overlay ov);
printf "%s\n" (string_of_target t)
) (List.combine overlays targets);
exit 0
)
);
(* Copy overlays to target (for [--in-place] this does nothing). *)
(match conversion_mode with
| In_place -> ()
@@ -684,6 +700,7 @@ and copy_targets cmdline targets input output =
message (f_"Copying disk %d/%d to qemu URI %s (%s)")
(i+1) nr_disks s t.target_format
);
debug "%s" (string_of_overlay t.target_overlay);
debug "%s" (string_of_target t);
(* We noticed that qemu sometimes corrupts the qcow2 file on

View File

@@ -616,6 +616,11 @@ Print information about the source guest and stop. This option is
useful when you are setting up network and bridge maps.
See L</NETWORKS AND BRIDGES>.
=item B<--print-target>
Print information about the target disk(s) and overlay file(s), and
stop.
=item B<--qemu-boot>
When using I<-o qemu> only, this boots the guest immediately after