Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ocaml/xapi/xapi_cluster_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,12 @@ let disable ~__context ~self =
Db.Cluster_host.set_enabled ~__context ~self ~value:false
| Result.Error error -> handle_error error
)

let disable_clustering ~__context =
let host = Helpers.get_localhost ~__context in
match Xapi_clustering.find_cluster_host ~__context ~host with
| None -> info "No cluster host found"
| Some self ->
info "Disabling cluster host";
disable ~__context ~self

5 changes: 5 additions & 0 deletions ocaml/xapi/xapi_cluster_host.mli
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ val disable : __context:Context.t -> self:API.ref_Cluster_host -> unit
(** [disable ~__context ~self] is the implementation of the XenAPI call
'Cluster_host.disable'. It will call xapi-clusterd and ask it to leave the
cluster. This requires all cluster members to be online. *)

val disable_clustering : __context:Context.t -> unit
(** [disable_clustering ~__context] is a wrapper for Xapi_cluster_host.disable
which finds the local cluster_host [self], calls [disable ~__context self]
and logs its actions. *)
1 change: 1 addition & 0 deletions ocaml/xapi/xapi_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ let prepare_for_poweroff ~__context ~host =

Xapi_ha.before_clean_shutdown_or_reboot ~__context ~host;
Xapi_pbd.unplug_all_pbds ~__context;
Xapi_cluster_host.disable_clustering ~__context;

if not i_am_master then
Remote_requests.stop_request_thread();
Expand Down
14 changes: 5 additions & 9 deletions ocaml/xapi/xapi_pbd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ let get_locally_attached ~__context =
Eq (Field "host", Literal (Ref.string_of host)),
Eq (Field "currently_attached", Literal "true"))))

(* Called on shutdown: it unplugs all the PBDs and disables the cluster host.
If anything fails it throws an exception *)
(* Host calls unplug_all_pbds on shutdown,
* followed by Xapi_cluster_host.disable_clustering.
* Both functions throw exceptions if anything fails *)
let unplug_all_pbds ~__context =
info "Unplugging all SRs plugged on local host";
(* best effort unplug of all PBDs *)
Expand All @@ -247,10 +248,5 @@ let unplug_all_pbds ~__context =
TaskHelper.exn_if_cancelling ~__context;
debug "Unplugging PBD %s" uuid;
unplug ~__context ~self:pbd);
debug "Finished unplug_all_pbds";
let host = Helpers.get_localhost ~__context in
match Xapi_clustering.find_cluster_host ~__context ~host with
| None -> info "No cluster host found"
| Some self ->
info "Disabling cluster host";
Xapi_cluster_host.disable ~__context ~self
debug "Finished unplug_all_pbds"