Skip to content

Commit b280fb0

Browse files
committed
CP-1158: Add a pool first-class field for the nicera vswitch controller address.
This field is checked by xapi to be consistent on pool-join, and it is cleared by the plugin on pool-eject. To set it: xe pool-set-vswitch-controller address=<IP address> Seems to work on my limited dev-tests, need to make more tests later. Signed-off-by: Ian Campbell <[email protected]>
1 parent c553bc6 commit b280fb0

File tree

10 files changed

+76
-4
lines changed

10 files changed

+76
-4
lines changed

ocaml/client_records/records.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ let pool_record rpc session_id pool =
410410
~remove_from_map:(fun k -> Client.Pool.remove_from_gui_config rpc session_id pool k)
411411
~get_map:(fun () -> (x ()).API.pool_gui_config)
412412
~expensive:true ();
413+
make_field ~name:"vswitch-controller" ~hidden:true ~get:(fun () -> let r = (x ()).API.pool_vswitch_controller in if r = "" then "<not set>" else r) ()
413414
]}
414415

415416
let subject_record rpc session_id subject =

ocaml/idl/datamodel.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Datamodel_types
1818
(* IMPORTANT: Please bump schema vsn if you change/add/remove a _field_.
1919
You do not have to bump vsn if you change/add/remove a message *)
2020
let schema_major_vsn = 5
21-
let schema_minor_vsn = 59
21+
let schema_minor_vsn = 60
2222

2323
(* Historical schema versions just in case this is useful later *)
2424
let rio_schema_major_vsn = 5
@@ -4987,6 +4987,15 @@ let pool_audit_log_append = call
49874987
~allowed_roles:_R_POOL_ADMIN
49884988
()
49894989

4990+
let pool_set_vswitch_controller = call
4991+
~in_oss_since:None
4992+
~in_product_since:rel_midnight_ride
4993+
~name:"set_vswitch_controller"
4994+
~params:[String, "address", "IP address of the vswitch controller."]
4995+
~doc:"Set the IP address of the vswitch controller."
4996+
~allowed_roles:_R_POOL_OP
4997+
()
4998+
49904999
(** A pool class *)
49915000
let pool =
49925001
create_obj
@@ -5047,6 +5056,7 @@ let pool =
50475056
; pool_enable_redo_log
50485057
; pool_disable_redo_log
50495058
; pool_audit_log_append
5059+
; pool_set_vswitch_controller
50505060
]
50515061
~contents:
50525062
[uid ~in_oss_since:None _pool
@@ -5074,6 +5084,7 @@ let pool =
50745084
; field ~in_product_since:rel_george ~qualifier:RW ~ty:Bool ~default_value:(Some (VBool false)) "wlb_verify_cert" "true if communication with the WLB server should enforce SSL certificate verification."
50755085
; field ~in_oss_since:None ~in_product_since:rel_midnight_ride ~qualifier:DynamicRO ~ty:Bool ~default_value:(Some (VBool false)) "redo_log_enabled" "true a redo-log is to be used other than when HA is enabled, false otherwise"
50765086
; field ~in_oss_since:None ~in_product_since:rel_midnight_ride ~qualifier:DynamicRO ~ty:(Ref _vdi) ~default_value:(Some (VRef (Ref.string_of Ref.null))) "redo_log_vdi" "indicates the VDI to use for the redo-log other than when HA is enabled"
5087+
; field ~in_oss_since:None ~in_product_since:rel_midnight_ride ~qualifier:DynamicRO ~ty:String ~default_value:(Some (VString "")) "vswitch_controller" "address of the vswitch controller"
50775088
]
50785089
()
50795090

ocaml/xapi/cli_frontend.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ let rec cmdtable_data : (string*cmd_spec) list =
387387
flags=[];
388388
};
389389

390+
"pool-set-vswitch-controller",
391+
{
392+
reqd=["address"];
393+
optn=[];
394+
help="Set the IP address of the vswitch controller.";
395+
implementation= No_fd Cli_operations.pool_set_vswitch_controller;
396+
flags=[Hidden];
397+
};
398+
390399
"host-is-in-emergency-mode",
391400
{
392401
reqd=[];

ocaml/xapi/cli_operations.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ let pool_enable_redo_log printer rpc session_id params =
974974
let pool_disable_redo_log printer rpc session_id params =
975975
Client.Pool.disable_redo_log ~rpc ~session_id
976976

977+
let pool_set_vswitch_controller printer rpc session_id params =
978+
let address = List.assoc "address" params in
979+
Client.Pool.set_vswitch_controller ~rpc ~session_id ~address
980+
977981
let vdi_type_of_string = function
978982
| "system" -> `system
979983
| "user" -> `user

ocaml/xapi/dbsync_master.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let create_pool_record ~__context =
3333
~ha_enabled:false ~ha_configuration:[] ~ha_statefiles:[]
3434
~ha_host_failures_to_tolerate:0L ~ha_plan_exists_for:0L ~ha_allow_overcommit:false ~ha_overcommitted:false ~blobs:[] ~tags:[] ~gui_config:[]
3535
~wlb_url:"" ~wlb_username:"" ~wlb_password:Ref.null ~wlb_enabled:false ~wlb_verify_cert:false
36-
~redo_log_enabled:false ~redo_log_vdi:Ref.null
36+
~redo_log_enabled:false ~redo_log_vdi:Ref.null ~vswitch_controller:""
3737
~other_config:[
3838
Xapi_globs.memory_ratio_hvm;
3939
Xapi_globs.memory_ratio_pv;

ocaml/xapi/helpers.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,17 @@ let remove_other_keys table valid_keys =
806806
let keys = Hashtbl.fold (fun k v acc -> k :: acc) table [] in
807807
List.iter (fun k -> if not (List.mem k valid_keys) then Hashtbl.remove table k) keys
808808

809+
let update_vswitch_controller ~__context ~host =
810+
try call_api_functions ~__context (fun rpc session_id ->
811+
let result = Client.Client.Host.call_plugin ~rpc ~session_id ~host ~plugin:"vswitch-cfg-update" ~fn:"update" ~args:[] in
812+
debug "vswitch-cfg-update(on %s): %s"
813+
(Db.Host.get_name_label ~__context ~self:host)
814+
result)
815+
with e ->
816+
debug "Got '%s' while trying to update the vswitch configuration on host %s"
817+
(Printexc.to_string e)
818+
(Db.Host.get_name_label ~__context ~self:host)
819+
809820
let set_vm_uncooperative ~__context ~self ~value =
810821
let current_value =
811822
let oc = Db.VM.get_other_config ~__context ~self in

ocaml/xapi/message_forwarding.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
555555
info "Pool.disable_redo_log: pool = '%s'" (current_pool_uuid ~__context);
556556
Local.Pool.disable_redo_log ~__context
557557

558+
let set_vswitch_controller ~__context ~address =
559+
info "Pool.set_vswitch_controller: pool = '%s'; address = '%s'" (current_pool_uuid ~__context) address;
560+
Local.Pool.set_vswitch_controller ~__context ~address
558561
end
559562

560563
module VM = struct

ocaml/xapi/xapi.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ let server_init() =
835835
"considering executing on-master-start script", [],
836836
(fun () -> Xapi_pool_transition.run_external_scripts (Pool_role.is_master ()));
837837
"creating networks", [ Startup.OnlyMaster ], Create_networks.create_networks_localhost;
838+
"updating the vswitch controller", [], (fun () -> Helpers.update_vswitch_controller ~__context ~host:(Helpers.get_localhost ~__context));
838839
(* CA-22417: bring up all non-bond slaves so that the SM backends can use storage NIC IP addresses (if the routing
839840
table happens to be right) *)
840841
"Best-effort bring up of physical NICs", [ Startup.NoExnRaising ], Xapi_pif.start_of_day_best_effort_bring_up;

ocaml/xapi/xapi_pool.ml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
224224
if master_uuid = my_uuid then
225225
raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["Host cannot become slave of itself"])) in
226226

227+
let assert_homogeneous_vswitch_configuration () =
228+
match Netdev.network.Netdev.kind with
229+
| Netdev.Vswitch ->
230+
let my_pool = Helpers.get_pool __context in
231+
let my_controller = Db.Pool.get_vswitch_controller ~__context ~self:my_pool in
232+
let pool = List.hd (Client.Pool.get_all rpc session_id) in
233+
let controller = Client.Pool.get_vswitch_controller ~rpc ~session_id ~self:pool in
234+
if my_controller <> controller then
235+
raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["vswitch controller address differs"]))
236+
| _ -> ()
237+
in
238+
227239
(* call pre-join asserts *)
228240
ha_is_not_enable_on_me ();
229241
ha_is_not_enable_on_the_distant_pool ();
@@ -235,7 +247,8 @@ let pre_join_checks ~__context ~rpc ~session_id ~force =
235247
assert_no_shared_srs_on_me ();
236248
assert_management_interface_is_physical ();
237249
assert_external_auth_matches ();
238-
assert_restrictions_match ()
250+
assert_restrictions_match ();
251+
assert_homogeneous_vswitch_configuration ()
239252

240253
let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) : API.ref_host =
241254
let my_uuid = host.API.host_uuid in
@@ -1336,7 +1349,24 @@ let disable_redo_log ~__context =
13361349
end;
13371350
end;
13381351
info "The redo log is now disabled"
1339-
1352+
1353+
let assert_is_valid_ip ip_addr =
1354+
if ip_addr <> "" then
1355+
try Unix.inet_addr_of_string ip_addr; ()
1356+
with _ -> raise (Api_errors.Server_error (Api_errors.invalid_ip_address_specified, [ "address" ]))
1357+
1358+
let set_vswitch_controller ~__context ~address =
1359+
match Netdev.network.Netdev.kind with
1360+
| Netdev.Vswitch ->
1361+
let pool = Helpers.get_pool ~__context in
1362+
let current_address = Db.Pool.get_vswitch_controller ~__context ~self:pool in
1363+
if current_address <> address then begin
1364+
assert_is_valid_ip address;
1365+
Db.Pool.set_vswitch_controller ~__context ~self:pool ~value:address;
1366+
List.iter (fun host -> Helpers.update_vswitch_controller ~__context ~host) (Db.Host.get_all ~__context)
1367+
end
1368+
| _ -> raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["host not configured for vswitch operation"]))
1369+
13401370

13411371
(* internal intra-pool call to allow slaves to log http actions on the master *)
13421372
let audit_log_append ~__context ~line =

ocaml/xapi/xapi_pool.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,6 @@ val enable_redo_log : __context:Context.t -> sr:[`SR] Ref.t -> unit
189189
(** Disable HA-independent redo log *)
190190
val disable_redo_log : __context:Context.t -> unit
191191

192+
(** VSwitch Controller *)
193+
val set_vswitch_controller : __context:Context.t -> address:string -> unit
192194
val audit_log_append : __context:Context.t -> line:string -> unit

0 commit comments

Comments
 (0)