Skip to content

Commit

Permalink
Merge pull request #5428 from GabrielBuica/private/dbuica/CP-46157
Browse files Browse the repository at this point in the history
CP:46157: Add `observer_experimental_components` flag
  • Loading branch information
mg12 authored Feb 9, 2024
2 parents f92edf0 + ff5f954 commit 8901af8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
16 changes: 16 additions & 0 deletions ocaml/xapi-consts/constants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
27 changes: 27 additions & 0 deletions ocaml/xapi/xapi_globs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 26 additions & 11 deletions ocaml/xapi/xapi_observer_components.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 8901af8

Please sign in to comment.