[Libguestfs] [v2v PATCH] vCenter: require curl in #precheck

Pino Toscano ptoscano at redhat.com
Tue May 26 07:29:24 UTC 2020


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




More information about the Libguestfs mailing list