Skip to content

Commit c542cf1

Browse files
thomassagaborigloi
authored andcommitted
CP-24903: Network.pool_introduce: purposes param
Give the Network.pool_introduce function a purposes parameter to enable network purpose preservation on pool-join. Add logic on pool-join to check whether the network purposes are compatible. Signed-off-by: Thomas Sanders <[email protected]>
1 parent 7ea22da commit c542cf1

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

ocaml/idl/datamodel.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,6 +5192,13 @@ let network_attach = call
51925192
~allowed_roles:_R_POOL_OP
51935193
()
51945194

5195+
let network_purpose = Enum ("network_purpose", [
5196+
"nbd", "Network Block Device service using TLS";
5197+
"insecure_nbd", "Network Block Device service without integrity or confidentiality: NOT RECOMMENDED";
5198+
(* We should (re-)add other purposes as and when we write code with behaviour that depends on them,
5199+
* e.g. management, storage, guest, himn... unmanaged? *)
5200+
])
5201+
51955202
let network_introduce_params first_rel =
51965203
[
51975204
{param_type=String; param_name="name_label"; param_doc=""; param_release=first_rel; param_default=None};
@@ -5200,6 +5207,7 @@ let network_introduce_params first_rel =
52005207
{param_type=Map(String,String); param_name="other_config"; param_doc=""; param_release=first_rel; param_default=None};
52015208
{param_type=String; param_name="bridge"; param_doc=""; param_release=first_rel; param_default=None};
52025209
{param_type=Bool; param_name="managed"; param_doc=""; param_release=falcon_release; param_default=None};
5210+
{param_type=Set(network_purpose); param_name="purposes"; param_doc=""; param_release=inverness_release; param_default=None};
52035211
]
52045212

52055213
(* network pool introduce is used to copy network records on pool join -- it's the network analogue of VDI/PIF.pool_introduce *)
@@ -5263,13 +5271,6 @@ let network_detach_for_vm = call
52635271
~allowed_roles:_R_VM_POWER_ADMIN
52645272
()
52655273

5266-
let network_purpose = Enum ("network_purpose", [
5267-
"nbd", "Network Block Device service using TLS";
5268-
"insecure_nbd", "Network Block Device service without integrity or confidentiality: NOT RECOMMENDED";
5269-
(* We should (re-)add other purposes as and when we write code with behaviour that depends on them,
5270-
* e.g. management, storage, guest, himn... unmanaged? *)
5271-
])
5272-
52735274
let network_add_purpose = call
52745275
~name:"add_purpose"
52755276
~doc:"Give a network a new purpose (if not present already)"

ocaml/xapi/test_common.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ let make_pif ~__context ~network ~host ?(device="eth0") ?(mAC="C0:FF:EE:C0:FF:EE
162162
~ipv6_configuration_mode ~iPv6 ~ipv6_gateway ~primary_address_type ~managed ~properties
163163

164164
let make_network ~__context ?(name_label="net") ?(name_description="description") ?(mTU=1500L)
165-
?(other_config=[]) ?(bridge="xenbr0") ?(managed=true) () =
166-
Xapi_network.pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge ~managed
165+
?(other_config=[]) ?(bridge="xenbr0") ?(managed=true) ?(purposes=[]) () =
166+
Xapi_network.pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge ~managed ~purposes
167167

168168
let make_vif ~__context ?(ref=Ref.make ()) ?(uuid=make_uuid ())
169169
?(current_operations=[]) ?(allowed_operations=[]) ?(reserved=false)

ocaml/xapi/xapi_network.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ let counter = ref 0
185185
let mutex = Mutex.create ()
186186
let stem = "xapi"
187187

188-
let pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge ~managed =
188+
let pool_introduce ~__context ~name_label ~name_description ~mTU ~other_config ~bridge ~managed ~purposes =
189189
let r = Ref.make() and uuid = Uuid.make_uuid() in
190190
Db.Network.create ~__context ~ref:r ~uuid:(Uuid.to_string uuid)
191-
~current_operations:[] ~allowed_operations:[] ~purposes:[]
191+
~current_operations:[] ~allowed_operations:[] ~purposes
192192
~name_label ~name_description ~mTU ~bridge ~managed
193193
~other_config ~blobs:[] ~tags:[] ~default_locking_mode:`unlocked ~assigned_ips:[];
194194
r

ocaml/xapi/xapi_network.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ val pool_introduce :
7272
mTU:int64 ->
7373
other_config:(string * string) list ->
7474
bridge:string ->
75-
managed:bool -> [ `network ] Ref.t
75+
managed:bool ->
76+
purposes:API.network_purpose list ->
77+
[ `network ] Ref.t
7678

7779
(** Attempt to create a bridge with a unique name *)
7880
val create :

ocaml/xapi/xapi_pool.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,22 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
423423
raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["Primary address type differs"]));
424424
in
425425

426+
let assert_compatible_network_purposes () = try (
427+
let my_nbdish =
428+
Db.Network.get_all ~__context |>
429+
List.map (fun nwk -> Db.Network.get_purposes ~__context ~self:nwk) |>
430+
List.flatten |>
431+
List.find (function `nbd | `insecure_nbd -> true | _ -> false) in
432+
let remote_nbdish =
433+
Client.Network.get_all rpc session_id |>
434+
List.map (fun nwk -> Client.Network.get_purposes ~rpc ~session_id ~self:nwk) |>
435+
List.flatten |>
436+
List.find (function `nbd | `insecure_nbd -> true | _ -> false) in
437+
if remote_nbdish <> my_nbdish then
438+
raise Api_errors.(Server_error(operation_not_allowed, ["Incompatible network purposes: nbd and insecure_nbd"]))
439+
) with Not_found -> () (* If either side has no network with nbd-related purpose, then no problem. *)
440+
in
441+
426442
(* call pre-join asserts *)
427443
assert_pool_size_unrestricted ();
428444
assert_management_interface_exists ();
@@ -446,7 +462,8 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
446462
assert_api_version_matches ();
447463
assert_db_schema_matches ();
448464
assert_homogeneous_updates ();
449-
assert_homogeneous_primary_address_type ()
465+
assert_homogeneous_primary_address_type ();
466+
assert_compatible_network_purposes ()
450467

451468
let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) : API.ref_host =
452469
let my_uuid = host.API.host_uuid in
@@ -638,6 +655,7 @@ let create_or_get_network_on_master __context rpc session_id (network_ref, netwo
638655
~other_config:network.API.network_other_config
639656
~bridge:network.API.network_bridge
640657
~managed:network.API.network_managed
658+
~purposes:network.API.network_purposes
641659
else begin
642660
debug "Recreating network '%s' as internal network." network.API.network_name_label;
643661
(* This call will generate a new 'xapi#' bridge name rather than keeping the

0 commit comments

Comments
 (0)