Skip to content

Commit ee53d06

Browse files
committed
Utility function Pool_features.assert_enabled
A new function which throws an appropriate exception if the specified pool licence feature is not enabled. Signed-off-by: Thomas Sanders <[email protected]>
1 parent e59dea2 commit ee53d06

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ocaml/xapi/pool_features.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ let is_enabled ~__context f =
3535
let pool_features = get_pool_features ~__context in
3636
List.mem f pool_features
3737

38+
let assert_enabled ~__context ~f =
39+
if not (is_enabled ~__context f) then
40+
raise (Api_errors.Server_error(Api_errors.license_restriction, [Features.name_of_feature f]))
41+
3842
let update_pool_features ~__context =
3943
let pool = Helpers.get_pool ~__context in
4044
let pool_restrictions = Db.Pool.get_restrictions ~__context ~self:pool in

ocaml/xapi/pool_features.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
(** Check whether a given feature is currently enabled on the pool. *)
1919
val is_enabled : __context:Context.t -> Features.feature -> bool
2020

21+
(** Raise appropriate exception if feature is not enabled. *)
22+
val assert_enabled : __context:Context.t -> f:Features.feature -> unit
23+
2124
(** Update the pool-level restrictions list in the database. *)
2225
val update_pool_features : __context:Context.t -> unit
2326

0 commit comments

Comments
 (0)