[Pkg-libvirt-commits] [libguestfs] 117/266: v2v: Add new -i disk to allow direct import of disk images with no metadata.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:49 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 7c7caae7c1872c317712c373217362172a46abd6
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Aug 15 18:07:02 2014 +0100

    v2v: Add new -i disk to allow direct import of disk images with no metadata.
    
    This is simpler to use and more convenient than -i libvirtxml, because
    users don't need to bother with writing libvirt XML.  However it is
    less expressive because many source capabilities such as memory and
    number of vCPUs cannot be specified this way.
---
 mllib/config.ml.in                        |  1 +
 po/POTFILES-ml                            |  1 +
 v2v/Makefile.am                           |  3 ++
 v2v/cmdline.ml                            | 19 ++++++++-
 v2v/source_disk.ml                        | 69 +++++++++++++++++++++++++++++++
 mllib/config.ml.in => v2v/source_disk.mli | 13 +++---
 v2v/test-v2v-i-disk.sh                    | 59 ++++++++++++++++++++++++++
 v2v/types.ml                              |  1 +
 v2v/types.mli                             |  1 +
 v2v/v2v.ml                                |  2 +
 v2v/virt-v2v.pod                          | 18 ++++++++
 11 files changed, 179 insertions(+), 8 deletions(-)

diff --git a/mllib/config.ml.in b/mllib/config.ml.in
index b1c4a49..793a35a 100644
--- a/mllib/config.ml.in
+++ b/mllib/config.ml.in
@@ -21,3 +21,4 @@ let package_name = "@PACKAGE_NAME@"
 let package_version = "@PACKAGE_VERSION@"
 let prefix = "@prefix@"
 let datadir = prefix ^ "/share"
+let host_cpu = "@host_cpu@"
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 4111d63..aeaac76 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -87,6 +87,7 @@ v2v/cmdline.ml
 v2v/convert_linux.ml
 v2v/convert_windows.ml
 v2v/lib_linux.ml
+v2v/source_disk.ml
 v2v/source_libvirt.ml
 v2v/stringMap.ml
 v2v/target_RHEV.ml
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index e916dc2..0f43951 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -29,6 +29,7 @@ SOURCES_MLI = \
 	convert_windows.mli \
 	DOM.mli \
 	lib_linux.mli \
+	source_disk.mli \
 	source_libvirt.mli \
 	target_libvirt.mli \
 	target_local.mli \
@@ -44,6 +45,7 @@ SOURCES_ML = \
 	DOM.ml \
 	lib_linux.ml \
 	cmdline.ml \
+	source_disk.ml \
 	source_libvirt.ml \
 	convert_linux.ml \
 	convert_windows.ml \
@@ -175,6 +177,7 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
 
 if ENABLE_APPLIANCE
 TESTS = \
+	test-v2v-i-disk.sh \
 	test-v2v-machine-readable.sh \
 	test-v2v-no-copy.sh \
 	test-v2v-o-libvirt.sh \
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index ea2c70c..c94cd60 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -35,6 +35,7 @@ let parse_cmdline () =
   let debug_gc = ref false in
   let do_copy = ref true in
   let input_conn = ref "" in
+  let input_format = ref "" in
   let output_conn = ref "" in
   let output_format = ref "" in
   let output_name = ref "" in
@@ -49,6 +50,7 @@ let parse_cmdline () =
 
   let input_mode = ref `Libvirt in
   let set_input_mode = function
+    | "disk" -> input_mode := `Disk
     | "libvirt" -> input_mode := `Libvirt
     | "libvirtxml" -> input_mode := `LibvirtXML
     | s ->
@@ -88,8 +90,10 @@ let parse_cmdline () =
   let ditto = " -\"-" in
   let argspec = Arg.align [
     "--debug-gc",Arg.Set debug_gc,          " " ^ s_"Debug GC and memory allocations";
-    "-i",        Arg.String set_input_mode, "libvirtxml|libvirt " ^ s_"Set input mode (default: libvirt)";
+    "-i",        Arg.String set_input_mode, "disk|libvirt|libvirtxml " ^ s_"Set input mode (default: libvirt)";
     "-ic",       Arg.Set_string input_conn, "uri " ^ s_"Libvirt URI";
+    "-if",       Arg.Set_string input_format,
+                                            "format " ^ s_"Input format (for -i disk)";
     "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
     "--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
     "--no-copy", Arg.Clear do_copy,         " " ^ s_"Just write the metadata";
@@ -129,6 +133,8 @@ let parse_cmdline () =
 
  virt-v2v -i libvirtxml -o local -os /tmp guest-domain.xml
 
+ virt-v2v -i disk -o local -os /tmp disk.img
+
 There is a companion front-end called \"virt-p2v\" which comes as an
 ISO or CD image that can be booted on physical machines.
 
@@ -143,6 +149,7 @@ read the man page virt-v2v(1).
   let debug_gc = !debug_gc in
   let do_copy = !do_copy in
   let input_conn = match !input_conn with "" -> None | s -> Some s in
+  let input_format = match !input_format with "" -> None | s -> Some s in
   let input_mode = !input_mode in
   let machine_readable = !machine_readable in
   let output_alloc = !output_alloc in
@@ -178,6 +185,15 @@ read the man page virt-v2v(1).
   (* Parsing of the argument(s) depends on the input mode. *)
   let input =
     match input_mode with
+    | `Disk ->
+      (* -i disk: Expecting a single argument, the disk filename. *)
+      let disk =
+        match args with
+        | [disk] -> disk
+        | _ ->
+          error (f_"expecting a disk image (filename) on the command line") in
+      InputDisk (input_format, disk)
+
     | `Libvirt ->
       (* -i libvirt: Expecting a single argument which is the name
        * of the libvirt guest.
@@ -188,6 +204,7 @@ read the man page virt-v2v(1).
         | _ ->
           error (f_"expecting a libvirt guest name on the command line") in
       InputLibvirt (input_conn, guest)
+
     | `LibvirtXML ->
       (* -i libvirtxml: Expecting a filename (XML file). *)
       let filename =
diff --git a/v2v/source_disk.ml b/v2v/source_disk.ml
new file mode 100644
index 0000000..28723c0
--- /dev/null
+++ b/v2v/source_disk.ml
@@ -0,0 +1,69 @@
+(* virt-v2v
+ * Copyright (C) 2009-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.
+ *)
+
+open Printf
+
+open Common_gettext.Gettext
+open Common_utils
+
+open Types
+open Utils
+
+let create input_format disk =
+  (* What name should we use for the guest?  We try to derive it from
+   * the filename passed in.  Users can override this using the
+   * `-on name' option.
+   *)
+  let name = Filename.chop_extension (Filename.basename disk) in
+  if name = "" then
+    error (f_"-i disk: invalid input filename (%s)") disk;
+
+  (* Get the absolute path to the disk file. *)
+  let disk_absolute =
+    if not (Filename.is_relative disk) then disk
+    else Sys.getcwd () // disk in
+
+  (* The rest of virt-v2v doesn't actually work unless we detect
+   * the format of the input, so:
+   *)
+  let format =
+    match input_format with
+    | Some format -> format
+    | None ->
+      match (new Guestfs.guestfs ())#disk_format disk with
+      | "unknown" ->
+        error (f_"cannot detect the input disk format; use the -if parameter")
+      | format -> format in
+
+  let disk = {
+    s_qemu_uri = disk_absolute;
+    s_format = Some format;
+    s_target_dev = None;
+  } in
+
+  let source = {
+    s_dom_type = "kvm";
+    s_name = name;
+    s_memory = 2048L *^ 1024L *^ 1024L; (* 2048 MB *)
+    s_vcpu = 1;                         (* 1 vCPU is a safe default *)
+    s_arch = Config.host_cpu;
+    s_features = [ "acpi"; "apic"; "pae" ];
+    s_disks = [disk];
+  } in
+
+  source
diff --git a/mllib/config.ml.in b/v2v/source_disk.mli
similarity index 76%
copy from mllib/config.ml.in
copy to v2v/source_disk.mli
index b1c4a49..30b3cfd 100644
--- a/mllib/config.ml.in
+++ b/v2v/source_disk.mli
@@ -1,6 +1,5 @@
-(* configuration for mllib.
- * @configure_input@
- * Copyright (C) 2013 Red Hat Inc.
+(* virt-v2v
+ * Copyright (C) 2009-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
@@ -17,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-let package_name = "@PACKAGE_NAME@"
-let package_version = "@PACKAGE_VERSION@"
-let prefix = "@prefix@"
-let datadir = prefix ^ "/share"
+(** [-i disk] source. *)
+
+val create : string option -> string -> Types.source
+(** [create input_format disk] reads the disk image and returns a {!Types.source}. *)
diff --git a/v2v/test-v2v-i-disk.sh b/v2v/test-v2v-i-disk.sh
new file mode 100755
index 0000000..dbf6f94
--- /dev/null
+++ b/v2v/test-v2v-i-disk.sh
@@ -0,0 +1,59 @@
+#!/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 -i disk option.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_I_DISK_SH" ]; then
+    echo "$0: test skipped because environment variable is set"
+    exit 77
+fi
+
+if [ "$(../fish/guestfish get-backend)" = "uml" ]; then
+    echo "$0: test skipped because UML backend does not support network"
+    exit 77
+fi
+
+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
+
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
+    echo "$0: test skipped because rhsrvany.exe is not installed"
+    exit 77
+fi
+
+d=test-v2v-i-disk.d
+rm -rf $d
+mkdir $d
+
+$VG ./virt-v2v --debug-gc \
+    -i disk $f \
+    -o local -os $d
+
+# Test the libvirt XML metadata and a disk was created.
+test -f $d/windows.xml
+test -f $d/windows-sda
+
+rm -r $d
diff --git a/v2v/types.ml b/v2v/types.ml
index 4ccddd6..fb4491e 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -21,6 +21,7 @@ open Printf
 (* Types.  See types.mli for documentation. *)
 
 type input =
+| InputDisk of string option * string
 | InputLibvirt of string option * string
 | InputLibvirtXML of string
 
diff --git a/v2v/types.mli b/v2v/types.mli
index 329bf6f..aac2952 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -19,6 +19,7 @@
 (** Types. *)
 
 type input =
+| InputDisk of string option * string   (* -i disk: format + file name *)
 | InputLibvirt of string option * string (* -i libvirt: -ic + guest name *)
 | InputLibvirtXML of string         (* -i libvirtxml: XML file name *)
 (** The input arguments as specified on the command line. *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 27c6270..8aa6c15 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -40,6 +40,8 @@ let rec main () =
 
   let source =
     match input with
+    | InputDisk (input_format, disk) ->
+      Source_disk.create input_format disk
     | InputLibvirt (libvirt_uri, guest) ->
       Source_libvirt.create libvirt_uri guest
     | InputLibvirtXML filename ->
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index ae5502d..e4a484f 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -11,6 +11,8 @@ virt-v2v - Convert a guest to use KVM
 
  virt-v2v -i libvirtxml -o local -os /tmp guest-domain.xml
 
+ virt-v2v -i disk -o local -os /tmp disk.img
+
 =head1 DESCRIPTION
 
 Virt-v2v converts guests from a foreign hypervisor to run on KVM,
@@ -38,6 +40,16 @@ Debug garbage collection and memory allocation.  This is only useful
 when debugging memory problems in virt-v2v or the OCaml libguestfs
 bindings.
 
+=item B<-i disk>
+
+Set the input method to I<disk>.
+
+In this mode you can read a virtual machine disk image with no
+metadata.  virt-v2v tries to guess the best default metadata.  This is
+usually adequate but you can get finer control (eg. of memory and
+vCPUs) by using I<-libvirtxml> instead.  Only guests that use a single
+disk can be imported this way.
+
 =item B<-i libvirt>
 
 Set the input method to I<libvirt>.  This is the default.
@@ -62,6 +74,12 @@ is only used when S<I<-i libvirt>>.
 Only local libvirt connections and ESX connections can be used.
 Remote libvirt connections will not work in general.
 
+=item B<-if> format
+
+For I<-i disk> only, this specifies the format of the input disk
+image.  For other input methods you should specify the input
+format in the metadata.
+
 =item B<--machine-readable>
 
 This option is used to make the output more machine friendly

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