From 88c237261f527e00e2d4bae46b20958e0440124c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 20 Nov 2018 09:14:11 +0000 Subject: [PATCH] v2v: -o openstack: Check openstack binary exists before running it. Improves the error message when openstack is not installed. This also mentions the openstack command in the manual page. --- v2v/output_openstack.ml | 17 +++++++++++++++-- v2v/virt-v2v-output-openstack.pod | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/v2v/output_openstack.ml b/v2v/output_openstack.ml index 376269428..2aef518a2 100644 --- a/v2v/output_openstack.ml +++ b/v2v/output_openstack.ml @@ -28,6 +28,9 @@ open Common_gettext.Gettext open Types open Utils +(* Name of the openstack CLI program (on $PATH). *) +let openstack_binary = "openstack" + (* Timeout waiting for new Cinder volumes to move to "available" state. * We assume this could be quite a long time on backends which want * to preallocate the storage. @@ -157,13 +160,20 @@ class output_openstack output_conn output_password output_storage List.push_back args "--insecure"; !args in + let error_unless_openstack_command_exists () = + try ignore (which openstack_binary) + with Executable_not_found _ -> + error (f_"the ā€˜%s’ program is not available. It is needed to communicate with OpenStack.") + openstack_binary + in + (* We use this convenient wrapper around [Tools_utils.run_command] * for two reasons: (1) Because we want to run openstack with * extra_args. (2) OpenStack commands are noisy so we want to * direct stdout to /dev/null unless we're in verbose mode. *) let run_openstack_command args = - let cmd = [ "openstack" ] @ extra_args @ args in + let cmd = [ openstack_binary ] @ extra_args @ args in let stdout_fd = if verbose () then None else Some (openfile "/dev/null" [O_WRONLY] 0) in @@ -176,7 +186,7 @@ class output_openstack output_conn output_password output_storage * '-f json' to the args yourself. *) let run_openstack_command_capture_json args = - let cmd = [ "openstack" ] @ extra_args @ args in + let cmd = [ openstack_binary ] @ extra_args @ args in let json, chan = Filename.open_temp_file "v2vopenstack" ".json" in unlink_on_exit json; @@ -353,6 +363,9 @@ object inherit output method precheck () = + (* Check the openstack command exists. *) + error_unless_openstack_command_exists (); + (* Run the openstack command simply to check we can connect * with the provided authentication parameters/environment * variables. Issuing a token should have only a tiny diff --git a/v2v/virt-v2v-output-openstack.pod b/v2v/virt-v2v-output-openstack.pod index 286fe1230..8d4fc4f04 100644 --- a/v2v/virt-v2v-output-openstack.pod +++ b/v2v/virt-v2v-output-openstack.pod @@ -54,6 +54,9 @@ The reason for this is because to create Cinder volumes that will contain the guest data (for the converted guest) we must attach those Cinder volumes to an OpenStack virtual machine. +The C command must be installed in the appliance. We use +it for communicating with OpenStack. + When virt-v2v is running in the conversion appliance, you must supply the name or UUID of the conversion appliance to virt-v2v, eg: @@ -206,7 +209,8 @@ leave the system disk in Glance, and import the data disks to Cinder. =head1 SEE ALSO -L. +L, +L. =head1 AUTHOR