Skip to content

Commit 9845df6

Browse files
committed
CR47: Give the possibility to restrict the checkpoint feature in experimental settings
Signed-off-by: Thomas Gazagnaire <[email protected]>
1 parent 092c2de commit 9845df6

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

ocaml/license/restrictions.ml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type restrictions = {
5353
enable_wlb : bool;
5454
enable_rbac : bool;
5555
enable_dmc : bool;
56+
enable_checkpoint : bool;
5657
enable_vswitch_controller : bool;
5758
restrict_connection : bool;
5859
platform_filter : bool;
@@ -76,6 +77,7 @@ let to_compact_string (x: restrictions) =
7677
"RBAC" , x.enable_rbac ;
7778
"DMC" , x.enable_dmc ;
7879
"DVSC" , x.enable_vswitch_controller;
80+
"chpt" , x.enable_checkpoint ;
7981
"Cnx" , not x.restrict_connection ;
8082
"Plat" , not x.platform_filter ;
8183
"nag" , x.regular_nag_dialog ;
@@ -99,6 +101,7 @@ let most_permissive = {
99101
enable_wlb = true;
100102
enable_rbac = true;
101103
enable_dmc = true;
104+
enable_checkpoint = true;
102105
enable_vswitch_controller = true;
103106
restrict_connection = false;
104107
platform_filter = false;
@@ -121,6 +124,7 @@ let least_permissive (a: restrictions) (b: restrictions) = {
121124
enable_wlb = a.enable_wlb && b.enable_wlb;
122125
enable_rbac = a.enable_rbac && b.enable_rbac;
123126
enable_dmc = a.enable_dmc && b.enable_dmc;
127+
enable_checkpoint = a.enable_checkpoint && b.enable_checkpoint;
124128
enable_vswitch_controller = a.enable_vswitch_controller && b.enable_vswitch_controller;
125129
restrict_connection = a.restrict_connection || b.restrict_connection;
126130
platform_filter = a.platform_filter || b.platform_filter;
@@ -151,6 +155,7 @@ let _restrict_historical_performance = "restrict_historical_performance"
151155
let _restrict_wlb = "restrict_wlb"
152156
let _restrict_rbac = "restrict_rbac"
153157
let _restrict_dmc = "restrict_dmc"
158+
let _restrict_checkpoint = "restrict_checkpoint"
154159
let _restrict_vswitch_controller = "restrict_vswitch_controller"
155160
let _regular_nag_dialog = "regular_nag_dialog"
156161

@@ -170,6 +175,7 @@ let to_assoc_list (x: restrictions) =
170175
(_restrict_wlb, string_of_bool (not x.enable_wlb));
171176
(_restrict_rbac, string_of_bool (not x.enable_rbac));
172177
(_restrict_dmc, string_of_bool (not x.enable_dmc ));
178+
(_restrict_checkpoint, string_of_bool (not x.enable_checkpoint ));
173179
(_restrict_vswitch_controller, string_of_bool (not x.enable_vswitch_controller ));
174180
(_regular_nag_dialog, string_of_bool x.regular_nag_dialog);
175181
]
@@ -194,7 +200,8 @@ let of_assoc_list x =
194200
enable_wlb = Opt.default most_permissive.enable_wlb (Opt.map not (find bool_of_string _restrict_wlb));
195201
enable_rbac = Opt.default most_permissive.enable_rbac (Opt.map not (find bool_of_string _restrict_rbac));
196202
enable_dmc = Opt.default most_permissive.enable_dmc (Opt.map not (find bool_of_string _restrict_dmc));
197-
enable_vswitch_controller = Opt.default most_permissive.enable_dmc (Opt.map not (find bool_of_string _restrict_vswitch_controller));
203+
enable_checkpoint = Opt.default most_permissive.enable_checkpoint (Opt.map not (find bool_of_string _restrict_dmc));
204+
enable_vswitch_controller = Opt.default most_permissive.enable_dmc (Opt.map not (find bool_of_string _restrict_vswitch_controller));
198205
regular_nag_dialog = Opt.default most_permissive.regular_nag_dialog (find bool_of_string _regular_nag_dialog);
199206
}
200207

@@ -216,7 +223,8 @@ let common_to_all_skus =
216223
enable_performance = false;
217224
enable_wlb = false;
218225
enable_rbac = false;
219-
enable_dmc = false;
226+
enable_dmc = false;
227+
enable_checkpoint = false;
220228
enable_vswitch_controller = false;
221229
regular_nag_dialog = true;
222230
}
@@ -239,7 +247,8 @@ let rec restrictions_of_sku = function
239247
enable_wlb = true;
240248
enable_rbac = true;
241249
enable_dmc = true;
242-
enable_vswitch_controller = true;
250+
enable_checkpoint = true;
251+
enable_vswitch_controller = true;
243252
regular_nag_dialog = false;
244253
}
245254

@@ -273,5 +282,8 @@ let license_ok_for_rbac ~__context =
273282
let context_ok_for_dmc ~__context =
274283
(get_pool()).enable_dmc
275284

285+
let ok_for_checkpoint () =
286+
(get_pool()).enable_checkpoint
287+
276288
let license_ok_for_dmc ~__context =
277289
(get_pool()).enable_vswitch_controller

ocaml/license/restrictions.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type restrictions = {
4646
enable_wlb : bool; (** enable Workload Balancing (WLB) *)
4747
enable_rbac : bool; (** enable Role-Based Access Control (RBAC) *)
4848
enable_dmc : bool; (** enable Dynamic Memory Control (DMC) *)
49+
enable_checkpoint : bool; (** enable Checkpoint *)
4950
enable_vswitch_controller : bool; (** enable use of a Distributed VSwitch (DVS) Controller *)
5051
restrict_connection : bool; (** not used anymore; perhaps XenCenter does? *)
5152
platform_filter : bool; (** filter platform data on domain create? *)
@@ -87,3 +88,6 @@ val license_ok_for_rbac : __context:'a -> bool
8788
(** Checks whether we are entitled to enable Dynamic Memory Control (DMC)
8889
* in the pool. *)
8990
val context_ok_for_dmc : __context:'a -> bool
91+
92+
(** Checks whether we are entitled to enable checkpoint *)
93+
val ok_for_checkpoint : unit -> bool

ocaml/xapi/xapi_vm.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,18 @@ let revert ~__context ~snapshot =
981981
(* As the checkpoint operation modify the domain state, we take the vm_lock to do not let the event *)
982982
(* thread mess around with that. *)
983983
let checkpoint ~__context ~vm ~new_name =
984-
Local_work_queue.wait_in_line Local_work_queue.long_running_queue
985-
(Printf.sprintf "VM.checkpoint %s" (Context.string_of_task __context))
986-
(fun () ->
987-
TaskHelper.set_cancellable ~__context;
988-
Locking_helpers.with_lock vm
989-
(fun token () -> Xapi_vm_snapshot.checkpoint ~__context ~vm ~new_name)
990-
()
991-
)
984+
if not (Restrictions.ok_for_checkpoint ()) then
985+
raise (Api_errors.Server_error(Api_errors.license_restriction, []))
986+
else begin
987+
Local_work_queue.wait_in_line Local_work_queue.long_running_queue
988+
(Printf.sprintf "VM.checkpoint %s" (Context.string_of_task __context))
989+
(fun () ->
990+
TaskHelper.set_cancellable ~__context;
991+
Locking_helpers.with_lock vm
992+
(fun token () -> Xapi_vm_snapshot.checkpoint ~__context ~vm ~new_name)
993+
()
994+
)
995+
end
992996

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

0 commit comments

Comments
 (0)