Commit Graph

41 Commits

Author SHA1 Message Date
Richard W.M. Jones
05d4fcb64d Update copyright dates for 2019.
This command run over the source:

perl -pi.bak -e 's/(20[01][0-9])-2018/$1-2019/g' `git ls-files`
2019-01-08 11:58:30 +00:00
Richard W.M. Jones
24404a5dec v2v: Refactor order of parameters to input objects.
Simple refactoring of the order of parameters to input objects
so they are always in the order:

  input_foo          ; class name
    input_conn       ; command line -iX parameters, alphabetically
    input_password   ;
    ...              ;
    vddk_options     ; extra class parameters
    ...              ;
    guestname        ; remaining command line parameters
2018-06-12 10:29:17 +01:00
Richard W.M. Jones
f49c5d14dd v2v: Use -ip to pass input password (instead of --password-file).
Consistent with the option -op added in
commit a4e181137a, use -ip to pass
passwords for the input side.

This replaces --password-file, and like that option you have to pass a
filename.

This also changes the code so we pass around the filename instead of
the password between functions.  For ‘-it vddk’ this simplifies
things: we can pass the filename through to nbdkit and we never need
to read it in virt-v2v.  For other input methods we eventually need to
read the password from the file at some lower level place in the code.
2018-06-12 10:29:16 +01:00
Richard W.M. Jones
212762c593 Update copyright dates for 2018.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2017/$1-2018/g' `git ls-files`
2018-01-04 15:30:10 +00:00
Richard W.M. Jones
eecf41956d v2v: Remove unused ‘scheme’ parameter.
It wasn't actually used for anything significant.  Even worse
virt-v2v-copy-to-local made up a scheme out of thin air.

Just code refactoring, no functional change.
2017-12-07 10:53:31 +00:00
Richard W.M. Jones
f87f254b2b v2v: In input and output classes move checks to new precheck () method.
Previously we were abusing the ‘input#source ()’ and
‘output#prepare_targets’ methods to perform environmental checks.

Small refactoring, no functional change.
2017-10-17 11:31:50 +01:00
Richard W.M. Jones
fb79fcde29 v2v: vCenter: Refactor the API to this module.
This module had a selection of functions taking a different mix of
parameters and doing slightly different things.  You could call one
function to return an https://... URL, or another function to return a
qemu URL, and there was a third function to get the session cookie but
you generally had to call that anyway (and it was implicitly called
when making the qemu URL!)

Integrate these into a single function which returns a struct
returning all possible values.

This is conceptually refactoring, except that the session cookie is no
longer memoized, but we didn't use this feature (of calling
get_session_cookie multiple times) anyway.
2017-10-16 17:08:54 +01:00
Richard W.M. Jones
3fdd923ce2 v2v: Remove --dcpath parameter and related functionality.
With modern libvirt, when fetching the XML of a VMware guest libvirt
passes us the datacenter path (dcpath).  However with older libvirt we
had to guess this value, or else the user had to supply it on the
command line.

This commit removes all the guessing code and the --dcpath parameter
(which will now give an error).

This requires libvirt >= 1.2.20 for virt-v2v, released Oct 2015.
2017-10-16 17:08:54 +01:00
Richard W.M. Jones
cd304ad838 common/mltools: Rename Common_utils to Tools_utils.
Reflecting the purpose of this module now, which is to act as a place
for utility functions shared only by the OCaml virt tools.
2017-09-28 14:39:23 +01:00
Richard W.M. Jones
512e5fd858 v2v: Move libvirt XML parsing code into a new module.
Just code motion.
2017-02-25 12:57:49 +00:00
Richard W.M. Jones
ad9e9c98b5 v2v: Rename Domainxml -> Libvirt_utils.
The name 'Domainxml' made no sense.
2017-02-24 09:05:30 +00:00
Richard W.M. Jones
24d2150047 v2v: vCenter: Remove proxy environment variables (RHBZ#1354507).
Currently imports from vCenter sometimes obey proxy environment
variables (eg. $http_proxy) and sometimes don't.  The initial libvirt
connection to fetch metadata never uses the proxy, but because the
subsequent conversion and copying uses libcurl, it will pick up on
proxy environment variables.

This makes no sense, and in any case vCenter is really slow as it is
without putting another device into the data path.  Therefore ensure
that libcurl does not see any proxy environment variables by unsetting
them.
2017-02-22 15:28:40 +00:00
Pino Toscano
55bf7de97c Update copyright dates for 2017
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2016/$1-2017/g' `git ls-files`

(Thanks Rich for the perl snippet, as used in past years.)
2017-01-03 16:48:21 +01:00
Richard W.M. Jones
b7a8247b5a v2v: Move xpath* functions to new module Xpath_helpers.
Just code motion.
2016-09-09 16:09:39 +01:00
Richard W.M. Jones
ecbf093850 v2v: Allow libvirt >= 2.1.0 to be used for Xen and vCenter conversions.
Libvirt >= 2.1.0 now allows you to open files which have a "json:"
QEMU pseudo-URL as backingfile, whereas previously it would fail hard
in this case (RHBZ#1134878).

When virt-v2v performs conversions from Xen (over SSH) or vCenter
(over HTTPS) it uses these pseudo-URLs as backingfiles.  We had to
tell people to use LIBGUESTFS_BACKEND=direct to avoid libvirt in this
situation.

This commit narrows the check so it will now only print the error if
libvirt < 2.1.0 and LIBGUESTFS_BACKEND=direct is not set.  Also the
error is modified to tell users they can either upgrade libvirt or set
LIBGUESTFS_BACKEND=direct to work around the problem.

Note there is not an easy way apart from checking the version number
of libvirt to tell if the json pseudo-URL is supported.

As a side-effect, this commit also prints the libvirt version number
in debugging output when virt-v2v starts up, which is sometimes useful
information for narrowing down bugs (it is in fact already printed by
libguestfs, so this is duplicate information, but it's a bit easier to
find when it's at the top of the debug).

Thanks: Peter Krempa.
2016-08-25 09:02:01 +01:00
Pino Toscano
c605765c95 mllib: add a new run_command helper
Add a simple helper to run a command from a sequence of arguments,
without using a shell: this should help reducing the amount of quoting
ineeded, since arguments are passed straight as such.

Make use of it in the places currently using shell_command, and which
don't assume they can run anything (so no shell redirections, `env`,
etc).
2016-05-24 11:26:48 +02:00
Pino Toscano
a52ee88f88 mllib: add an helper shell_command
Add a simple shell_command, which is mostly a wrapper around
Sys.command but with logging of the command run.
2016-05-24 11:10:42 +02:00
Richard W.M. Jones
063af7f987 ocaml tools: Use a common debug function.
Add a common debug function for printing debugging messages.  It only
emits the debug message when the verbose (-v) flag is used on the
command line.

It sends the output to stderr, which is flushed immediately after the
message is printed (to help with debugging unexpected crashes).  There
are good arguments for sending the debug to either stdout or stderr,
and almost all existing debug messages replaced by this change went to
stdout.  However using stderr is consistent with libguestfs's own
debug messages which also go to stderr.

I only made simple changes to code of the form 'if verbose () then
printf ...'.  There are more places which could be changed in future.
In a few places I removed gettext calls since we probably should not
translate debug messages.
2016-05-23 10:30:56 +01:00
Richard W.M. Jones
307c83177c Update copyright dates for 2016.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2015/$1-2016/g' `git ls-files`
2016-01-02 21:19:51 +00:00
Richard W.M. Jones
5cdff50d8a v2v: Refactor the map_source_to_uri function.
Move this function to the VCenter module.  This is easier since it
doesn't have to do dcPath calculation (see previous commit).

The readhead parameter is no longer labelled.
2015-10-09 13:21:07 +01:00
Richard W.M. Jones
ffea9f9792 v2v: Use libvirt-supplied <vmware:datacenterpath> if available.
In libvirt >= 1.2.20, the VMware libvirt driver supplies the correct
dcPath to use via <vmware:datacenterpath> in the libvirt XML.  If
libvirt passes us this element, use it.

This code still allows the user to override dcPath using the --dcPath
option on the command line, but that's mainly for safety so we can fix
any problems in virt-v2v or libvirt in the field.  As we get more
confident in libvirt and as libvirt 1.2.20 is more widely adopted, we
will be able to deprecate this parameter entirely.

Thanks: Matthias Bolte for adding the <vmware:datacenterpath> element
to libvirt in
https://libvirt.org/git/?p=libvirt.git;a=commit;h=636a99058758a0447482f3baad94de8de3ab1151
2015-10-09 13:21:07 +01:00
Richard W.M. Jones
a8c725071d v2v: Move VCenter functions to library module.
This refactors useful VCenter functions out of the large
'input_libvirt_vcenter_https.ml' file.
2015-10-09 13:21:07 +01:00
Richard W.M. Jones
d4431886c7 v2v: Move curl functions to library module.
This refactors the curl functions used to talk to vCenter into a
library module.
2015-10-09 13:21:07 +01:00
Richard W.M. Jones
0944acf90c mllib: Replace various ad hoc string_* functions with String.*
This is just a straight refactoring.  Various ad hoc string_*
functions that appeared in Common_utils have been renamed and placed
in the String.* namespace.  The old vs "new" functions are:

string_prefix  -> String.is_prefix
string_suffix  -> String.is_suffix
string_find    -> String.find
replace_str    -> String.replace
string_nsplit  -> String.nsplit
string_split   -> String.split
string_lines_split -> String.lines_split
string_random8 -> String.random8
2015-10-06 13:40:34 +01:00
Richard W.M. Jones
0ed3855098 v2v: Add --dcpath parameter to allow dcPath to be overridden (RHBZ#1256823).
It's currently impossible to correctly predict the dcPath parameter
from the data that libvirt gives us.  So allow the user to override
--dcpath themselves.

Eventually we will get better support in libvirt for this, and this
option will no longer be needed:

  https://www.redhat.com/archives/libvir-list/2015-September/thread.html#00201

This enhances commit 51bc573d0c
and commit 20f1eb400b.
2015-09-10 12:38:56 +01:00
Richard W.M. Jones
51bc573d0c v2v: Fix handling of extra slashes in dcPath calculation (RHBZ#1258342).
This updates commit 20f1eb400b.

Thanks: Tingting Zheng
2015-09-01 14:56:10 +01:00
Richard W.M. Jones
20f1eb400b v2v: vcenter: Calculate dcPath correctly (RHBZ#1256823).
Previously given a path such as:

  vpx://vcenter/Folder/Datacenter/esxi

we calculated dcPath=Folder.  However this is obviously wrong.  We
should chop the path at the final (esxi) element to give
dcPath=Folder/Datacenter.
2015-08-28 17:53:41 +01:00
Richard W.M. Jones
1585bb5bee v2v: vcenter: Change function get_datacenter -> get_dcPath.
In vCenter, the datacenter is identified by a path, and the parameter
used for this is called 'dcPath'.  Rename the function to avoid any
confusion about what we're getting here.

This is just renaming function/variable names and has no other effect.
2015-08-28 17:53:41 +01:00
Richard W.M. Jones
801832e676 v2v: Increase the timeout of VMware curl connections (RHBZ#1146007).
On certain webservers these appear to go beyond even 600 seconds (10
minutes).
2015-06-29 10:43:42 +01:00
Richard W.M. Jones
79fc6074a7 ocaml tools: Use global variables to store trace (-x) and verbose (-v) flags.
Don't pass these flags to dozens of functions.
2015-05-15 15:18:19 +01:00
Richard W.M. Jones
e35605ad8d ocaml tools: Define Common_utils.prog and don't pass it to every function.
This large commit is just code refactoring.  Instead of having
every OCaml tool define 'prog' the same way, always as:

  let prog = Filename.basename Sys.executable_name

move that into a single place, Common_utils.prog.  Then we can use
that global value everywhere else, instead of having to pass it as a
parameter into a dozen different functions.
2015-05-15 15:18:19 +01:00
Pino Toscano
f7529522ab v2v: pass libvirt connection URI to parse_libvirt_xml
This makes it possible to connect to the right libvirt.
2015-04-15 09:36:33 +02:00
Richard W.M. Jones
c5800dc97d Update copyright dates for 2015. 2015-01-17 09:08:15 +00:00
Richard W.M. Jones
c58d335952 v2v: -i libvirt vcenter: Change 'esx:' to 'vcenter:' in errors/warnings.
'esx' is inaccurate.
2014-11-04 21:21:20 +00:00
Richard W.M. Jones
65abc44203 v2v: Add --password-file parameter (RHBZ#1158526).
This allows you to send passwords to virt-v2v input modes without
being interactive.
2014-10-30 13:47:54 +00:00
Richard W.M. Jones
b35b84684c v2v: vmware: Use 'curl --config' to pass arguments securely to curl.
Instead of making up an ordinary curl command line, write a temporary
config file and use 'curl --config tmpfile' to pass the arguments.

The advantage is that it's more secure if we want to supply passwords
to curl, since a '--user username:password' parameter on the command
line could be read (eg. by 'ps ax'), but the temporary file has mode
0600 and cannot be read by other users.

This is mostly code motion, but it also passes the '-q' option to curl
to stop it from reading default configuration files.
2014-10-30 13:47:37 +00:00
Richard W.M. Jones
7c9293fff0 v2v: Add Utils.warning and Utils.info that don't require ~prog parameter. 2014-10-25 15:06:08 +01:00
Richard W.M. Jones
ad78d1492b v2v: -i libvirtxml: Fix handling of nbd sources (RHBZ#1153589).
Previously I modified the parse_libvirt_xml function to get rid of the
awkward 'map_source*' functions, and have the callers map over and
modify the source disks afterwards.  However this broke the case where
an "nbd:..." URL was returned by parse_libvirt_xml, since the callers
might try to map this URL (eg. turning it into an absolute path).
This broke virt-p2v specifically.

This commit changes parse_libvirt_xml to return a list of tuples
containing disk information, giving the callers more information with
which to do the mapping.

This fixes commit 3596165282.
2014-10-22 12:46:08 +01:00
Richard W.M. Jones
496d0c45bc v2v: vcenter: Hoist readahead configurables to top of file.
No change, just code motion.
2014-10-20 22:23:23 +01:00
Richard W.M. Jones
b8f826b7ac v2v: Inline and simplify Xen and vCenter input methods.
Take the opportunity presented by the refactoring in the previous
commit to inline and simplify functions in these input subclasses.

This finally removes the map_source* functions.
2014-10-20 21:12:57 +01:00
Richard W.M. Jones
a468fde016 v2v: Refactor Xen and vCenter code.
This refactors the code into more logical units, based on the previous
commits.  So Xen + the input_libvirt Xen code is grouped and moved
into a new module called Input_libvirt_xen_ssh.  Similarly VCenter +
input_libvirt vCenter code is moved to Input_libvirt_vcenter_https.

There is no change here, purely code motion.
2014-10-20 20:36:06 +01:00