-
Notifications
You must be signed in to change notification settings - Fork 292
CA-390277: Reduce record usage on CLI cross-pool migrations #5773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8689af4
c6984ad
caadaf2
ba47a87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4580,68 +4580,58 @@ let vm_migrate printer rpc session_id params = | |
Client.Session.login_with_password ~rpc:remote_rpc ~uname ~pwd | ||
~version:"1.3" ~originator:Constants.xapi_user_agent | ||
in | ||
let remote f = f ~rpc:remote_rpc ~session_id:remote_session in | ||
finally | ||
(fun () -> | ||
let host, host_record = | ||
let all = | ||
Client.Host.get_all_records ~rpc:remote_rpc | ||
~session_id:remote_session | ||
let host = | ||
let expr_match x = | ||
Printf.sprintf | ||
{|(field "hostname"="%s") or (field "name__label"="%s") or (field "uuid"="%s")|} | ||
x x x | ||
in | ||
if List.mem_assoc "host" params then | ||
let x = List.assoc "host" params in | ||
try | ||
List.find | ||
(fun (_, h) -> | ||
h.API.host_hostname = x | ||
|| h.API.host_name_label = x | ||
|| h.API.host_uuid = x | ||
) | ||
all | ||
with Not_found -> | ||
failwith (Printf.sprintf "Failed to find host: %s" x) | ||
else | ||
List.hd all | ||
let expr, fail_msg = | ||
match List.assoc_opt "host" params with | ||
| Some x -> | ||
(expr_match x, Printf.sprintf "Failed to find host: %s" x) | ||
| None -> | ||
("true", Printf.sprintf "Failed to find a suitable host") | ||
in | ||
match remote Client.Host.get_all_where ~expr with | ||
| host :: _ -> | ||
host | ||
| [] -> | ||
failwith fail_msg | ||
in | ||
let network, network_record = | ||
let all = | ||
Client.Network.get_all_records ~rpc:remote_rpc | ||
~session_id:remote_session | ||
let network = | ||
let expr x = | ||
Printf.sprintf | ||
{|(field "bridge"="%s") or (field "name__label"="%s") or (field "uuid"="%s")|} | ||
x x x | ||
in | ||
if List.mem_assoc "remote-network" params then | ||
let x = List.assoc "remote-network" params in | ||
try | ||
List.find | ||
(fun (_, net) -> | ||
net.API.network_bridge = x | ||
|| net.API.network_name_label = x | ||
|| net.API.network_uuid = x | ||
) | ||
all | ||
with Not_found -> | ||
failwith (Printf.sprintf "Failed to find network: %s" x) | ||
else | ||
let pifs = host_record.API.host_PIFs in | ||
let management_pifs = | ||
List.filter | ||
(fun self -> | ||
Client.PIF.get_management ~rpc:remote_rpc | ||
~session_id:remote_session ~self | ||
) | ||
pifs | ||
in | ||
if management_pifs = [] then | ||
failwith | ||
(Printf.sprintf "Could not find management PIF on host %s" | ||
host_record.API.host_uuid | ||
) ; | ||
let pif = List.hd management_pifs in | ||
let net = | ||
Client.PIF.get_network ~rpc:remote_rpc ~session_id:remote_session | ||
~self:pif | ||
in | ||
( net | ||
, Client.Network.get_record ~rpc:remote_rpc | ||
~session_id:remote_session ~self:net | ||
match List.assoc_opt "remote-network" params with | ||
| Some x -> ( | ||
match remote Client.Network.get_all_where ~expr:(expr x) with | ||
| network :: _ -> | ||
network | ||
| [] -> | ||
failwith (Printf.sprintf "Failed to find network: %s" x) | ||
psafont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
| None -> ( | ||
let expr = | ||
psafont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Printf.sprintf | ||
{|(field "host"="%s") and (field "management"="true")|} | ||
Ref.(string_of host) | ||
in | ||
let management_pifs = remote Client.PIF.get_all_where ~expr in | ||
match management_pifs with | ||
| [] -> | ||
let host_uuid = remote Client.Host.get_uuid ~self:host in | ||
failwith | ||
psafont marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(Printf.sprintf "Could not find management PIF on host %s" | ||
host_uuid | ||
) | ||
| pif :: _ -> | ||
remote Client.PIF.get_network ~self:pif | ||
) | ||
in | ||
let vif_map = | ||
|
@@ -4650,10 +4640,7 @@ let vm_migrate printer rpc session_id params = | |
let vif = | ||
Client.VIF.get_by_uuid ~rpc ~session_id ~uuid:vif_uuid | ||
in | ||
let net = | ||
Client.Network.get_by_uuid ~rpc:remote_rpc | ||
~session_id:remote_session ~uuid:net_uuid | ||
in | ||
let net = remote Client.Network.get_by_uuid ~uuid:net_uuid in | ||
(vif, net) | ||
) | ||
(read_map_params "vif" params) | ||
|
@@ -4664,10 +4651,7 @@ let vm_migrate printer rpc session_id params = | |
let vdi = | ||
Client.VDI.get_by_uuid ~rpc ~session_id ~uuid:vdi_uuid | ||
in | ||
let sr = | ||
Client.SR.get_by_uuid ~rpc:remote_rpc ~session_id:remote_session | ||
~uuid:sr_uuid | ||
in | ||
let sr = remote Client.SR.get_by_uuid ~uuid:sr_uuid in | ||
(vdi, sr) | ||
) | ||
(read_map_params "vdi" params) | ||
|
@@ -4679,8 +4663,7 @@ let vm_migrate printer rpc session_id params = | |
Client.VGPU.get_by_uuid ~rpc ~session_id ~uuid:vgpu_uuid | ||
in | ||
let gpu_group = | ||
Client.GPU_group.get_by_uuid ~rpc:remote_rpc | ||
~session_id:remote_session ~uuid:gpu_group_uuid | ||
remote Client.GPU_group.get_by_uuid ~uuid:gpu_group_uuid | ||
in | ||
(vgpu, gpu_group) | ||
) | ||
|
@@ -4696,19 +4679,12 @@ let vm_migrate printer rpc session_id params = | |
{|(field "host"="%s") and (field "currently_attached"="true")|} | ||
(Ref.string_of host) | ||
in | ||
let host_pbds = | ||
Client.PBD.get_all_records_where ~rpc:remote_rpc | ||
~session_id:remote_session ~expr | ||
in | ||
let srs = | ||
List.map | ||
(fun (_, pbd_rec) -> | ||
( pbd_rec.API.pBD_SR | ||
, Client.SR.get_record ~rpc:remote_rpc | ||
~session_id:remote_session ~self:pbd_rec.API.pBD_SR | ||
) | ||
) | ||
host_pbds | ||
remote Client.PBD.get_all_where ~expr | ||
|> List.map (fun pbd -> | ||
let sr = remote Client.PBD.get_SR ~self:pbd in | ||
(sr, remote Client.SR.get_record ~self:sr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it is safe to use the SR record, but not the host and network record? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not safe, but not using them means risking a large amount of roundtrips between both servers to order the SRs. The internal tests should now try to find this issue continually and catch this issue in time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So using SR record is unsafe, but there hasn't been problems using them. And we can fix them once there are changes causing them to become real problems, is that right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We have 3 options here:
|
||
) | ||
in | ||
(* In the following loop, the current SR:sr' will be compared with previous checked ones, | ||
first if it is an ISO type, then pass this one for selection, then the only shared one from this and | ||
|
@@ -4807,13 +4783,20 @@ let vm_migrate printer rpc session_id params = | |
) | ||
params | ||
in | ||
let host_name_label = | ||
Client.Host.get_name_label ~rpc:remote_rpc ~session_id:remote_session | ||
~self:host | ||
in | ||
let network_name_label = | ||
Client.Network.get_name_label ~rpc:remote_rpc | ||
~session_id:remote_session ~self:network | ||
in | ||
printer | ||
(Cli_printer.PMsg | ||
(Printf.sprintf | ||
"Will migrate to remote host: %s, using remote network: %s. \ | ||
Here is the VDI mapping:" | ||
host_record.API.host_name_label | ||
network_record.API.network_name_label | ||
host_name_label network_name_label | ||
) | ||
) ; | ||
List.iter | ||
|
@@ -4822,16 +4805,13 @@ let vm_migrate printer rpc session_id params = | |
(Cli_printer.PMsg | ||
(Printf.sprintf "VDI %s -> SR %s" | ||
(Client.VDI.get_uuid ~rpc ~session_id ~self:vdi) | ||
(Client.SR.get_uuid ~rpc:remote_rpc | ||
~session_id:remote_session ~self:sr | ||
) | ||
(remote Client.SR.get_uuid ~self:sr) | ||
) | ||
) | ||
) | ||
vdi_map ; | ||
let token = | ||
Client.Host.migrate_receive ~rpc:remote_rpc ~session_id:remote_session | ||
~host ~network ~options | ||
remote Client.Host.migrate_receive ~host ~network ~options | ||
in | ||
let new_vm = | ||
do_vm_op ~include_control_vms:false ~include_template_vms:true printer | ||
|
@@ -4847,13 +4827,7 @@ let vm_migrate printer rpc session_id params = | |
|> List.hd | ||
in | ||
if get_bool_param params "copy" then | ||
printer | ||
(Cli_printer.PList | ||
[ | ||
Client.VM.get_uuid ~rpc:remote_rpc ~session_id:remote_session | ||
~self:new_vm | ||
] | ||
) | ||
printer (Cli_printer.PList [remote Client.VM.get_uuid ~self:new_vm]) | ||
) | ||
(fun () -> | ||
Client.Session.logout ~rpc:remote_rpc ~session_id:remote_session | ||
|
Uh oh!
There was an error while loading. Please reload this page.