Skip to content

Commit bef6739

Browse files
authored
Add message argument to LICENSE_CHECKOUT_ERROR (#6592)
The first argument of this API error is used for error codes as defined by v6d. These product-specific error codes can be matched on by clients who know about them (e.g. XenCenter for XenServer). The new, second argument allows v6d to return an error message in English that xe can print directly, while xe remains product agnostic and does not need to know v6d's error definitions. This replaces some awkward API-message handling code in cli_operations.
2 parents 19fa4d2 + ac52de9 commit bef6739

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

ocaml/idl/datamodel_errors.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let _ =
6868
"The license-server connection details (address or port) were missing or \
6969
incomplete."
7070
() ;
71-
error Api_errors.license_checkout_error ["reason"]
71+
error Api_errors.license_checkout_error ["code"; "message"]
7272
~doc:"The license for the edition you requested is not available." () ;
7373
error Api_errors.license_file_deprecated []
7474
~doc:

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5338,9 +5338,8 @@ let with_license_server_changes printer rpc session_id params hosts f =
53385338
)
53395339
hosts
53405340
) ;
5341-
let now = Unix.gettimeofday () in
53425341
try f rpc session_id with
5343-
| Api_errors.Server_error (name, _) as e
5342+
| Api_errors.Server_error (name, [_; msg])
53445343
when name = Api_errors.license_checkout_error ->
53455344
(* Put back original license_server_details *)
53465345
List.iter
@@ -5349,28 +5348,8 @@ let with_license_server_changes printer rpc session_id params hosts f =
53495348
~value:license_server
53505349
)
53515350
current_license_servers ;
5352-
let alerts =
5353-
Client.Message.get_since ~rpc ~session_id
5354-
~since:(Date.of_unix_time (now -. 1.))
5355-
in
5356-
let print_if_checkout_error (ref, msg) =
5357-
if
5358-
false
5359-
|| msg.API.message_name = fst Api_messages.v6_rejected
5360-
|| msg.API.message_name = fst Api_messages.v6_comm_error
5361-
|| msg.API.message_name
5362-
= fst Api_messages.v6_license_server_version_obsolete
5363-
then (
5364-
Client.Message.destroy ~rpc ~session_id ~self:ref ;
5365-
printer (Cli_printer.PStderr (msg.API.message_body ^ "\n"))
5366-
)
5367-
in
5368-
if alerts = [] then
5369-
raise e
5370-
else (
5371-
List.iter print_if_checkout_error alerts ;
5372-
raise (ExitWithError 1)
5373-
)
5351+
printer (Cli_printer.PStderr (msg ^ "\n")) ;
5352+
raise (ExitWithError 1)
53745353
| Api_errors.Server_error (name, _) as e
53755354
when name = Api_errors.invalid_edition ->
53765355
let host = get_host_from_session rpc session_id in

ocaml/xapi-idl/v6/v6_interface.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ type errors =
7878
(** Thrown by license_check when expiry date matches or precedes current
7979
date *)
8080
| License_processing_error (** License could not be processed *)
81-
| License_checkout_error of string (** License could not be checked out *)
81+
| License_checkout_error of string * string
82+
(** License could not be checked out *)
8283
| Missing_connection_details
8384
(** Thrown if connection port or address parameter not supplied to
8485
check_license *)

ocaml/xapi/xapi_host.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,8 +2079,8 @@ let apply_edition_internal ~__context ~host ~edition ~additional =
20792079
raise Api_errors.(Server_error (license_processing_error, []))
20802080
| V6_interface.(V6_error Missing_connection_details) ->
20812081
raise Api_errors.(Server_error (missing_connection_details, []))
2082-
| V6_interface.(V6_error (License_checkout_error s)) ->
2083-
raise Api_errors.(Server_error (license_checkout_error, [s]))
2082+
| V6_interface.(V6_error (License_checkout_error (code, msg))) ->
2083+
raise Api_errors.(Server_error (license_checkout_error, [code; msg]))
20842084
| V6_interface.(V6_error (Internal_error e)) ->
20852085
Helpers.internal_error "%s" e
20862086
in

0 commit comments

Comments
 (0)