Skip to content

Commit

Permalink
CP-3442: Allow disabling of VIFs without a license check.
Browse files Browse the repository at this point in the history
Also remove some of the checks for a vswitch controller - we only really
need to check for this when locking or disabling a VIF, not when adding
or removing IP addresses.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information
johnelse committed May 11, 2012
1 parent 3eaa057 commit afeec48
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions ocaml/xapi/xapi_vif.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ let assert_locking_licensed ~__context =
if (not (Pool_features.is_enabled ~__context Features.VIF_locking)) then if (not (Pool_features.is_enabled ~__context Features.VIF_locking)) then
raise (Api_errors.Server_error(Api_errors.license_restriction, [])) raise (Api_errors.Server_error(Api_errors.license_restriction, []))


let change_locking_config ~__context ~self ~run_prechecks f = let change_locking_config ~__context ~self ~licence_check f =
(* If turning the feature "on", we should check that the feature is licensed *) if licence_check then assert_locking_licensed ~__context;
(* and that there is no vswitch controller active. *)
if run_prechecks then begin
assert_locking_licensed ~__context;
Helpers.assert_vswitch_controller_not_active ~__context
end;
f (); f ();
refresh_filtering_rules ~__context ~self refresh_filtering_rules ~__context ~self


let set_locking_mode ~__context ~self ~value = let set_locking_mode ~__context ~self ~value =
change_locking_config ~__context ~self ~run_prechecks:(value <> `network_default) let effective_locking_mode : API.vif_locking_mode =
match value with
| `network_default ->
let network = Db.VIF.get_network ~__context ~self in
Db.Network.get_default_locking_mode ~__context ~self:network
| other -> other
in
if effective_locking_mode <> `unlocked then
Helpers.assert_vswitch_controller_not_active ~__context;
change_locking_config ~__context ~self
~licence_check:(effective_locking_mode = `locked)
(fun () -> Db.VIF.set_locking_mode ~__context ~self ~value) (fun () -> Db.VIF.set_locking_mode ~__context ~self ~value)


let assert_ip_address_is domain field_name addr = let assert_ip_address_is domain field_name addr =
Expand All @@ -85,34 +90,34 @@ let assert_ip_address_is domain field_name addr =


let set_ipv4_allowed ~__context ~self ~value = let set_ipv4_allowed ~__context ~self ~value =
let setified_value = List.setify value in let setified_value = List.setify value in
change_locking_config ~__context ~self ~run_prechecks:(setified_value <> []) change_locking_config ~__context ~self ~licence_check:(setified_value <> [])
(fun () -> (fun () ->
List.iter (assert_ip_address_is Unix.PF_INET "ipv4_allowed") setified_value; List.iter (assert_ip_address_is Unix.PF_INET "ipv4_allowed") setified_value;
Db.VIF.set_ipv4_allowed ~__context ~self ~value:setified_value) Db.VIF.set_ipv4_allowed ~__context ~self ~value:setified_value)


let add_ipv4_allowed ~__context ~self ~value = let add_ipv4_allowed ~__context ~self ~value =
change_locking_config ~__context ~self ~run_prechecks:true change_locking_config ~__context ~self ~licence_check:true
(fun () -> (fun () ->
assert_ip_address_is Unix.PF_INET "ipv4_allowed" value; assert_ip_address_is Unix.PF_INET "ipv4_allowed" value;
Db.VIF.add_ipv4_allowed ~__context ~self ~value) Db.VIF.add_ipv4_allowed ~__context ~self ~value)


let remove_ipv4_allowed ~__context ~self ~value = let remove_ipv4_allowed ~__context ~self ~value =
change_locking_config ~__context ~self ~run_prechecks:false change_locking_config ~__context ~self ~licence_check:false
(fun () -> Db.VIF.remove_ipv4_allowed ~__context ~self ~value) (fun () -> Db.VIF.remove_ipv4_allowed ~__context ~self ~value)


let set_ipv6_allowed ~__context ~self ~value = let set_ipv6_allowed ~__context ~self ~value =
let setified_value = List.setify value in let setified_value = List.setify value in
change_locking_config ~__context ~self ~run_prechecks:(setified_value <> []) change_locking_config ~__context ~self ~licence_check:(setified_value <> [])
(fun () -> (fun () ->
List.iter (assert_ip_address_is Unix.PF_INET6 "ipv6_allowed") setified_value; List.iter (assert_ip_address_is Unix.PF_INET6 "ipv6_allowed") setified_value;
Db.VIF.set_ipv6_allowed ~__context ~self ~value:setified_value) Db.VIF.set_ipv6_allowed ~__context ~self ~value:setified_value)


let add_ipv6_allowed ~__context ~self ~value = let add_ipv6_allowed ~__context ~self ~value =
change_locking_config ~__context ~self ~run_prechecks:true change_locking_config ~__context ~self ~licence_check:true
(fun () -> (fun () ->
assert_ip_address_is Unix.PF_INET6 "ipv6_allowed" value; assert_ip_address_is Unix.PF_INET6 "ipv6_allowed" value;
Db.VIF.add_ipv6_allowed ~__context ~self ~value) Db.VIF.add_ipv6_allowed ~__context ~self ~value)


let remove_ipv6_allowed ~__context ~self ~value = let remove_ipv6_allowed ~__context ~self ~value =
change_locking_config ~__context ~self ~run_prechecks:false change_locking_config ~__context ~self ~licence_check:false
(fun () -> Db.VIF.remove_ipv4_allowed ~__context ~self ~value) (fun () -> Db.VIF.remove_ipv4_allowed ~__context ~self ~value)

0 comments on commit afeec48

Please sign in to comment.