Skip to content

Commit 1e6ad2e

Browse files
committed
xapi-consts: use a variant to reify valid values of cluster stack
Until now, the valid string values were not written anywhere, change the situation. Ideally this would be done using an enum in the idl, but unfortunately this changes types of existing parameters in API calls, so it's quite risky. Instead have a conservative approach to only enumerate the valid values and make Constants the only source of truth for these values, including default ones, which were scatterred around previously. Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent b48e85e commit 1e6ad2e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

ocaml/xapi-consts/constants.ml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,29 @@ let ballooning_enabled = "ballooning.enabled"
212212
let redo_log_enabled = "redo_log.enabled"
213213

214214
(* Valid cluster stack values *)
215-
let ha_cluster_stack = "ha_cluster_stack"
215+
module Ha_cluster_stack = struct
216+
type t = Xhad | Corosync
216217

217-
let default_smapiv3_cluster_stack = "corosync"
218+
let key = "ha_cluster_stack"
218219

219-
(* Note: default without clustering is in !Xapi_globs.default_cluster_stack *)
220-
let supported_smapiv3_cluster_stacks = ["corosync"]
220+
let to_string = function Xhad -> "xhad" | Corosync -> "corosync"
221+
222+
let of_string = function
223+
| "xhad" ->
224+
Some Xhad
225+
| "corosync" ->
226+
Some Corosync
227+
| _ ->
228+
None
229+
end
230+
231+
let ha_cluster_stack = Ha_cluster_stack.key
232+
233+
let default_cluster_stack = Ha_cluster_stack.(to_string Xhad)
234+
235+
let default_smapiv3_cluster_stack = Ha_cluster_stack.(to_string Corosync)
236+
237+
let supported_smapiv3_cluster_stacks = [default_smapiv3_cluster_stack]
221238

222239
(* Set in the local db to cause us to emit an alert when we come up as a master after
223240
a transition or HA failover *)

ocaml/xapi/xapi_globs.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ let migration_https_only = ref true
858858

859859
let cluster_stack_root = ref "/usr/libexec/xapi/cluster-stack"
860860

861-
let cluster_stack_default = ref "xhad"
861+
let cluster_stack_default = ref Constants.default_cluster_stack
862862

863863
let xen_cmdline_path = ref "/opt/xensource/libexec/xen-cmdline"
864864

0 commit comments

Comments
 (0)