]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
CP-2137: Allow additional feature flags to be set by v6d
authorRob Hoes <rob.hoes@citrix.com>
Wed, 26 Jan 2011 17:39:04 +0000 (17:39 +0000)
committerRob Hoes <rob.hoes@citrix.com>
Wed, 26 Jan 2011 17:39:04 +0000 (17:39 +0000)
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
ocaml/xapi/features.ml
ocaml/xapi/features.mli
ocaml/xapi/pool_features.ml

index d22c560c97d344df4d21a4f2f019023d37174d7f..afecac5e064fc31b0a079bb1a36e1bf7c0109c91 100644 (file)
@@ -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");
index e450df073383c26c05eaf393705480ee91b12d4d..083238910d906ee15ba3ab3473f7e2ecf4fbb230 100644 (file)
@@ -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 *)
index db0d71f2c849e6914d3944fbd39129edf25d97ec..d61b93c9aefdec755a79e9c41203ee55a2de8203 100644 (file)
@@ -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