Pino Toscano
2020-May-26 07:29 UTC
[Libguestfs] [v2v PATCH] vCenter: require curl in #precheck
The curl binary is used in the VCenter module, so require it up-front. This let us remove the need to point the user to check whether curl is installed in an error message. --- v2v/input_libvirt_vcenter_https.ml | 13 ++++++++++++- v2v/vCenter.ml | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml index ed2e5eed..2265f76e 100644 --- a/v2v/input_libvirt_vcenter_https.ml +++ b/v2v/input_libvirt_vcenter_https.ml @@ -19,6 +19,7 @@ (** [-i libvirt] when the source is VMware vCenter *) open Common_gettext.Gettext +open Std_utils open Tools_utils open Unix_utils.Env @@ -33,13 +34,23 @@ open Printf (* Subclass specialized for handling VMware vCenter over https. *) class input_libvirt_vcenter_https libvirt_conn input_conn input_password parsed_uri server guest + + let error_unless_curl_command_exists () + let curl_binary = "curl" in + try ignore (which curl_binary) + with Executable_not_found _ -> + error (f_"the ‘%s’ program is not available. It is needed to communicate with vCenter.") + curl_binary + in + object (self) inherit input_libvirt libvirt_conn ~input_conn guest val mutable dcPath = "" method precheck () - error_if_libvirt_does_not_support_json_backingfile () + error_if_libvirt_does_not_support_json_backingfile (); + error_unless_curl_command_exists () method source ?bandwidth () debug "input_libvirt_vcenter_https: source: server %s" server; diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml index 586ea3e2..33120e88 100644 --- a/v2v/vCenter.ml +++ b/v2v/vCenter.ml @@ -189,7 +189,7 @@ and fetch_headers_from_url password_file uri sslverify https_url match statuses with | [] -> dump_response stderr; - error (f_"vcenter: no status code in output of ‘curl’ command. Is ‘curl’ installed?") + error (f_"vcenter: no status code in output of ‘curl’ command.") | ss -> let s = List.hd (List.rev ss) in String.sub s (String.index s ' ' + 1) 3 in -- 2.25.4
Richard W.M. Jones
2020-May-26 09:20 UTC
Re: [Libguestfs] [v2v PATCH] vCenter: require curl in #precheck
On Tue, May 26, 2020 at 09:29:24AM +0200, Pino Toscano wrote:> The curl binary is used in the VCenter module, so require it up-front. > This let us remove the need to point the user to check whether curl is > installed in an error message. > --- > v2v/input_libvirt_vcenter_https.ml | 13 ++++++++++++- > v2v/vCenter.ml | 2 +- > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml > index ed2e5eed..2265f76e 100644 > --- a/v2v/input_libvirt_vcenter_https.ml > +++ b/v2v/input_libvirt_vcenter_https.ml > @@ -19,6 +19,7 @@ > (** [-i libvirt] when the source is VMware vCenter *) > > open Common_gettext.Gettext > +open Std_utils > open Tools_utils > open Unix_utils.Env > > @@ -33,13 +34,23 @@ open Printf > (* Subclass specialized for handling VMware vCenter over https. *) > class input_libvirt_vcenter_https > libvirt_conn input_conn input_password parsed_uri server guest > + > + let error_unless_curl_command_exists () > + let curl_binary = "curl" in > + try ignore (which curl_binary) > + with Executable_not_found _ -> > + error (f_"the ‘%s’ program is not available. It is needed to communicate with vCenter.") > + curl_binary > + in > + > object (self) > inherit input_libvirt libvirt_conn ~input_conn guest > > val mutable dcPath = "" > > method precheck () > - error_if_libvirt_does_not_support_json_backingfile () > + error_if_libvirt_does_not_support_json_backingfile (); > + error_unless_curl_command_exists () > > method source ?bandwidth () > debug "input_libvirt_vcenter_https: source: server %s" server; > diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml > index 586ea3e2..33120e88 100644 > --- a/v2v/vCenter.ml > +++ b/v2v/vCenter.ml > @@ -189,7 +189,7 @@ and fetch_headers_from_url password_file uri sslverify https_url > match statuses with > | [] -> > dump_response stderr; > - error (f_"vcenter: no status code in output of ‘curl’ command. Is ‘curl’ installed?") > + error (f_"vcenter: no status code in output of ‘curl’ command.") > | ss -> > let s = List.hd (List.rev ss) in > String.sub s (String.index s ' ' + 1) 3 inACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Possibly Parallel Threads
- [v2v PATCH] -i libvirt: print URI without connecting
- [PATCH] v2v: Allow libvirt >= 2.1.0 to be used for Xen and vCenter conversions.
- [PATCH v2 00/11] v2v: Change virt-v2v to use nbdkit for input in several modes.
- [PATCH v3 00/12] v2v: Change virt-v2v to use nbdkit for input in several modes.
- [PATCH v2v 0/4] v2v: vcenter: Implement cookie scripts.