From ff5f9543dd0f94643ca356bdf268cba61da2b69d Mon Sep 17 00:00:00 2001 From: Gabriel Buica Date: Mon, 5 Feb 2024 11:41:02 +0000 Subject: [PATCH] CP:46157: Add `observer_experimental_components` flag Adds a new variable in `Xapi_globs` that is a comma-separeted string of components. Components in this list will be considered experimental and therefore disabled by default. They can be enabled by adding an entry in `xapi.conf` without their name. For instance, adding the line: observer-experimental-components = "" will enable all experimental components. Signed-off-by: Gabriel Buica --- ocaml/xapi-consts/constants.ml | 16 +++++++++++ ocaml/xapi/xapi_globs.ml | 27 +++++++++++++++++++ ocaml/xapi/xapi_observer_components.ml | 37 ++++++++++++++++++-------- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/ocaml/xapi-consts/constants.ml b/ocaml/xapi-consts/constants.ml index 5a0eea13af8..e0ae61b0001 100644 --- a/ocaml/xapi-consts/constants.ml +++ b/ocaml/xapi-consts/constants.ml @@ -398,3 +398,19 @@ let good_ciphersuites = ["ECDHE-RSA-AES256-GCM-SHA384"; "ECDHE-RSA-AES128-GCM-SHA256"] let verify_certificates_path = "/var/xapi/verify-certificates" + +let observer_component_xapi = "xapi" + +let observer_component_xenopsd = "xenopsd" + +let observer_component_xapi_clusterd = "xapi-clusterd" + +let observer_component_smapi = "smapi" + +let observer_components_all = + [ + observer_component_xapi + ; observer_component_xenopsd + ; observer_component_xapi_clusterd + ; observer_component_smapi + ] diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index f722fbe83cd..37e9f561537 100644 --- a/ocaml/xapi/xapi_globs.ml +++ b/ocaml/xapi/xapi_globs.ml @@ -16,6 +16,7 @@ module String_plain = String (* For when we don't want the Xstringext version *) open Xapi_stdext_std.Xstringext +module StringSet = Set.Make (String) module D = Debug.Make (struct let name = "xapi_globs" end) @@ -1019,6 +1020,9 @@ let observer_endpoint_https_enabled = ref false let python3_path = ref "/usr/bin/python3" +let observer_experimental_components = + ref (StringSet.singleton Constants.observer_component_smapi) + let xapi_globs_spec = [ ( "master_connection_reset_timeout" @@ -1515,6 +1519,29 @@ let other_options = , (fun () -> string_of_bool !observer_endpoint_https_enabled) , "Enable https endpoints to be used by observers" ) + ; ( "observer-experimental-components" + , Arg.String + (fun s -> + observer_experimental_components := + match s with + | "" -> + StringSet.empty + | s -> + let input_set = + s |> String.split_on_char ',' |> StringSet.of_list + in + let valid_set = + Constants.observer_components_all |> StringSet.of_list + in + StringSet.inter input_set valid_set + ) + , (fun () -> + !observer_experimental_components + |> StringSet.elements + |> String.concat "," + ) + , "Comma-separated list of experimental observer components" + ) ] (* The options can be set with the variable xapiflags in /etc/sysconfig/xapi. diff --git a/ocaml/xapi/xapi_observer_components.ml b/ocaml/xapi/xapi_observer_components.ml index 33a6570d008..e91fd143ec1 100644 --- a/ocaml/xapi/xapi_observer_components.ml +++ b/ocaml/xapi/xapi_observer_components.ml @@ -12,34 +12,36 @@ * GNU Lesser General Public License for more details. *) +module D = Debug.Make (struct let name = "xapi_observer_components" end) + type t = Xapi | Xenopsd | Xapi_clusterd | SMApi [@@deriving ord] exception Unsupported_Component of string -let all = [Xapi; Xenopsd; Xapi_clusterd; SMApi] - let to_string = function | Xapi -> - "xapi" + Constants.observer_component_xapi | Xenopsd -> - "xenopsd" + Constants.observer_component_xenopsd | Xapi_clusterd -> - "xapi-clusterd" + Constants.observer_component_xapi_clusterd | SMApi -> - "smapi" + Constants.observer_component_smapi let of_string = function - | "xapi" -> + | str when String.equal str Constants.observer_component_xapi -> Xapi - | "xenopsd" -> + | str when String.equal str Constants.observer_component_xenopsd -> Xenopsd - | "xapi-clusterd" -> + | str when String.equal str Constants.observer_component_xapi_clusterd -> Xapi_clusterd - | "smapi" -> + | str when String.equal str Constants.observer_component_smapi -> SMApi | c -> raise (Unsupported_Component c) +let all = List.map of_string Constants.observer_components_all + (* We start up the observer for clusterd only if clusterd has been enabled otherwise we initialise clusterd separately in cluster_host so that there is no need to restart xapi in order for clusterd to be observed. @@ -54,8 +56,21 @@ let assert_valid_components components = with Unsupported_Component component -> raise Api_errors.(Server_error (invalid_value, ["component"; component])) +let filter_out_exp_components components = + let open Xapi_globs in + let component_set = components |> List.map to_string |> StringSet.of_list in + StringSet.diff component_set !observer_experimental_components + |> StringSet.elements + |> List.map of_string + let observed_components_of components = - match components with [] -> startup_components () | components -> components + ( match components with + | [] -> + startup_components () + | components -> + components + ) + |> filter_out_exp_components let is_component_enabled ~component = try