From 2cd744900d1f3228839d29c3e144547d3b2c742e Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Wed, 26 Jan 2011 17:39:04 +0000 Subject: [PATCH] CP-2137: Allow additional feature flags to be set by v6d Signed-off-by: Rob Hoes --- ocaml/xapi/features.ml | 2 -- ocaml/xapi/features.mli | 1 - ocaml/xapi/pool_features.ml | 33 ++++++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ocaml/xapi/features.ml b/ocaml/xapi/features.ml index d22c560c..afecac5e 100644 --- a/ocaml/xapi/features.ml +++ b/ocaml/xapi/features.ml @@ -31,7 +31,6 @@ type feature = | RBAC | DMC | Checkpoint - | Vswitch_controller | CPU_masking | Connection | No_platform_filter @@ -57,7 +56,6 @@ let keys_of_features = RBAC, ("restrict_rbac", Negative, "RBAC"); DMC, ("restrict_dmc", Negative, "DMC"); Checkpoint, ("restrict_checkpoint", Negative, "chpt"); - Vswitch_controller, ("restrict_vswitch_controller", Negative, "DVSC"); CPU_masking, ("restrict_cpu_masking", Negative, "Mask"); Connection, ("restrict_connection", Negative, "Cnx"); No_platform_filter, ("platform_filter", Negative, "Plat"); diff --git a/ocaml/xapi/features.mli b/ocaml/xapi/features.mli index e450df07..08323891 100644 --- a/ocaml/xapi/features.mli +++ b/ocaml/xapi/features.mli @@ -31,7 +31,6 @@ type feature = | RBAC (** Enable Role-Based Access Control (RBAC) *) | DMC (** Enable Dynamic Memory Control (DMC) *) | Checkpoint (** Enable Checkpoint functionality *) - | Vswitch_controller (** Enable use of a Distributed VSwitch (DVS) Controller *) | CPU_masking (** Enable masking of CPU features *) | Connection (** Used by XenCenter *) | No_platform_filter (** Filter platform data *) diff --git a/ocaml/xapi/pool_features.ml b/ocaml/xapi/pool_features.ml index db0d71f2..d61b93c9 100644 --- a/ocaml/xapi/pool_features.ml +++ b/ocaml/xapi/pool_features.ml @@ -15,27 +15,46 @@ open Features module D = Debug.Debugger(struct let name="pool_features" end) open D +let all_flags = List.map (fun (k, v) -> k) (to_assoc_list all_features) + +let new_restrictions params = + let kvs = List.filter (fun (k, v) -> + try String.sub k 0 9 = "restrict_" && not (List.mem k all_flags) + with Invalid_argument _ -> false + ) params in + List.map (fun (k, v) -> k) kvs + let pool_features_of_list hosts = List.fold_left Listext.List.intersect all_features hosts - + let get_pool_features ~__context = let pool = List.hd (Db.Pool.get_all ~__context) in of_assoc_list (Db.Pool.get_restrictions ~__context ~self:pool) - + let is_enabled ~__context f = let pool_features = get_pool_features ~__context in List.mem f pool_features let update_pool_features ~__context = let pool = List.hd (Db.Pool.get_all ~__context) in - let pool_features = get_pool_features ~__context in + let pool_restrictions = Db.Pool.get_restrictions ~__context ~self:pool in let hosts = List.map - (fun (_, host_r) -> of_assoc_list host_r.API.host_license_params) + (fun (_, host_r) -> host_r.API.host_license_params) (Db.Host.get_all_records ~__context) in - let new_features = pool_features_of_list hosts in - if new_features <> pool_features then begin + let new_features = pool_features_of_list (List.map of_assoc_list hosts) in + let additional_flags = new_restrictions (List.hd hosts) in + let rec find_additional = function + | [] -> [] + | flag :: rest -> + let switches = List.map (function params -> bool_of_string (List.assoc flag params)) hosts in + (flag, string_of_bool (List.fold_left (||) false switches)) :: find_additional rest + in + let additional_restrictions = find_additional additional_flags in + let new_restrictions = additional_restrictions @ (to_assoc_list new_features) in + if new_restrictions <> pool_restrictions then begin + let pool_features = of_assoc_list pool_restrictions in info "Old pool features enabled: %s" (to_compact_string pool_features); info "New pool features enabled: %s" (to_compact_string new_features); - Db.Pool.set_restrictions ~__context ~self:pool ~value:(to_assoc_list new_features) + Db.Pool.set_restrictions ~__context ~self:pool ~value:new_restrictions end -- 2.39.5