Richard W.M. Jones
2017-Dec-07 16:24 UTC
[Libguestfs] v2v: vddk: Switch to using ‘-it vddk’ to specify VDDK as input transport.
Proposed small change to the command line of virt-v2v when specifying that you want VDDK mode. Rich.
Richard W.M. Jones
2017-Dec-07 16:24 UTC
[Libguestfs] [PATCH] v2v: vddk: Switch to using ‘-it vddk’ to specify VDDK as input transport.
Previously the presence of the ‘--vddk <libdir>’ option magically enabled VDDK mode. However we want to introduce other transports for VMware conversions so this wasn't a very clean choice. With this commit you must use ‘-it vddk’ to specify that you want VDDK as a disk transport. The previous ‘--vddk <libdir>’ option has been renamed to ‘--vddk-libdir <libdir>’ to be consistent with the other passthrough options, and it is no longer required. A new command line looks like: $ export PATH=/path/to/nbdkit:$PATH $ virt-v2v \ -ic 'vpx://root@vcenter.example.com/Datacenter/esxi?no_verify=1' \ | -it vddk \ | --vddk-libdir /path/to/vmware-vix-disklib-distrib \ --vddk-thumbprint xx:xx:xx:... \ "Windows 2003" \ -o local -os /var/tmp where only the two lines marked with ‘|’ have changed. --- v2v/cmdline.ml | 66 ++++++++++++++++++++++++++++------------------- v2v/input_libvirt.ml | 37 ++++++++++++-------------- v2v/input_libvirt.mli | 8 +++--- v2v/input_libvirt_vddk.ml | 55 +++++++++++++++++++++++++-------------- v2v/test-v2v-docs.sh | 2 +- v2v/types.ml | 2 +- v2v/types.mli | 2 +- v2v/virt-v2v.pod | 30 +++++++++++++++------ 8 files changed, 122 insertions(+), 80 deletions(-) diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml index a452458a1..f25c0545d 100644 --- a/v2v/cmdline.ml +++ b/v2v/cmdline.ml @@ -57,15 +57,16 @@ let parse_cmdline () let input_conn = ref None in let input_format = ref None in + let input_transport = ref None in let in_place = ref false in let output_conn = ref None in let output_format = ref None in let output_name = ref None in let output_storage = ref None in let password_file = ref None in - let vddk = ref None in let vddk_config = ref None in let vddk_cookie = ref None in + let vddk_libdir = ref None in let vddk_nfchostport = ref None in let vddk_port = ref None in let vddk_snapshot = ref None in @@ -191,6 +192,8 @@ let parse_cmdline () s_"Libvirt URI"; [ M"if" ], Getopt.String ("format", set_string_option_once "-if" input_format), s_"Input format (for -i disk)"; + [ M"it" ], Getopt.String ("transport", set_string_option_once "-it" input_transport), + s_"Input transport"; [ L"in-place" ], Getopt.Set in_place, s_"Only tune the guest in the input VM"; [ L"machine-readable" ], Getopt.Set machine_readable, @@ -220,12 +223,12 @@ let parse_cmdline () [ 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"; - [ L"vddk" ], Getopt.String ("libpath", set_string_option_once "--vddk" vddk), - s_"Use nbdkit VDDK plugin"; [ L"vddk-config" ], Getopt.String ("filename", set_string_option_once "--vddk-config" vddk_config), s_"Set VDDK config file"; [ L"vddk-cookie" ], Getopt.String ("cookie", set_string_option_once "--vddk-cookie" vddk_cookie), s_"Set VDDK cookie"; + [ L"vddk-libdir" ], Getopt.String ("libdir", set_string_option_once "--vddk-libdir" vddk_libdir), + s_"Set VDDK library parent directory"; [ L"vddk-nfchostport" ], Getopt.String ("nfchostport", set_string_option_once "--vddk-nfchostport" vddk_nfchostport), s_"Set VDDK nfchostport"; [ L"vddk-port" ], Getopt.String ("port", set_string_option_once "--vddk-port" vddk_port), @@ -286,6 +289,7 @@ read the man page virt-v2v(1). let input_conn = !input_conn in let input_format = !input_format in let input_mode = !input_mode in + let input_transport = !input_transport in let in_place = !in_place in let machine_readable = !machine_readable in let network_map = !network_map in @@ -303,28 +307,15 @@ read the man page virt-v2v(1). let qemu_boot = !qemu_boot in let root_choice = !root_choice in let vddk_options - match !vddk with - | Some libdir -> - Some { vddk_libdir = libdir; - vddk_config = !vddk_config; - vddk_cookie = !vddk_cookie; - vddk_nfchostport = !vddk_nfchostport; - vddk_port = !vddk_port; - vddk_snapshot = !vddk_snapshot; - vddk_thumbprint = !vddk_thumbprint; - vddk_transports = !vddk_transports; - vddk_vimapiver = !vddk_vimapiver } - | None -> - if !vddk_config <> None || - !vddk_cookie <> None || - !vddk_nfchostport <> None || - !vddk_port <> None || - !vddk_snapshot <> None || - !vddk_thumbprint <> None || - !vddk_transports <> None || - !vddk_vimapiver <> None then - error (f_"‘--vddk-*’ options should only be used when conversion via the nbdkit VDDK plugin has been enabled, ie. using ‘--vddk’."); - None in + { vddk_config = !vddk_config; + vddk_cookie = !vddk_cookie; + vddk_libdir = !vddk_libdir; + vddk_nfchostport = !vddk_nfchostport; + vddk_port = !vddk_port; + vddk_snapshot = !vddk_snapshot; + vddk_thumbprint = !vddk_thumbprint; + vddk_transports = !vddk_transports; + vddk_vimapiver = !vddk_vimapiver } in let vdsm_compat = !vdsm_compat in let vdsm_image_uuids = List.rev !vdsm_image_uuids in let vdsm_vol_uuids = List.rev !vdsm_vol_uuids in @@ -357,6 +348,28 @@ read the man page virt-v2v(1). let password = read_first_line_from_file filename in Some password in + (* Input transport affects whether some parameters should or + * should not be used. + *) + (match input_transport with + | None -> + if !vddk_config <> None || + !vddk_cookie <> None || + !vddk_libdir <> None || + !vddk_nfchostport <> None || + !vddk_port <> None || + !vddk_snapshot <> None || + !vddk_thumbprint <> None || + !vddk_transports <> None || + !vddk_vimapiver <> None then + error (f_"‘--vddk-*’ options should only be used when conversion via the nbdkit VDDK plugin has been enabled, ie. using ‘-it vddk’.") + | Some "vddk" -> + if !vddk_thumbprint = None then + error (f_"‘--vddk-thumbprint’ is required when using ‘-it vddk’.") + | Some transport -> + error (f_"unknown input transport ‘-it %s’") transport + ); + (* Parsing of the argument(s) depends on the input mode. *) let input match input_mode with @@ -379,7 +392,8 @@ read the man page virt-v2v(1). | [guest] -> guest | _ -> error (f_"expecting a libvirt guest name on the command line") in - Input_libvirt.input_libvirt vddk_options password input_conn guest + Input_libvirt.input_libvirt vddk_options password + input_conn input_transport guest | `LibvirtXML -> (* -i libvirtxml: Expecting a filename (XML file). *) diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml index 59845c9b2..ec2e406d6 100644 --- a/v2v/input_libvirt.ml +++ b/v2v/input_libvirt.ml @@ -27,7 +27,7 @@ open Types open Utils (* Choose the right subclass based on the URI. *) -let input_libvirt vddk_options password libvirt_uri guest +let input_libvirt vddk_options password libvirt_uri input_transport guest match libvirt_uri with | None -> Input_libvirt_other.input_libvirt_other password libvirt_uri guest @@ -39,29 +39,26 @@ let input_libvirt vddk_options password libvirt_uri guest error (f_"could not parse '-ic %s'. Original error message was: %s") orig_uri msg in - match server, scheme with - | None, _ - | Some "", _ (* Not a remote URI. *) + match server, scheme, input_transport with + | None, _, _ + | Some "", _, _ (* Not a remote URI. *) - | Some _, None (* No scheme? *) - | Some _, Some "" -> + | Some _, None, _ (* No scheme? *) + | Some _, Some "", _ -> Input_libvirt_other.input_libvirt_other password libvirt_uri guest - (* vCenter over https, or - * vCenter or ESXi using nbdkit vddk plugin - *) - | Some server, Some ("esx"|"gsx"|"vpx") -> - (match vddk_options with - | None -> - Input_libvirt_vcenter_https.input_libvirt_vcenter_https - password libvirt_uri parsed_uri server guest - | Some vddk_options -> - Input_libvirt_vddk.input_libvirt_vddk vddk_options password - libvirt_uri parsed_uri guest - ) + (* vCenter over https. *) + | Some server, Some ("esx"|"gsx"|"vpx"), None -> + Input_libvirt_vcenter_https.input_libvirt_vcenter_https + password libvirt_uri parsed_uri server guest + + (* vCenter or ESXi using nbdkit vddk plugin *) + | Some server, Some ("esx"|"gsx"|"vpx"), Some "vddk" -> + Input_libvirt_vddk.input_libvirt_vddk vddk_options password + libvirt_uri parsed_uri guest (* Xen over SSH *) - | Some server, Some "xen+ssh" -> + | Some server, Some "xen+ssh", _ -> Input_libvirt_xen_ssh.input_libvirt_xen_ssh password libvirt_uri parsed_uri server guest @@ -71,7 +68,7 @@ let input_libvirt vddk_options password libvirt_uri guest *) (* Unknown remote scheme. *) - | Some _, Some _ -> + | Some _, Some _, _ -> warning (f_"no support for remote libvirt connections to '-ic %s'. The conversion may fail when it tries to read the source disks.") orig_uri; Input_libvirt_other.input_libvirt_other password libvirt_uri guest diff --git a/v2v/input_libvirt.mli b/v2v/input_libvirt.mli index acf2ca417..1f13ab330 100644 --- a/v2v/input_libvirt.mli +++ b/v2v/input_libvirt.mli @@ -18,7 +18,7 @@ (** [-i libvirt] source. *) -val input_libvirt : Types.vddk_options option -> string option -> string option -> string -> Types.input -(** [input_libvirt vddk_options password libvirt_uri guest] creates - and returns a new {!Types.input} object specialized for reading input - from libvirt sources. *) +val input_libvirt : Types.vddk_options -> string option -> string option -> string option -> string -> Types.input +(** [input_libvirt vddk_options password libvirt_uri input_transport guest] + creates and returns a new {!Types.input} object specialized for reading + input from libvirt sources. *) diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml index dfe1759b5..1e673f4c7 100644 --- a/v2v/input_libvirt_vddk.ml +++ b/v2v/input_libvirt_vddk.ml @@ -35,11 +35,16 @@ open Printf (* Subclass specialized for handling VMware via nbdkit vddk plugin. *) class input_libvirt_vddk vddk_options password libvirt_uri parsed_uri guest - (* The VDDK path. *) let libdir = vddk_options.vddk_libdir in - (* Compute the LD_LIBRARY_PATH that we must pass to nbdkit. *) - let library_path = libdir // sprintf "lib%d" Sys.word_size in + + (* VDDK libraries are located under lib32/ or lib64/ relative to the + * libdir. Note this is unrelated to Linux multilib or multiarch. + *) + let libNN = sprintf "lib%d" Sys.word_size in + + (* Compute the LD_LIBRARY_PATH that we may have to pass to nbdkit. *) + let library_path = Option.map (fun libdir -> libdir // libNN) libdir in (* Is SELinux enabled and enforcing on the host? *) let have_selinux @@ -47,18 +52,25 @@ class input_libvirt_vddk vddk_options password libvirt_uri parsed_uri guest (* Check that the VDDK path looks reasonable. *) let error_unless_vddk_libdir () - if not (is_directory libdir) then - error (f_"‘--vddk %s’ does not point to a directory. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") libdir; + (match libdir with + | None -> () + | Some libdir -> + if not (is_directory libdir) then + error (f_"‘--vddk-libdir %s’ does not point to a directory. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") libdir + ); - if not (is_directory library_path) then - error (f_"VDDK library path %s not found or not a directory. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") - library_path + (match library_path with + | None -> () + | Some library_path -> + if not (is_directory library_path) then + error (f_"VDDK library path %s not found or not a directory. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") library_path + ) in (* Check that nbdkit is available and new enough. *) let error_unless_nbdkit_working () if 0 <> Sys.command "nbdkit --version >/dev/null" then - error (f_"nbdkit is not installed or not working. It is required to use ‘--vddk’. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual."); + error (f_"nbdkit is not installed or not working. It is required to use ‘-it vddk’. See \"INPUT FROM VDDK\" in the virt-v2v(1) manual."); (* Check it's a new enough version. The latest features we * require are ‘--exit-with-parent’ and ‘--selinux-label’, both @@ -74,14 +86,20 @@ class input_libvirt_vddk vddk_options password libvirt_uri parsed_uri guest (* Check that the VDDK plugin is installed and working *) let error_unless_nbdkit_vddk_working () + let set_ld_library_path + match library_path with + | None -> "" + | Some library_path -> + sprintf "LD_LIBRARY_PATH=%s " (quote library_path) in + let cmd - sprintf "LD_LIBRARY_PATH=%s nbdkit vddk --dump-plugin >/dev/null" - (quote library_path) in + sprintf "%snbdkit vddk --dump-plugin >/dev/null" + set_ld_library_path in if Sys.command cmd <> 0 then ( (* See if we can diagnose why ... *) let cmd - sprintf "LD_LIBRARY_PATH=%s LANG=C nbdkit vddk --dump-plugin 2>&1 | grep -sq libvixDiskLib.so" - (quote library_path) in + sprintf "LANG=C %snbdkit vddk --dump-plugin 2>&1 | grep -sq libvixDiskLib.so" + set_ld_library_path in let needs_library = Sys.command cmd = 0 in if not needs_library then error (f_"nbdkit VDDK plugin is not installed or not working. It is required if you want to use VDDK. @@ -92,9 +110,9 @@ See also \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") else error (f_"nbdkit VDDK plugin is not installed or not working. It is required if you want to use VDDK. -It looks like you did not set the right path in the ‘--vddk’ option, or your copy of the VDDK directory is incomplete. There should be a library called ’%s/libvixDiskLib.so.?’. +It looks like you did not set the right path in the ‘--vddk-libdir’ option, or your copy of the VDDK directory is incomplete. There should be a library called ’<libdir>/%s/libvixDiskLib.so.?’. -See also \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") library_path +See also \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") libNN ) in @@ -121,6 +139,7 @@ See also \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") library_path let vddk_passthrus [ "config", (fun { vddk_config } -> vddk_config); "cookie", (fun { vddk_cookie } -> vddk_cookie); + "libdir", (fun { vddk_libdir } -> vddk_libdir); "nfchostport", (fun { vddk_nfchostport } -> vddk_nfchostport); "port", (fun { vddk_port } -> vddk_port); "snapshot", (fun { vddk_snapshot } -> vddk_snapshot); @@ -149,9 +168,8 @@ object | Some field -> sprintf " --vddk-%s %s" name field ) vddk_passthrus ) in - sprintf "%s --vddk %s%s" + sprintf "%s -it vddk %s" super#as_options (* superclass prints "-i libvirt etc" *) - vddk_options.vddk_libdir pt_options method source () @@ -252,7 +270,6 @@ object add_arg (sprintf "user=%s" user); add_arg password_param; add_arg (sprintf "vm=moref=%s" moref); - add_arg (sprintf "libdir=%s" libdir); (* The passthrough parameters. *) List.iter ( @@ -310,7 +327,7 @@ object let pid = fork () in if pid = 0 then ( (* Child process (nbdkit). *) - putenv "LD_LIBRARY_PATH" library_path; + Option.may (putenv "LD_LIBRARY_PATH") library_path; execvp "nbdkit" args ); diff --git a/v2v/test-v2v-docs.sh b/v2v/test-v2v-docs.sh index 8bd03f68e..5d034c465 100755 --- a/v2v/test-v2v-docs.sh +++ b/v2v/test-v2v-docs.sh @@ -22,4 +22,4 @@ $TEST_FUNCTIONS skip_if_skipped $top_srcdir/podcheck.pl virt-v2v.pod virt-v2v \ - --ignore=--debug-overlay,--ic,--if,--no-trim,--oa,--oc,--of,--on,--os,--vmtype + --ignore=--debug-overlay,--ic,--if,--it,--no-trim,--oa,--oc,--of,--on,--os,--vmtype diff --git a/v2v/types.ml b/v2v/types.ml index 490c049af..1ffb09440 100644 --- a/v2v/types.ml +++ b/v2v/types.ml @@ -475,9 +475,9 @@ type root_choice = AskRoot | SingleRoot | FirstRoot | RootDev of string type output_allocation = Sparse | Preallocated type vddk_options = { - vddk_libdir : string; vddk_config : string option; vddk_cookie : string option; + vddk_libdir : string option; vddk_nfchostport : string option; vddk_port : string option; vddk_snapshot : string option; diff --git a/v2v/types.mli b/v2v/types.mli index 2b73210ab..9e2f8ceb4 100644 --- a/v2v/types.mli +++ b/v2v/types.mli @@ -336,9 +336,9 @@ type output_allocation = Sparse | Preallocated (** Type of [-oa] (output allocation) option. *) type vddk_options = { - vddk_libdir : string; vddk_config : string option; vddk_cookie : string option; + vddk_libdir : string option; vddk_nfchostport : string option; vddk_port : string option; vddk_snapshot : string option; diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod index 4ac44988e..503830c9d 100644 --- a/v2v/virt-v2v.pod +++ b/v2v/virt-v2v.pod @@ -379,6 +379,13 @@ See L</IN PLACE CONVERSION> below. Conflicts with all I<-o *> options. +=item B<-it> B<vddk> + +Use VMware VDDK as a transport to copy the input disks. See +L</INPUT FROM VDDK> below. If you use this parameter then you may +need to use other I<--vddk*> options to specify how to connect through +VDDK. + =item B<--keys-from-stdin> Read key or passphrase parameters from stdin. The default is @@ -633,13 +640,20 @@ boot an operating system from the first virtio disk. Specifically, F</boot> must be on the first virtio disk, and it cannot chainload an OS which is not in the first virtio disk. -=item B<--vddk> LIBDIR +=item B<--vddk-libdir> LIBDIR -Enable VDDK input from VMware vCenter or ESXi. C<LIBDIR> is the top -directory of the VDDK library. This directory should I<contain> +Set the VDDK library directory. This directory should I<contain> subdirectories called F<include>, F<lib64> etc., but do not include F<lib64> actually in the parameter. +In most cases this parameter is required when using the I<-it vddk> +(VDDK) transport. See L</INPUT FROM VDDK> below for details. + +=item B<--vddk-thumbprint> xx:xx:xx:... + +Set the thumbprint of the remote VMware server. + +This parameter is required when using the I<-it vddk> (VDDK) transport. See L</INPUT FROM VDDK> below for details. =item B<--vddk-config> FILENAME @@ -652,16 +666,13 @@ See L</INPUT FROM VDDK> below for details. =item B<--vddk-snapshot> SNAPSHOT-MOREF -=item B<--vddk-thumbprint> xx:xx:xx:... - =item B<--vddk-transports> MODE:MODE:... =item B<--vddk-vimapiver> APIVER When using VDDK mode, these options are passed unmodified to the L<nbdkit(1)> VDDK plugin. Please refer to L<nbdkit-vddk-plugin(1)>. -If I<--vddk> is present, I<--vddk-thumbprint> is also required, -the rest are optional. +These are all optional. =item B<--vdsm-compat=0.10> @@ -1543,6 +1554,8 @@ continuing. =head2 VDDK: IMPORTING A GUEST +The I<-it vddk> parameter selects VDDK as the input transport for disks. + To import a particular guest from vCenter server or ESXi hypervisor, use a command like the following, substituting the URI, guest name and SSL thumbprint: @@ -1550,7 +1563,8 @@ SSL thumbprint: $ export PATH=/path/to/nbdkit:$PATH $ virt-v2v \ -ic 'vpx://root@vcenter.example.com/Datacenter/esxi?no_verify=1' \ - --vddk /path/to/vmware-vix-disklib-distrib \ + -it vddk \ + --vddk-libdir /path/to/vmware-vix-disklib-distrib \ --vddk-thumbprint xx:xx:xx:... \ "Windows 2003" \ -o local -os /var/tmp -- 2.13.2
Seemingly Similar Threads
- [PATCH INCOMPLETE 0/4] v2v: Add general mechanism for input and output options.
- [PATCH v2 0/2] v2v: Add -it vddk and -it ssh flags.
- [PATCH v7 0/6] v2v: Add -o rhv-upload output mode (RHBZ#1557273).
- [PATCH] v2v: vddk: Print passthrough options.
- [PATCH v2 1/2] v2v: vddk: Switch to using ‘-it vddk’ to specify VDDK as input transport.