[Pkg-libvirt-commits] [libguestfs] 144/266: v2v: Add --print-source option.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:53 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.35-1
in repository libguestfs.

commit 3a6dc32342cd6a545d66e9b773bab8450f533fa5
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Aug 21 10:21:19 2014 +0100

    v2v: Add --print-source option.
---
 v2v/Makefile.am              |  1 +
 v2v/cmdline.ml               |  7 +++--
 v2v/test-v2v-print-source.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++
 v2v/types.ml                 | 44 +++++++++++++++--------------
 v2v/v2v.ml                   | 10 ++++++-
 v2v/virt-v2v.pod             | 51 +++++++++++++++++++++++++++++++++
 6 files changed, 156 insertions(+), 24 deletions(-)

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 94801d1..c4ed313 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -187,6 +187,7 @@ TESTS = \
 	test-v2v-o-rhev-options.sh \
 	test-v2v-of-option.sh \
 	test-v2v-on-option.sh \
+	test-v2v-print-source.sh \
 	test-v2v-windows-conversion.sh
 endif ENABLE_APPLIANCE
 
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 70b1209..c2d586a 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -36,11 +36,12 @@ let parse_cmdline () =
   let do_copy = ref true in
   let input_conn = ref "" in
   let input_format = ref "" in
+  let machine_readable = ref false in
   let output_conn = ref "" in
   let output_format = ref "" in
   let output_name = ref "" in
   let output_storage = ref "" in
-  let machine_readable = ref false in
+  let print_source = ref false in
   let quiet = ref false in
   let rhev_image_uuid = ref "" in
   let rhev_vm_uuid = ref "" in
@@ -118,6 +119,7 @@ let parse_cmdline () =
     "-of",       Arg.Set_string output_format, "raw|qcow2 " ^ s_"Set output format";
     "-on",       Arg.Set_string output_name, "name " ^ s_"Rename guest when converting";
     "-os",       Arg.Set_string output_storage, "storage " ^ s_"Set output storage location";
+    "--print-source", Arg.Set print_source, " " ^ s_"Print source and stop";
     "-q",        Arg.Set quiet,             " " ^ s_"Quiet output";
     "--quiet",   Arg.Set quiet,             ditto;
     "--rhev-image-uuid",
@@ -174,6 +176,7 @@ read the man page virt-v2v(1).
   let output_mode = !output_mode in
   let output_name = match !output_name with "" -> None | s -> Some s in
   let output_storage = !output_storage in
+  let print_source = !print_source in
   let quiet = !quiet in
   let rhev_image_uuid = match !rhev_image_uuid with "" -> None | s -> Some s in
   let rhev_vol_uuids = List.rev !rhev_vol_uuids in
@@ -266,4 +269,4 @@ read the man page virt-v2v(1).
   input, output,
   debug_gc, do_copy, network_map,
   output_alloc, output_format, output_name,
-  quiet, root_choice, trace, verbose
+  print_source, quiet, root_choice, trace, verbose
diff --git a/v2v/test-v2v-print-source.sh b/v2v/test-v2v-print-source.sh
new file mode 100755
index 0000000..39119a0
--- /dev/null
+++ b/v2v/test-v2v-print-source.sh
@@ -0,0 +1,67 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test --print-source option.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_PRINT_SOURCE_SH" ]; then
+    echo "$0: test skipped because environment variable is set"
+    exit 77
+fi
+
+abs_top_builddir="$(cd ..; pwd)"
+libvirt_uri="test://$abs_top_builddir/tests/guests/guests-all-good.xml"
+
+f=../tests/guests/windows.img
+if ! test -f $f || ! test -s $f; then
+    echo "$0: test skipped because phony Windows image was not created"
+    exit 77
+fi
+
+d=test-v2v-print-source.d
+rm -rf $d
+mkdir $d
+
+$VG ./virt-v2v --debug-gc \
+    -i libvirt -ic "$libvirt_uri" windows \
+    -o local -os $d \
+    --print-source > $d/output
+
+if [ "$(cat $d/output)" != "Source guest information (--print-source option):
+
+    source name: windows
+hypervisor type: test
+         memory: 1073741824 (bytes)
+       nr vCPUs: 1
+           arch: i686
+   CPU features: 
+        display: 
+disks:
+	/home/rjones/d/libguestfs/tests/guests/windows.img (raw) [vda]
+removable media:
+
+NICs:" ]; then
+    echo "$0: unexpected output from test:"
+    cat $d/output
+    exit 1
+fi
+
+rm -r $d
diff --git a/v2v/types.ml b/v2v/types.ml
index 582fb2f..ffc99ce 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -92,20 +92,22 @@ and source_display = {
 }
 
 let rec string_of_source s =
-  sprintf "\
-s_dom_type = %s
-s_name = %s
-s_memory = %Ld
-s_vcpu = %d
-s_arch = %s
-s_features = [%s]
-s_display = %s
-s_disks = [%s]
-s_removables = [%s]
-s_nics = [%s]
+  sprintf "    source name: %s
+hypervisor type: %s
+         memory: %Ld (bytes)
+       nr vCPUs: %d
+           arch: %s
+   CPU features: %s
+        display: %s
+disks:
+%s
+removable media:
+%s
+NICs:
+%s
 "
-    s.s_dom_type
     s.s_name
+    s.s_dom_type
     s.s_memory
     s.s_vcpu
     s.s_arch
@@ -113,13 +115,13 @@ s_nics = [%s]
     (match s.s_display with
     | None -> ""
     | Some display -> string_of_source_display display)
-    (String.concat "," (List.map string_of_source_disk s.s_disks))
-    (String.concat "," (List.map string_of_source_removable s.s_removables))
-    (String.concat "," (List.map string_of_source_nic s.s_nics))
+    (String.concat "\n" (List.map string_of_source_disk s.s_disks))
+    (String.concat "\n" (List.map string_of_source_removable s.s_removables))
+    (String.concat "\n" (List.map string_of_source_nic s.s_nics))
 
 and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
                             s_target_dev = target_dev } =
-  sprintf "%s%s%s"
+  sprintf "\t%s%s%s"
     qemu_uri
     (match format with
     | None -> ""
@@ -130,19 +132,19 @@ and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
 
 and string_of_source_removable { s_removable_type = typ;
                                  s_removable_target_dev = target_dev } =
-  sprintf "%s%s"
-    (match typ with `CDROM -> "cdrom" | `Floppy -> "floppy")
+  sprintf "\t%s%s"
+    (match typ with `CDROM -> "CD-ROM" | `Floppy -> "Floppy")
     (match target_dev with
     | None -> ""
     | Some target_dev -> " [" ^ target_dev ^ "]")
 
 and string_of_source_nic { s_mac = mac; s_vnet = vnet; s_vnet_type = typ } =
-  sprintf "%s%s%s"
-    (match typ with Bridge -> "bridge" | Network -> "network")
+  sprintf "\t%s \"%s\"%s"
+    (match typ with Bridge -> "Bridge" | Network -> "Network")
     vnet
     (match mac with
     | None -> ""
-    | Some mac -> " " ^ mac)
+    | Some mac -> " mac: " ^ mac)
 
 and string_of_source_display { s_display_type = typ;
                                s_keymap = keymap; s_password = password } =
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 3339c7b..63bc162 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -34,7 +34,7 @@ let rec main () =
   let input, output,
     debug_gc, do_copy, network_map,
     output_alloc, output_format, output_name,
-    quiet, root_choice, trace, verbose =
+    print_source, quiet, root_choice, trace, verbose =
     Cmdline.parse_cmdline () in
 
   let msg fs = make_message_function ~quiet fs in
@@ -48,6 +48,14 @@ let rec main () =
     | InputLibvirtXML filename ->
       Source_libvirt.create_from_xml filename in
 
+  (* Print source and stop. *)
+  if print_source then (
+    printf (f_"Source guest information (--print-source option):\n");
+    printf "\n";
+    printf "%s\n" (string_of_source source);
+    exit 0
+  );
+
   if verbose then printf "%s%!" (string_of_source source);
 
   (* Map source name. *)
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 2a26113..fe26c61 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -193,6 +193,8 @@ Map network (or bridge) called C<in> to network (or bridge) called
 C<out>.  If no C<in:> prefix is given, all other networks (or bridges)
 are mapped to C<out>.
 
+See L</NETWORKS AND BRIDGES> below.
+
 =item B<--no-copy>
 
 Don't copy the disks.  Instead, conversion is performed (and thrown
@@ -293,6 +295,12 @@ C<root>.
 You will get an error if virt-v2v is unable to mount/write to the
 Export Storage Domain.
 
+=item B<--print-source>
+
+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<-q>
 
 =item B<--quiet>
@@ -479,6 +487,49 @@ below.
  Windows        Drivers are installed from /usr/share/virtio-win
                 if present
 
+=head1 NETWORKS AND BRIDGES
+
+Guests are usually connected to one or more networks, and when
+converted to the target hypervisor you usually want to reconnect those
+networks at the destination.  The options I<--network> and I<--bridge>
+allow you to do that.
+
+If you are unsure of what networks and bridges are in use on the
+source hypervisor, then you can examine the source metadata (libvirt
+XML, vCenter information, etc.).  Or you can run virt-v2v with the
+I<--print-source> option which causes virt-v2v to print out the
+information it has about the guest on the source and then exit.
+
+In the I<--print-source> output you will see a section showing the
+guest's Network Interface Cards (NICs):
+
+ $ virt-v2v [-i ...] --print-source name
+ [...]
+ NICs:
+     Network "default" mac: 52:54:00:d0:cf:0e
+
+This is typical of a libvirt guest: It has a single network interface
+connected to a network called C<default>.
+
+To map a specific network to a target network, for example C<default>
+on the source to C<rhevm> on the target, use:
+
+ virt-v2v [...] --network default:rhevm
+
+To map every network to a target network, use:
+
+ virt-v2v [...] --network rhevm
+
+Bridges are handled in the same way, but you have to use the
+I<--bridge> option instead.  For example:
+
+ $ virt-v2v [-i ...] --print-source name
+ [...]
+ NICs:
+     Bridge "br0"
+ 
+ $ virt-v2v [...] --bridge br0:targetbr
+
 =head1 MACHINE READABLE OUTPUT
 
 The I<--machine-readable> option can be used to make the output more

-- 
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