Skip to content

Commit 9b72c47

Browse files
committed
Use Pool_features.assert_enabled where appropriate.
Now we we no longer raise Api_errors.license_restriction except in Pool_features.assert_enabled. Signed-off-by: Thomas Sanders <[email protected]>
1 parent ee53d06 commit 9b72c47

File tree

9 files changed

+19
-40
lines changed

9 files changed

+19
-40
lines changed

ocaml/xapi/workload_balancing.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ let raise_not_initialized () =
4646
let raise_disabled () =
4747
raise (Api_errors.Server_error (Api_errors.wlb_disabled, []))
4848

49-
let raise_license_restriction () =
50-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
51-
5249
let raise_timeout timeout =
5350
raise (Api_errors.Server_error
5451
(Api_errors.wlb_timeout, [string_of_float timeout]))
@@ -97,9 +94,7 @@ let wlb_host_port ~__context =
9794
split_host_port url
9895

9996
let assert_wlb_licensed ~__context =
100-
if not (Pool_features.is_enabled ~__context Features.WLB)
101-
then
102-
raise_license_restriction()
97+
Pool_features.assert_enabled ~__context ~f:Features.WLB
10398

10499
let assert_wlb_initialized ~__context =
105100
let pool = Helpers.get_pool ~__context in

ocaml/xapi/xapi_dr.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ let clear_sr_introduced_by ~__context ~vm =
209209
let assert_session_allows_dr ~session_id ~action =
210210
Server_helpers.exec_with_new_task ~session_id "Checking pool license and session permissions allow DR"
211211
(fun __context ->
212-
if (not (Pool_features.is_enabled ~__context Features.DR)) then
213-
raise (Api_errors.Server_error(Api_errors.license_restriction, []));
212+
Pool_features.assert_enabled ~__context ~f:Features.DR;
214213
(* Any session can call VM(_appliance).recover since it is marked as readonly *)
215214
(* so it can be used by the sessions returned by VDI.open_database. *)
216215
(* We need to manually check that a session could legitimately have called VDI.open_database. *)

ocaml/xapi/xapi_dr_task.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ let try_create_sr_from_record ~__context ~_type ~device_config ~dr_task ~sr_reco
9292

9393
let create ~__context ~_type ~device_config ~whitelist =
9494
(* Check if licence allows disaster recovery. *)
95-
if (not (Pool_features.is_enabled ~__context Features.DR)) then
96-
raise (Api_errors.Server_error(Api_errors.license_restriction, []));
95+
Pool_features.assert_enabled ~__context ~f:Features.DR;
9796
(* Check that the SR type supports metadata. *)
9897
if not (List.mem_assoc Smint.Sr_metadata (Sm.features_of_driver _type)) then
9998
raise (Api_errors.Server_error (Api_errors.operation_not_allowed,

ocaml/xapi/xapi_ha.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,7 @@ let enable __context heartbeat_srs configuration =
13461346
if Db.Pool.get_ha_enabled ~__context ~self:pool
13471347
then raise (Api_errors.Server_error(Api_errors.ha_is_enabled, []));
13481348

1349-
if not (Pool_features.is_enabled ~__context Features.HA)
1350-
then raise (Api_errors.Server_error(Api_errors.license_restriction, []));
1349+
Pool_features.assert_enabled ~__context ~f:Features.HA;
13511350

13521351
(* Check that all of our 'disallow_unplug' PIFs are currently attached *)
13531352
let unplugged_ununpluggable_pifs = Db.PIF.get_refs_where ~__context ~expr:(And (

ocaml/xapi/xapi_sr.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ let find_or_create_metadata_vdi ~__context ~sr =
608608
vdi
609609

610610
let enable_database_replication ~__context ~sr =
611-
if (not (Pool_features.is_enabled ~__context Features.DR)) then
612-
raise (Api_errors.Server_error(Api_errors.license_restriction, []));
611+
Pool_features.assert_enabled ~__context ~f:Features.DR;
613612
assert_supports_database_replication ~__context ~sr;
614613
let get_vdi_callback = (fun () -> find_or_create_metadata_vdi ~__context ~sr) in
615614
Xapi_vdi_helpers.enable_database_replication ~__context ~get_vdi_callback

ocaml/xapi/xapi_subject.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ let add_to_roles ~__context ~self ~role =
177177

178178
(* CP-1224: Free Edition: Attempts to add or remove roles *)
179179
(* will fail with a LICENSE_RESTRICTION error.*)
180-
if (not (Pool_features.is_enabled ~__context Features.RBAC)) then
181-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
182-
else
180+
Pool_features.assert_enabled ~__context ~f:Features.RBAC;
183181

184182
if (Xapi_role.is_valid_role ~__context ~role)
185183
then
@@ -215,9 +213,7 @@ let remove_from_roles ~__context ~self ~role =
215213

216214
(* CP-1224: Free Edition: Attempts to add or remove roles *)
217215
(* will fail with a LICENSE_RESTRICTION error.*)
218-
if not (Pool_features.is_enabled ~__context Features.RBAC) then
219-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
220-
else
216+
Pool_features.assert_enabled ~__context ~f:Features.RBAC;
221217

222218
if (List.mem role (Db.Subject.get_roles ~__context ~self))
223219
then

ocaml/xapi/xapi_vif_helpers.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ let gen_mac(dev, seed) =
143143
take_byte 2 mac_data_2; |]
144144

145145
let assert_locking_licensed ~__context =
146-
if (not (Pool_features.is_enabled ~__context Features.VIF_locking)) then
147-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
146+
Pool_features.assert_enabled ~__context ~f:Features.VIF_locking
148147

149148
let m = Mutex.create () (* prevents duplicate VIFs being created by accident *)
150149

ocaml/xapi/xapi_vm.ml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,9 @@ let snapshot ~__context ~vm ~new_name =
499499
(* Snapshot_with_quiesce triggers the VSS plugin which will then calls the VM.snapshot API call. *)
500500
(* Thus, to avoid dead-locks, do not put snapshot and snapshot_with_quiesce on the same waiting line *)
501501
let snapshot_with_quiesce ~__context ~vm ~new_name =
502-
if not (Pool_features.is_enabled ~__context Features.VSS)
503-
then raise (Api_errors.Server_error(Api_errors.license_restriction, []))
504-
else begin
505-
TaskHelper.set_cancellable ~__context;
506-
Xapi_vm_snapshot.snapshot_with_quiesce ~__context ~vm ~new_name
507-
end
502+
Pool_features.assert_enabled ~__context ~f:Features.VSS;
503+
TaskHelper.set_cancellable ~__context;
504+
Xapi_vm_snapshot.snapshot_with_quiesce ~__context ~vm ~new_name
508505

509506
(* As we will destroy the domain ourself, we grab the vm_lock here in order to tell the event thread to *)
510507
(* do not look at this domain. The message forwarding layer already checked that the VM reference we *)
@@ -521,16 +518,13 @@ let revert ~__context ~snapshot =
521518
(* As the checkpoint operation modify the domain state, we take the vm_lock to do not let the event *)
522519
(* thread mess around with that. *)
523520
let checkpoint ~__context ~vm ~new_name =
524-
if not (Pool_features.is_enabled ~__context Features.Checkpoint) then
525-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
526-
else begin
527-
Local_work_queue.wait_in_line Local_work_queue.long_running_queue
528-
(Printf.sprintf "VM.checkpoint %s" (Context.string_of_task __context))
529-
(fun () ->
530-
TaskHelper.set_cancellable ~__context;
531-
Xapi_vm_snapshot.checkpoint ~__context ~vm ~new_name
532-
)
533-
end
521+
Pool_features.assert_enabled ~__context ~f:Features.Checkpoint;
522+
Local_work_queue.wait_in_line Local_work_queue.long_running_queue
523+
(Printf.sprintf "VM.checkpoint %s" (Context.string_of_task __context))
524+
(fun () ->
525+
TaskHelper.set_cancellable ~__context;
526+
Xapi_vm_snapshot.checkpoint ~__context ~vm ~new_name
527+
)
534528

535529
let copy ~__context ~vm ~new_name ~sr =
536530
(* See if the supplied SR is suitable: it must exist and be a non-ISO SR *)

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ let assert_sr_support_migration ~__context ~vdi_map ~remote_rpc ~session_id =
7979
) vdi_map
8080

8181
let assert_licensed_storage_motion ~__context =
82-
if (not (Pool_features.is_enabled ~__context Features.Storage_motion)) then
83-
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
82+
Pool_features.assert_enabled ~__context ~f:Features.Storage_motion
8483

8584
let get_ip_from_url url =
8685
match Http.Url.of_string url with

0 commit comments

Comments
 (0)