Skip to content

Commit 4921d12

Browse files
committed
CP-5095:Retrieve a list of SRs required to recover a VM through xapi
Signed-off-by: Akshay Ramani <[email protected]>
1 parent e5af7b3 commit 4921d12

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

ocaml/idl/datamodel.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,17 @@ let vm_assert_can_be_recovered = call
22242224
~allowed_roles:_R_READ_ONLY
22252225
()
22262226

2227+
let vm_required_list_of_SRs = call
2228+
~name:"required_list_of_SRs"
2229+
~in_product_since:rel_clearwater
2230+
~doc:"List all the SR's that are required for the VM to be recovered"
2231+
~params:[Ref _vm , "self" , "The VM for which the SRs have to be recovered";
2232+
Ref _session , "session_to" , "The session to which the SRs of the VM have to be recovered."]
2233+
~result:(Set(Ref _sr),"refs for SRs required to recover the VM")
2234+
~errs:[Api_errors.vm_requires_sr]
2235+
~allowed_roles:_R_READ_ONLY
2236+
()
2237+
22272238
let vm_recover = call
22282239
~name:"recover"
22292240
~in_product_since:rel_boston
@@ -6696,6 +6707,7 @@ let vm =
66966707
vm_set_order;
66976708
vm_set_suspend_VDI;
66986709
vm_assert_can_be_recovered;
6710+
vm_required_list_of_SRs;
66996711
vm_recover;
67006712
vm_import_convert;
67016713
vm_set_appliance;

ocaml/xapi/message_forwarding.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,10 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
19421942
info "VM.assert_can_be_recovered: self = '%s';" (vm_uuid ~__context self);
19431943
Local.VM.assert_can_be_recovered ~__context ~self ~session_to
19441944

1945+
let required_list_of_SRs ~__context ~self ~session_to =
1946+
info "VM.required_list_of_SRs: self = '%s';" (vm_uuid ~__context self);
1947+
Local.VM.required_list_of_SRs ~__context ~self ~session_to
1948+
19451949
let recover ~__context ~self ~session_to ~force =
19461950
info "VM.recover: self = '%s'; force = %b;" (vm_uuid ~__context self) force;
19471951
(* If a VM is part of an appliance, the appliance *)

ocaml/xapi/xapi_vm.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,9 @@ let set_order ~__context ~self ~value =
778778
let assert_can_be_recovered ~__context ~self ~session_to =
779779
Xapi_vm_helpers.assert_can_be_recovered ~__context ~self ~session_to
780780

781+
let required_list_of_SRs ~__context ~self ~session_to =
782+
Xapi_vm_helpers.required_list_of_SRs ~__context ~self ~session_to
783+
781784
let recover ~__context ~self ~session_to ~force =
782785
Xapi_dr.assert_session_allows_dr ~session_id:session_to ~action:"VM.recover";
783786
(* Check the VM SRs are available. *)

ocaml/xapi/xapi_vm.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ val set_shutdown_delay : __context:Context.t -> self:API.ref_VM -> value:int64 -
229229
val set_order : __context:Context.t -> self:API.ref_VM -> value:int64 -> unit
230230

231231
val assert_can_be_recovered : __context:Context.t -> self:API.ref_VM -> session_to:API.ref_session -> unit
232+
val required_list_of_SRs : __context:Context.t -> self:API.ref_VM -> session_to:API.ref_session ->API.ref_SR list
232233
val recover : __context:Context.t -> self:API.ref_VM ->
233234
session_to:API.ref_session -> force:bool -> unit
234235
val set_suspend_VDI : __context:Context.t -> self:API.ref_VM ->

ocaml/xapi/xapi_vm_helpers.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,23 @@ let assert_can_be_recovered ~__context ~self ~session_to =
767767
raise (Api_errors.Server_error(Api_errors.vm_requires_sr,
768768
[Ref.string_of self; Ref.string_of sr]))
769769

770+
let required_list_of_SRs ~__context ~self ~session_to =
771+
let required_SR_list = list_required_SRs ~__context ~self in
772+
try
773+
Server_helpers.exec_with_new_task ~session_id:session_to
774+
"Looking for the required SRs"
775+
(fun __context_to -> List.filter
776+
( fun sr_ref ->
777+
let pbds = Db.SR.get_PBDs ~__context:__context_to ~self:sr_ref in
778+
let attached_pbds = List.filter
779+
(fun pbd -> Db.PBD.get_currently_attached ~__context:__context_to ~self:pbd)
780+
pbds
781+
in
782+
if attached_pbds = [] then true else false
783+
)
784+
required_SR_list)
785+
with e -> raise e;;
786+
770787
(* BIOS strings *)
771788

772789
let copy_bios_strings ~__context ~vm ~host =

0 commit comments

Comments
 (0)