@@ -4580,68 +4580,58 @@ let vm_migrate printer rpc session_id params =
4580
4580
Client.Session. login_with_password ~rpc: remote_rpc ~uname ~pwd
4581
4581
~version: " 1.3" ~originator: Constants. xapi_user_agent
4582
4582
in
4583
+ let remote f = f ~rpc: remote_rpc ~session_id: remote_session in
4583
4584
finally
4584
4585
(fun () ->
4585
- let host, host_record =
4586
- let all =
4587
- Client.Host. get_all_records ~rpc: remote_rpc
4588
- ~session_id: remote_session
4586
+ let host =
4587
+ let expr_match x =
4588
+ Printf. sprintf
4589
+ {| (field " hostname" = " %s" ) or (field " name__label" = " %s" ) or (field " uuid" = " %s" )| }
4590
+ x x x
4589
4591
in
4590
- if List. mem_assoc " host" params then
4591
- let x = List. assoc " host" params in
4592
- try
4593
- List. find
4594
- (fun (_ , h ) ->
4595
- h.API. host_hostname = x
4596
- || h.API. host_name_label = x
4597
- || h.API. host_uuid = x
4598
- )
4599
- all
4600
- with Not_found ->
4601
- failwith (Printf. sprintf " Failed to find host: %s" x)
4602
- else
4603
- List. hd all
4592
+ let expr, fail_msg =
4593
+ match List. assoc_opt " host" params with
4594
+ | Some x ->
4595
+ (expr_match x, Printf. sprintf " Failed to find host: %s" x)
4596
+ | None ->
4597
+ (" true" , Printf. sprintf " Failed to find a suitable host" )
4598
+ in
4599
+ match remote Client.Host. get_all_where ~expr with
4600
+ | host :: _ ->
4601
+ host
4602
+ | [] ->
4603
+ failwith fail_msg
4604
4604
in
4605
- let network, network_record =
4606
- let all =
4607
- Client.Network. get_all_records ~rpc: remote_rpc
4608
- ~session_id: remote_session
4605
+ let network =
4606
+ let expr x =
4607
+ Printf. sprintf
4608
+ {| (field " bridge" = " %s" ) or (field " name__label" = " %s" ) or (field " uuid" = " %s" )| }
4609
+ x x x
4609
4610
in
4610
- if List. mem_assoc " remote-network" params then
4611
- let x = List. assoc " remote-network" params in
4612
- try
4613
- List. find
4614
- (fun (_ , net ) ->
4615
- net.API. network_bridge = x
4616
- || net.API. network_name_label = x
4617
- || net.API. network_uuid = x
4618
- )
4619
- all
4620
- with Not_found ->
4621
- failwith (Printf. sprintf " Failed to find network: %s" x)
4622
- else
4623
- let pifs = host_record.API. host_PIFs in
4624
- let management_pifs =
4625
- List. filter
4626
- (fun self ->
4627
- Client.PIF. get_management ~rpc: remote_rpc
4628
- ~session_id: remote_session ~self
4629
- )
4630
- pifs
4631
- in
4632
- if management_pifs = [] then
4633
- failwith
4634
- (Printf. sprintf " Could not find management PIF on host %s"
4635
- host_record.API. host_uuid
4636
- ) ;
4637
- let pif = List. hd management_pifs in
4638
- let net =
4639
- Client.PIF. get_network ~rpc: remote_rpc ~session_id: remote_session
4640
- ~self: pif
4641
- in
4642
- ( net
4643
- , Client.Network. get_record ~rpc: remote_rpc
4644
- ~session_id: remote_session ~self: net
4611
+ match List. assoc_opt " remote-network" params with
4612
+ | Some x -> (
4613
+ match remote Client.Network. get_all_where ~expr: (expr x) with
4614
+ | network :: _ ->
4615
+ network
4616
+ | [] ->
4617
+ failwith (Printf. sprintf " Failed to find network: %s" x)
4618
+ )
4619
+ | None -> (
4620
+ let expr =
4621
+ Printf. sprintf
4622
+ {| (field " host" = " %s" ) and (field " management" = " true" )| }
4623
+ Ref. (string_of host)
4624
+ in
4625
+ let management_pifs = remote Client.PIF. get_all_where ~expr in
4626
+ match management_pifs with
4627
+ | [] ->
4628
+ let host_uuid = remote Client.Host. get_uuid ~self: host in
4629
+ failwith
4630
+ (Printf. sprintf " Could not find management PIF on host %s"
4631
+ host_uuid
4632
+ )
4633
+ | pif :: _ ->
4634
+ remote Client.PIF. get_network ~self: pif
4645
4635
)
4646
4636
in
4647
4637
let vif_map =
@@ -4650,10 +4640,7 @@ let vm_migrate printer rpc session_id params =
4650
4640
let vif =
4651
4641
Client.VIF. get_by_uuid ~rpc ~session_id ~uuid: vif_uuid
4652
4642
in
4653
- let net =
4654
- Client.Network. get_by_uuid ~rpc: remote_rpc
4655
- ~session_id: remote_session ~uuid: net_uuid
4656
- in
4643
+ let net = remote Client.Network. get_by_uuid ~uuid: net_uuid in
4657
4644
(vif, net)
4658
4645
)
4659
4646
(read_map_params " vif" params)
@@ -4664,10 +4651,7 @@ let vm_migrate printer rpc session_id params =
4664
4651
let vdi =
4665
4652
Client.VDI. get_by_uuid ~rpc ~session_id ~uuid: vdi_uuid
4666
4653
in
4667
- let sr =
4668
- Client.SR. get_by_uuid ~rpc: remote_rpc ~session_id: remote_session
4669
- ~uuid: sr_uuid
4670
- in
4654
+ let sr = remote Client.SR. get_by_uuid ~uuid: sr_uuid in
4671
4655
(vdi, sr)
4672
4656
)
4673
4657
(read_map_params " vdi" params)
@@ -4679,8 +4663,7 @@ let vm_migrate printer rpc session_id params =
4679
4663
Client.VGPU. get_by_uuid ~rpc ~session_id ~uuid: vgpu_uuid
4680
4664
in
4681
4665
let gpu_group =
4682
- Client.GPU_group. get_by_uuid ~rpc: remote_rpc
4683
- ~session_id: remote_session ~uuid: gpu_group_uuid
4666
+ remote Client.GPU_group. get_by_uuid ~uuid: gpu_group_uuid
4684
4667
in
4685
4668
(vgpu, gpu_group)
4686
4669
)
@@ -4696,19 +4679,12 @@ let vm_migrate printer rpc session_id params =
4696
4679
{| (field " host" = " %s" ) and (field " currently_attached" = " true" )| }
4697
4680
(Ref. string_of host)
4698
4681
in
4699
- let host_pbds =
4700
- Client.PBD. get_all_records_where ~rpc: remote_rpc
4701
- ~session_id: remote_session ~expr
4702
- in
4703
4682
let srs =
4704
- List. map
4705
- (fun (_ , pbd_rec ) ->
4706
- ( pbd_rec.API. pBD_SR
4707
- , Client.SR. get_record ~rpc: remote_rpc
4708
- ~session_id: remote_session ~self: pbd_rec.API. pBD_SR
4709
- )
4710
- )
4711
- host_pbds
4683
+ remote Client.PBD. get_all_where ~expr
4684
+ |> List. map (fun pbd ->
4685
+ let sr = remote Client.PBD. get_SR ~self: pbd in
4686
+ (sr, remote Client.SR. get_record ~self: sr)
4687
+ )
4712
4688
in
4713
4689
(* In the following loop, the current SR:sr' will be compared with previous checked ones,
4714
4690
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 =
4807
4783
)
4808
4784
params
4809
4785
in
4786
+ let host_name_label =
4787
+ Client.Host. get_name_label ~rpc: remote_rpc ~session_id: remote_session
4788
+ ~self: host
4789
+ in
4790
+ let network_name_label =
4791
+ Client.Network. get_name_label ~rpc: remote_rpc
4792
+ ~session_id: remote_session ~self: network
4793
+ in
4810
4794
printer
4811
4795
(Cli_printer. PMsg
4812
4796
(Printf. sprintf
4813
4797
" Will migrate to remote host: %s, using remote network: %s. \
4814
4798
Here is the VDI mapping:"
4815
- host_record.API. host_name_label
4816
- network_record.API. network_name_label
4799
+ host_name_label network_name_label
4817
4800
)
4818
4801
) ;
4819
4802
List. iter
@@ -4822,16 +4805,13 @@ let vm_migrate printer rpc session_id params =
4822
4805
(Cli_printer. PMsg
4823
4806
(Printf. sprintf " VDI %s -> SR %s"
4824
4807
(Client.VDI. get_uuid ~rpc ~session_id ~self: vdi)
4825
- (Client.SR. get_uuid ~rpc: remote_rpc
4826
- ~session_id: remote_session ~self: sr
4827
- )
4808
+ (remote Client.SR. get_uuid ~self: sr)
4828
4809
)
4829
4810
)
4830
4811
)
4831
4812
vdi_map ;
4832
4813
let token =
4833
- Client.Host. migrate_receive ~rpc: remote_rpc ~session_id: remote_session
4834
- ~host ~network ~options
4814
+ remote Client.Host. migrate_receive ~host ~network ~options
4835
4815
in
4836
4816
let new_vm =
4837
4817
do_vm_op ~include_control_vms: false ~include_template_vms: true printer
@@ -4847,13 +4827,7 @@ let vm_migrate printer rpc session_id params =
4847
4827
|> List. hd
4848
4828
in
4849
4829
if get_bool_param params " copy" then
4850
- printer
4851
- (Cli_printer. PList
4852
- [
4853
- Client.VM. get_uuid ~rpc: remote_rpc ~session_id: remote_session
4854
- ~self: new_vm
4855
- ]
4856
- )
4830
+ printer (Cli_printer. PList [remote Client.VM. get_uuid ~self: new_vm])
4857
4831
)
4858
4832
(fun () ->
4859
4833
Client.Session. logout ~rpc: remote_rpc ~session_id: remote_session
0 commit comments