Skip to content

Commit 8894e1b

Browse files
committed
CA-390277: Stop using host records on CLI cross-pool migrations
Host records have changed between CH8.2CU1 and XS8, this means that the records produced from an new host cannot be serialized by this code. Instead of making the remote host filter records, now the client tries to fetch the correct reference, and if it can't, fetches all references and fetches fields to find it. Records from Networks, PBDs and SRs are still used. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent 2e39039 commit 8894e1b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,24 +4310,42 @@ let vm_migrate printer rpc session_id params =
43104310
Client.Session.login_with_password remote_rpc username password "1.3"
43114311
Constants.xapi_user_agent
43124312
in
4313+
let remote f = f ~rpc:remote_rpc ~session_id:remote_session in
43134314
finally
43144315
(fun () ->
4315-
let host, host_record =
4316-
let all = Client.Host.get_all_records remote_rpc remote_session in
4317-
if List.mem_assoc "host" params then
4318-
let x = List.assoc "host" params in
4319-
try
4320-
List.find
4321-
(fun (_, h) ->
4322-
h.API.host_hostname = x
4323-
|| h.API.host_name_label = x
4324-
|| h.API.host_uuid = x
4316+
let host =
4317+
let get_host_by_hostname x =
4318+
let host_matches self =
4319+
let hostname = remote (Client.Host.get_hostname ~self) in
4320+
hostname = x
4321+
in
4322+
let all_hosts = remote Client.Host.get_all in
4323+
List.find_opt host_matches all_hosts
4324+
in
4325+
let get_host_with x =
4326+
let ref =
4327+
if Uuidm.of_string x |> Option.is_some then
4328+
remote (Client.Host.get_by_uuid ~uuid:x)
4329+
else
4330+
let hosts = remote (Client.Host.get_by_name_label ~label:x) in
4331+
Option.fold ~none:Ref.null ~some:Fun.id (List.nth_opt hosts 0)
4332+
in
4333+
if ref <> Ref.null then
4334+
Some ref
4335+
else
4336+
get_host_by_hostname x
4337+
in
4338+
4339+
let search, fail_msg =
4340+
match List.assoc_opt "host" params with
4341+
| Some x ->
4342+
(get_host_with x, Printf.sprintf "Failed to find host: %s" x)
4343+
| None ->
4344+
( List.nth_opt (remote Client.Host.get_all) 0
4345+
, Printf.sprintf "Failed to find a suitable host"
43254346
)
4326-
all
4327-
with Not_found ->
4328-
failwith (Printf.sprintf "Failed to find host: %s" x)
4329-
else
4330-
List.hd all
4347+
in
4348+
match search with Some ref -> ref | None -> failwith fail_msg
43314349
in
43324350
let network, network_record =
43334351
let all = Client.Network.get_all_records remote_rpc remote_session in
@@ -4344,7 +4362,7 @@ let vm_migrate printer rpc session_id params =
43444362
with Not_found ->
43454363
failwith (Printf.sprintf "Failed to find network: %s" x)
43464364
else
4347-
let pifs = host_record.API.host_PIFs in
4365+
let pifs = remote Client.Host.get_PIFs ~self:host in
43484366
let management_pifs =
43494367
List.filter
43504368
(fun pif ->
@@ -4355,7 +4373,7 @@ let vm_migrate printer rpc session_id params =
43554373
if List.length management_pifs = 0 then
43564374
failwith
43574375
(Printf.sprintf "Could not find management PIF on host %s"
4358-
host_record.API.host_uuid
4376+
(remote Client.Host.get_uuid ~self:host)
43594377
) ;
43604378
let pif = List.hd management_pifs in
43614379
let net = Client.PIF.get_network remote_rpc remote_session pif in
@@ -4509,13 +4527,13 @@ let vm_migrate printer rpc session_id params =
45094527
)
45104528
params
45114529
in
4530+
let host_name_label = remote (Client.Host.get_name_label ~self:host) in
45124531
printer
45134532
(Cli_printer.PMsg
45144533
(Printf.sprintf
45154534
"Will migrate to remote host: %s, using remote network: %s. \
45164535
Here is the VDI mapping:"
4517-
host_record.API.host_name_label
4518-
network_record.API.network_name_label
4536+
host_name_label network_record.API.network_name_label
45194537
)
45204538
) ;
45214539
List.iter

0 commit comments

Comments
 (0)