# HG changeset patch # User Thomas Gazagnaire # Date 1265237162 0 # Node ID d8aa1b08fa3288a638936a19835a0e7b6aa33dff # Parent abcc76c21160383f68ea0ee576bb4ecdf2d0be9a 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= Seems to work on my limited dev-tests, need to make more tests later. Signed-off-by: Ian Campbell diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/client_records/records.ml --- a/ocaml/client_records/records.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/client_records/records.ml Wed Feb 03 22:46:02 2010 +0000 @@ -410,6 +410,7 @@ ~remove_from_map:(fun k -> Client.Pool.remove_from_gui_config rpc session_id pool k) ~get_map:(fun () -> (x ()).API.pool_gui_config) ~expensive:true (); + make_field ~name:"vswitch-controller" ~hidden:true ~get:(fun () -> let r = (x ()).API.pool_vswitch_controller in if r = "" then "" else r) () ]} let subject_record rpc session_id subject = diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/idl/datamodel.ml --- a/ocaml/idl/datamodel.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/idl/datamodel.ml Wed Feb 03 22:46:02 2010 +0000 @@ -18,7 +18,7 @@ (* IMPORTANT: Please bump schema vsn if you change/add/remove a _field_. You do not have to bump vsn if you change/add/remove a message *) let schema_major_vsn = 5 -let schema_minor_vsn = 59 +let schema_minor_vsn = 60 (* Historical schema versions just in case this is useful later *) let rio_schema_major_vsn = 5 @@ -4987,6 +4987,15 @@ ~allowed_roles:_R_POOL_ADMIN () +let pool_set_vswitch_controller = call + ~in_oss_since:None + ~in_product_since:rel_midnight_ride + ~name:"set_vswitch_controller" + ~params:[String, "address", "IP address of the vswitch controller."] + ~doc:"Set the IP address of the vswitch controller." + ~allowed_roles:_R_POOL_OP + () + (** A pool class *) let pool = create_obj @@ -5047,6 +5056,7 @@ ; pool_enable_redo_log ; pool_disable_redo_log ; pool_audit_log_append + ; pool_set_vswitch_controller ] ~contents: [uid ~in_oss_since:None _pool @@ -5074,6 +5084,7 @@ ; 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." ; 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" ; 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" + ; 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" ] () diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/cli_frontend.ml --- a/ocaml/xapi/cli_frontend.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/cli_frontend.ml Wed Feb 03 22:46:02 2010 +0000 @@ -387,6 +387,15 @@ flags=[]; }; + "pool-set-vswitch-controller", + { + reqd=["address"]; + optn=[]; + help="Set the IP address of the vswitch controller."; + implementation= No_fd Cli_operations.pool_set_vswitch_controller; + flags=[Hidden]; + }; + "host-is-in-emergency-mode", { reqd=[]; diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/cli_operations.ml --- a/ocaml/xapi/cli_operations.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/cli_operations.ml Wed Feb 03 22:46:02 2010 +0000 @@ -974,6 +974,10 @@ let pool_disable_redo_log printer rpc session_id params = Client.Pool.disable_redo_log ~rpc ~session_id +let pool_set_vswitch_controller printer rpc session_id params = + let address = List.assoc "address" params in + Client.Pool.set_vswitch_controller ~rpc ~session_id ~address + let vdi_type_of_string = function | "system" -> `system | "user" -> `user diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/dbsync_master.ml --- a/ocaml/xapi/dbsync_master.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/dbsync_master.ml Wed Feb 03 22:46:02 2010 +0000 @@ -33,7 +33,7 @@ ~ha_enabled:false ~ha_configuration:[] ~ha_statefiles:[] ~ha_host_failures_to_tolerate:0L ~ha_plan_exists_for:0L ~ha_allow_overcommit:false ~ha_overcommitted:false ~blobs:[] ~tags:[] ~gui_config:[] ~wlb_url:"" ~wlb_username:"" ~wlb_password:Ref.null ~wlb_enabled:false ~wlb_verify_cert:false - ~redo_log_enabled:false ~redo_log_vdi:Ref.null + ~redo_log_enabled:false ~redo_log_vdi:Ref.null ~vswitch_controller:"" ~other_config:[ Xapi_globs.memory_ratio_hvm; Xapi_globs.memory_ratio_pv; diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/helpers.ml --- a/ocaml/xapi/helpers.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/helpers.ml Wed Feb 03 22:46:02 2010 +0000 @@ -806,6 +806,17 @@ let keys = Hashtbl.fold (fun k v acc -> k :: acc) table [] in List.iter (fun k -> if not (List.mem k valid_keys) then Hashtbl.remove table k) keys +let update_vswitch_controller ~__context ~host = + try call_api_functions ~__context (fun rpc session_id -> + let result = Client.Client.Host.call_plugin ~rpc ~session_id ~host ~plugin:"vswitch-cfg-update" ~fn:"update" ~args:[] in + debug "vswitch-cfg-update(on %s): %s" + (Db.Host.get_name_label ~__context ~self:host) + result) + with e -> + debug "Got '%s' while trying to update the vswitch configuration on host %s" + (Printexc.to_string e) + (Db.Host.get_name_label ~__context ~self:host) + let set_vm_uncooperative ~__context ~self ~value = let current_value = let oc = Db.VM.get_other_config ~__context ~self in diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/message_forwarding.ml --- a/ocaml/xapi/message_forwarding.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/message_forwarding.ml Wed Feb 03 22:46:02 2010 +0000 @@ -555,6 +555,9 @@ info "Pool.disable_redo_log: pool = '%s'" (current_pool_uuid ~__context); Local.Pool.disable_redo_log ~__context + let set_vswitch_controller ~__context ~address = + info "Pool.set_vswitch_controller: pool = '%s'; address = '%s'" (current_pool_uuid ~__context) address; + Local.Pool.set_vswitch_controller ~__context ~address end module VM = struct diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/xapi.ml --- a/ocaml/xapi/xapi.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/xapi.ml Wed Feb 03 22:46:02 2010 +0000 @@ -835,6 +835,7 @@ "considering executing on-master-start script", [], (fun () -> Xapi_pool_transition.run_external_scripts (Pool_role.is_master ())); "creating networks", [ Startup.OnlyMaster ], Create_networks.create_networks_localhost; + "updating the vswitch controller", [], (fun () -> Helpers.update_vswitch_controller ~__context ~host:(Helpers.get_localhost ~__context)); (* CA-22417: bring up all non-bond slaves so that the SM backends can use storage NIC IP addresses (if the routing table happens to be right) *) "Best-effort bring up of physical NICs", [ Startup.NoExnRaising ], Xapi_pif.start_of_day_best_effort_bring_up; diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/xapi_pool.ml --- a/ocaml/xapi/xapi_pool.ml Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/xapi_pool.ml Wed Feb 03 22:46:02 2010 +0000 @@ -224,6 +224,18 @@ if master_uuid = my_uuid then raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["Host cannot become slave of itself"])) in + let assert_homogeneous_vswitch_configuration () = + match Netdev.network.Netdev.kind with + | Netdev.Vswitch -> + let my_pool = Helpers.get_pool __context in + let my_controller = Db.Pool.get_vswitch_controller ~__context ~self:my_pool in + let pool = List.hd (Client.Pool.get_all rpc session_id) in + let controller = Client.Pool.get_vswitch_controller ~rpc ~session_id ~self:pool in + if my_controller <> controller then + raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["vswitch controller address differs"])) + | _ -> () + in + (* call pre-join asserts *) ha_is_not_enable_on_me (); ha_is_not_enable_on_the_distant_pool (); @@ -235,7 +247,8 @@ assert_no_shared_srs_on_me (); assert_management_interface_is_physical (); assert_external_auth_matches (); - assert_restrictions_match () + assert_restrictions_match (); + assert_homogeneous_vswitch_configuration () let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) : API.ref_host = let my_uuid = host.API.host_uuid in @@ -1336,7 +1349,24 @@ end; end; info "The redo log is now disabled" - + +let assert_is_valid_ip ip_addr = + if ip_addr <> "" then + try Unix.inet_addr_of_string ip_addr; () + with _ -> raise (Api_errors.Server_error (Api_errors.invalid_ip_address_specified, [ "address" ])) + +let set_vswitch_controller ~__context ~address = + match Netdev.network.Netdev.kind with + | Netdev.Vswitch -> + let pool = Helpers.get_pool ~__context in + let current_address = Db.Pool.get_vswitch_controller ~__context ~self:pool in + if current_address <> address then begin + assert_is_valid_ip address; + Db.Pool.set_vswitch_controller ~__context ~self:pool ~value:address; + List.iter (fun host -> Helpers.update_vswitch_controller ~__context ~host) (Db.Host.get_all ~__context) + end + | _ -> raise (Api_errors.Server_error(Api_errors.operation_not_allowed, ["host not configured for vswitch operation"])) + (* internal intra-pool call to allow slaves to log http actions on the master *) let audit_log_append ~__context ~line = diff -r abcc76c21160 -r d8aa1b08fa32 ocaml/xapi/xapi_pool.mli --- a/ocaml/xapi/xapi_pool.mli Wed Feb 03 22:43:37 2010 +0000 +++ b/ocaml/xapi/xapi_pool.mli Wed Feb 03 22:46:02 2010 +0000 @@ -189,4 +189,6 @@ (** Disable HA-independent redo log *) val disable_redo_log : __context:Context.t -> unit +(** VSwitch Controller *) +val set_vswitch_controller : __context:Context.t -> address:string -> unit val audit_log_append : __context:Context.t -> line:string -> unit