@@ -4310,24 +4310,42 @@ let vm_migrate printer rpc session_id params =
4310
4310
Client.Session. login_with_password remote_rpc username password " 1.3"
4311
4311
Constants. xapi_user_agent
4312
4312
in
4313
+ let remote f = f ~rpc: remote_rpc ~session_id: remote_session in
4313
4314
finally
4314
4315
(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"
4325
4346
)
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
4331
4349
in
4332
4350
let network, network_record =
4333
4351
let all = Client.Network. get_all_records remote_rpc remote_session in
@@ -4344,7 +4362,7 @@ let vm_migrate printer rpc session_id params =
4344
4362
with Not_found ->
4345
4363
failwith (Printf. sprintf " Failed to find network: %s" x)
4346
4364
else
4347
- let pifs = host_record. API. host_PIFs in
4365
+ let pifs = remote Client.Host. get_PIFs ~self: host in
4348
4366
let management_pifs =
4349
4367
List. filter
4350
4368
(fun pif ->
@@ -4355,7 +4373,7 @@ let vm_migrate printer rpc session_id params =
4355
4373
if List. length management_pifs = 0 then
4356
4374
failwith
4357
4375
(Printf. sprintf " Could not find management PIF on host %s"
4358
- host_record. API. host_uuid
4376
+ (remote Client.Host. get_uuid ~self: host)
4359
4377
) ;
4360
4378
let pif = List. hd management_pifs in
4361
4379
let net = Client.PIF. get_network remote_rpc remote_session pif in
@@ -4509,13 +4527,13 @@ let vm_migrate printer rpc session_id params =
4509
4527
)
4510
4528
params
4511
4529
in
4530
+ let host_name_label = remote (Client.Host. get_name_label ~self: host) in
4512
4531
printer
4513
4532
(Cli_printer. PMsg
4514
4533
(Printf. sprintf
4515
4534
" Will migrate to remote host: %s, using remote network: %s. \
4516
4535
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
4519
4537
)
4520
4538
) ;
4521
4539
List. iter
0 commit comments