From 51f2c711924fb677bceed3fd39098e3753c54a96 Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Mon, 23 Aug 2010 13:23:54 +0100 Subject: [PATCH] Add host.reset_networking API call This call purges all network-related metadata associated with the given host (PIFs, VLANs, bonds, tunnels). This call is used by the emergency network reset functionality. It should normally not be used directly, and is hidden from the API docs. Signed-off-by: Rob Hoes --- ocaml/idl/datamodel.ml | 14 +++++++++++--- ocaml/xapi/message_forwarding.ml | 4 ++++ ocaml/xapi/xapi_host.ml | 24 ++++++++++++++++++++++++ ocaml/xapi/xapi_host.mli | 3 +++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ocaml/idl/datamodel.ml b/ocaml/idl/datamodel.ml index d0bbd290..adee5c3e 100644 --- a/ocaml/idl/datamodel.ml +++ b/ocaml/idl/datamodel.ml @@ -2503,7 +2503,7 @@ let host_refresh_pack_info = call ~params:[Ref _host, "host", "The Host to modify"] ~allowed_roles:_R_POOL_OP () - + (* ------------------------------------------------------------------------------------------------------------ VDI Management ------------------------------------------------------------------------------------------------------------ *) @@ -3576,7 +3576,6 @@ let host_apply_edition = call ~flags:[`Session] ~allowed_roles:_R_POOL_OP () - let host_set_power_on_mode = call ~name:"set_power_on_mode" ~in_product_since:rel_midnight_ride @@ -3609,6 +3608,15 @@ let host_reset_cpu_features = call ~flags:[`Session] ] ~allowed_roles:_R_POOL_OP () + +let host_reset_networking = call + ~name:"reset_networking" + ~lifecycle:[] + ~doc:"Purge all network-related metadata associated with the given host." + ~params:[Ref _host, "host", "The Host to modify"] + ~allowed_roles:_R_POOL_OP + ~hide_from_docs:true + () (** Hosts *) let host = @@ -3681,6 +3689,7 @@ let host = host_set_power_on_mode; host_set_cpu_features; host_reset_cpu_features; + host_reset_networking; ] ~contents: ([ uid _host; @@ -3991,7 +4000,6 @@ let pif_db_introduce = call ~allowed_roles:_R_POOL_OP () - let pif_db_forget = call ~name:"db_forget" ~in_oss_since:None diff --git a/ocaml/xapi/message_forwarding.ml b/ocaml/xapi/message_forwarding.ml index ecf03d9a..3f801fef 100644 --- a/ocaml/xapi/message_forwarding.ml +++ b/ocaml/xapi/message_forwarding.ml @@ -2168,6 +2168,10 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct info "Host.reset_cpu_features: host = '%s'" (host_uuid ~__context host); let local_fn = Local.Host.reset_cpu_features ~host in do_op_on ~local_fn ~__context ~host (fun session_id rpc -> Client.Host.reset_cpu_features rpc session_id host) + + let reset_networking ~__context ~host = + info "Host.reset_networking: host = '%s'" (host_uuid ~__context host); + Local.Host.reset_networking ~__context ~host end module Host_crashdump = struct diff --git a/ocaml/xapi/xapi_host.ml b/ocaml/xapi/xapi_host.ml index 160b9c67..49455141 100644 --- a/ocaml/xapi/xapi_host.ml +++ b/ocaml/xapi/xapi_host.ml @@ -1272,6 +1272,30 @@ let refresh_pack_info ~__context ~host = debug "Refreshing software_version"; let software_version = Create_misc.make_software_version () in Db.Host.set_software_version ~__context ~self:host ~value:software_version + +let reset_networking ~__context ~host = + debug "Resetting networking"; + let local_pifs = List.filter (fun pif -> Db.PIF.get_host ~__context ~self:pif = host) (Db.PIF.get_all ~__context) in + let bond_is_local bond = + List.fold_left (fun a pif -> Db.Bond.get_master ~__context ~self:bond = pif || a) false local_pifs + in + let vlan_is_local vlan = + List.fold_left (fun a pif -> Db.VLAN.get_untagged_PIF ~__context ~self:vlan = pif || a) false local_pifs + in + let tunnel_is_local tunnel = + List.fold_left (fun a pif -> Db.Tunnel.get_access_PIF ~__context ~self:tunnel = pif || a) false local_pifs + in + let bonds = List.filter bond_is_local (Db.Bond.get_all ~__context) in + List.iter (fun bond -> debug "destroying bond %s" (Db.Bond.get_uuid ~__context ~self:bond); + Db.Bond.destroy ~__context ~self:bond) bonds; + let vlans = List.filter vlan_is_local (Db.VLAN.get_all ~__context) in + List.iter (fun vlan -> debug "destroying VLAN %s" (Db.VLAN.get_uuid ~__context ~self:vlan); + Db.VLAN.destroy ~__context ~self:vlan) vlans; + let tunnels = List.filter tunnel_is_local (Db.Tunnel.get_all ~__context) in + List.iter (fun tunnel -> debug "destroying tunnel %s" (Db.Tunnel.get_uuid ~__context ~self:tunnel); + Db.Tunnel.destroy ~__context ~self:tunnel) tunnels; + List.iter (fun pif -> debug "destroying PIF %s" (Db.PIF.get_uuid ~__context ~self:pif); + Db.PIF.destroy ~__context ~self:pif) local_pifs let set_cpu_features ~__context ~host ~features = debug "Set CPU features"; diff --git a/ocaml/xapi/xapi_host.mli b/ocaml/xapi/xapi_host.mli index a1848903..59727a5d 100644 --- a/ocaml/xapi/xapi_host.mli +++ b/ocaml/xapi/xapi_host.mli @@ -251,3 +251,6 @@ val set_cpu_features : __context:Context.t -> host:API.ref_host -> features:stri (** Remove the feature mask, such that after a reboot all features of the CPU are enabled. *) val reset_cpu_features : __context:Context.t -> host:API.ref_host -> unit +(** Purge all network-related metadata associated with the given host. *) +val reset_networking : __context:Context.t -> host:API.ref_host -> unit + -- 2.39.5