Skip to content

Commit

Permalink
fixup! CA-390277: Stop using records on CLI cross-pool migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
psafont committed Jun 20, 2024
1 parent 96882d1 commit c7ad632
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions ocaml/xapi-cli-server/cli_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4314,27 +4314,40 @@ let vm_migrate printer rpc session_id params =
finally
(fun () ->
let host =
let host_matches x self =
let hostname () = remote (Client.Host.get_hostname ~self) in
let uuid () = remote (Client.Host.get_uuid ~self) in
let name_label () = remote (Client.Host.get_name_label ~self) in
hostname () = x || uuid () = x || name_label () = x
let get_host_by_hostname x =
let host_matches x self =
let hostname = remote (Client.Host.get_hostname ~self) in
hostname = x
in
let all_hosts = remote Client.Host.get_all in
List.find_opt (host_matches x) all_hosts
in
let get_host_by_uuid_or_name x =
let ref =
if Uuidm.of_string x |> Option.is_some then
remote (Client.Host.get_by_uuid ~uuid:x)
else
let hosts = remote (Client.Host.get_by_name_label ~label:x) in
Option.fold ~none:Ref.null ~some:Fun.id (List.nth_opt hosts 0)
in
if ref <> Ref.null then
Some ref
else
get_host_by_hostname x
in
let matches, fail_msg =

let search, fail_msg =
match List.assoc_opt "host" params with
| Some x ->
(host_matches x, Printf.sprintf "Failed to find host: %s" x)
( get_host_by_uuid_or_name x
, Printf.sprintf "Failed to find host: %s" x
)
| None ->
( (fun _ -> true)
( List.nth_opt (remote Client.Host.get_all) 0
, Printf.sprintf "Failed to find a suitable host"
)
in
let all_hosts = remote Client.Host.get_all in
match List.find_opt matches all_hosts with
| Some host ->
host
| None ->
failwith fail_msg
match search with Some ref -> ref | None -> failwith fail_msg
in
let network =
let network_matches x self =
Expand Down

0 comments on commit c7ad632

Please sign in to comment.