@@ -229,7 +229,7 @@ let get_hosts_by_name_or_id rpc session_id name =
229
229
230
230
let get_host_by_name_or_id rpc session_id name =
231
231
let hosts = get_hosts_by_name_or_id rpc session_id name in
232
- if List. length hosts = 0 then failwith (" Host " ^ name ^ " not found" ) ;
232
+ if hosts = [] then failwith (" Host " ^ name ^ " not found" ) ;
233
233
List. nth hosts 0
234
234
235
235
let get_host_from_session rpc session_id =
@@ -862,7 +862,7 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
862
862
]
863
863
in
864
864
let ops =
865
- if List. length settable > 0 then
865
+ if settable <> [] then
866
866
( cli_name " param-set"
867
867
, [" uuid" ]
868
868
, settable
@@ -877,7 +877,7 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
877
877
ops
878
878
in
879
879
let ops =
880
- if List. length addable > 0 then
880
+ if addable <> [] then
881
881
ops
882
882
@ [
883
883
( cli_name " param-add"
@@ -902,7 +902,7 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
902
902
ops
903
903
in
904
904
let ops =
905
- if List. length clearable > 0 then
905
+ if clearable <> [] then
906
906
ops
907
907
@ [
908
908
( cli_name " param-clear"
@@ -2933,13 +2933,7 @@ let event_wait_gen rpc session_id classname record_matches =
2933
2933
(List.map (fun r -> (r.name, fun () -> safe_get_field r)))
2934
2934
current_tbls
2935
2935
in
2936
- debug " Got % d records" (List.length all_recs) ;
2937
- (* true if anything matches now *)
2938
- let find_any_match recs =
2939
- let ls = List.map record_matches recs in
2940
- List.length (List.filter (fun x -> x) ls) > 0
2941
- in
2942
- find_any_match all_recs
2936
+ List.exists record_matches all_recs
2943
2937
in
2944
2938
finally
2945
2939
(fun () ->
@@ -3310,9 +3304,9 @@ let do_host_op rpc session_id op params ?(multiple = true) ignore_params =
3310
3304
failwith " No matching hosts found"
3311
3305
| 1 ->
3312
3306
[op 1 (List. hd hosts)]
3313
- | _ ->
3307
+ | len ->
3314
3308
if multiple && get_bool_param params " multiple" then
3315
- do_multiple (op ( List. length hosts) ) hosts
3309
+ do_multiple (op len ) hosts
3316
3310
else
3317
3311
failwith
3318
3312
( if not multiple then
@@ -3922,11 +3916,13 @@ let vm_install_real printer rpc session_id template name description params =
3922
3916
failwith
3923
3917
" SR specified via sr-uuid doesn't have the name specified via \
3924
3918
sr-name-label"
3925
- | None ->
3926
- if List. length sr_list > 1 then
3919
+ | None -> (
3920
+ match sr_list with
3921
+ | [x] ->
3922
+ Some x
3923
+ | _ ->
3927
3924
failwith " Multiple SRs with that name-label found"
3928
- else
3929
- Some (List. hd sr_list)
3925
+ )
3930
3926
)
3931
3927
else
3932
3928
sr_ref
@@ -4063,12 +4059,12 @@ let vm_install printer rpc session_id params =
4063
4059
List. fold_left filter_records_on_fields all_recs
4064
4060
((" name-label" , name) :: filter_params)
4065
4061
in
4066
- match List. length templates with
4067
- | 0 ->
4062
+ match templates with
4063
+ | [] ->
4068
4064
failwith " No templates matched"
4069
- | 1 ->
4070
- ( List. hd templates) .getref ()
4071
- | _ ->
4065
+ | [x] ->
4066
+ x .getref ()
4067
+ | _ :: _ :: _ ->
4072
4068
failwith " More than one matching template found"
4073
4069
in
4074
4070
if
@@ -4119,7 +4115,7 @@ let console fd _printer rpc session_id params =
4119
4115
| [] ->
4120
4116
marshal fd (Command (PrintStderr " No VM found\n " )) ;
4121
4117
raise (ExitWithError 1 )
4122
- | _ :: _ ->
4118
+ | _ :: _ :: _ ->
4123
4119
marshal fd
4124
4120
(Command
4125
4121
(PrintStderr
@@ -4158,9 +4154,10 @@ let vm_uninstall_common fd _printer rpc session_id params vms =
4158
4154
(* add extra text if the VDI is being shared *)
4159
4155
let r = Client.VDI. get_record ~rpc ~session_id ~self: vdi in
4160
4156
Printf. sprintf " VDI: %s (%s) %s" r.API. vDI_uuid r.API. vDI_name_label
4161
- ( if List. length r.API. vDI_VBDs < = 1 then
4157
+ ( match r.API. vDI_VBDs with
4158
+ | [] | [_] ->
4162
4159
" "
4163
- else
4160
+ | _ :: _ :: _ ->
4164
4161
" ** WARNING: disk is shared by other VMs"
4165
4162
)
4166
4163
in
@@ -4482,18 +4479,15 @@ let vm_retrieve_wlb_recommendations printer rpc session_id params =
4482
4479
in
4483
4480
try
4484
4481
let vms = select_vms rpc session_id params [] in
4485
- match List. length vms with
4486
- | 0 ->
4482
+ match vms with
4483
+ | [] ->
4487
4484
failwith " No matching VMs found"
4488
- | 1 ->
4485
+ | [x] ->
4489
4486
printer
4490
4487
(Cli_printer. PTable
4491
- [
4492
- (" Host(Uuid)" , " Stars, RecID, ZeroScoreReason" )
4493
- :: table (List. hd vms)
4494
- ]
4488
+ [(" Host(Uuid)" , " Stars, RecID, ZeroScoreReason" ) :: table x]
4495
4489
)
4496
- | _ ->
4490
+ | _ :: _ :: _ ->
4497
4491
failwith
4498
4492
" Multiple VMs found. Operation can only be performed on one VM at a \
4499
4493
time"
@@ -4633,7 +4627,7 @@ let vm_migrate printer rpc session_id params =
4633
4627
)
4634
4628
pifs
4635
4629
in
4636
- if List. length management_pifs = 0 then
4630
+ if management_pifs = [] then
4637
4631
failwith
4638
4632
(Printf. sprintf " Could not find management PIF on host %s"
4639
4633
host_record.API. host_uuid
@@ -5031,7 +5025,7 @@ let vm_disk_remove printer rpc session_id params =
5031
5025
(fun x -> device = Client.VBD. get_userdevice ~rpc ~session_id ~self: x)
5032
5026
vm_record.API. vM_VBDs
5033
5027
in
5034
- if List. length vbd_to_remove < 1 then
5028
+ if vbd_to_remove = [] then
5035
5029
failwith " Disk not found"
5036
5030
else
5037
5031
let vbd = List. nth vbd_to_remove 0 in
@@ -5057,7 +5051,7 @@ let vm_cd_remove printer rpc session_id params =
5057
5051
)
5058
5052
vm_record.API. vM_VBDs
5059
5053
in
5060
- if List. length vbd_to_remove < 1 then
5054
+ if vbd_to_remove = [] then
5061
5055
raise (failwith " Disk not found" )
5062
5056
else
5063
5057
let vbd = List. nth vbd_to_remove 0 in
@@ -5076,7 +5070,7 @@ let vm_cd_add printer rpc session_id params =
5076
5070
)
5077
5071
vdis
5078
5072
in
5079
- if List. length vdis = 0 then failwith (" CD " ^ cd_name ^ " not found!" ) ;
5073
+ if vdis = [] then failwith (" CD " ^ cd_name ^ " not found!" ) ;
5080
5074
let vdi = List. nth vdis 0 in
5081
5075
let op vm =
5082
5076
create_vbd_and_plug rpc session_id (vm.getref () ) vdi
@@ -5099,9 +5093,14 @@ let vm_cd_eject printer rpc session_id params =
5099
5093
(fun vbd -> Client.VBD. get_type ~rpc ~session_id ~self: vbd = `CD )
5100
5094
vbds
5101
5095
in
5102
- if List. length cdvbds = 0 then failwith " No CDs found" ;
5103
- if List. length cdvbds > 1 then
5104
- failwith " Two or more CDs found. Please use vbd-eject" ;
5096
+ ( match cdvbds with
5097
+ | [] ->
5098
+ failwith " No CDs found"
5099
+ | [_] ->
5100
+ ()
5101
+ | _ :: _ :: _ ->
5102
+ failwith " Two or more CDs found. Please use vbd-eject"
5103
+ ) ;
5105
5104
let cd = List. hd cdvbds in
5106
5105
Client.VBD. eject ~rpc ~session_id ~vbd: cd
5107
5106
in
@@ -5118,13 +5117,18 @@ let vm_cd_insert printer rpc session_id params =
5118
5117
)
5119
5118
vdis
5120
5119
in
5121
- if List. length vdis = 0 then failwith (" CD " ^ cd_name ^ " not found" ) ;
5122
- if List. length vdis > 1 then
5123
- failwith
5124
- (" Multiple CDs named "
5125
- ^ cd_name
5126
- ^ " found. Please use vbd-insert and specify uuids"
5127
- ) ;
5120
+ ( match vdis with
5121
+ | [] ->
5122
+ failwith (" CD " ^ cd_name ^ " not found" )
5123
+ | [_] ->
5124
+ ()
5125
+ | _ :: _ :: _ ->
5126
+ failwith
5127
+ (" Multiple CDs named "
5128
+ ^ cd_name
5129
+ ^ " found. Please use vbd-insert and specify uuids"
5130
+ )
5131
+ ) ;
5128
5132
let op vm =
5129
5133
let vm_record = vm.record () in
5130
5134
let vbds = vm_record.API. vM_VBDs in
@@ -5136,15 +5140,16 @@ let vm_cd_insert printer rpc session_id params =
5136
5140
)
5137
5141
vbds
5138
5142
in
5139
- if List. length cdvbds = 0 then
5140
- raise
5141
- (Api_errors. Server_error
5142
- (Api_errors. vm_no_empty_cd_vbd, [Ref. string_of (vm.getref () )])
5143
- ) ;
5144
- if List. length cdvbds > 1 then
5145
- failwith " Two or more empty CD devices found. Please use vbd-insert" ;
5146
- let cd = List. hd cdvbds in
5147
- Client.VBD. insert ~rpc ~session_id ~vbd: cd ~vdi: (List. hd vdis)
5143
+ match cdvbds with
5144
+ | [] ->
5145
+ raise
5146
+ (Api_errors. Server_error
5147
+ (Api_errors. vm_no_empty_cd_vbd, [Ref. string_of (vm.getref () )])
5148
+ )
5149
+ | [cd] ->
5150
+ Client.VBD. insert ~rpc ~session_id ~vbd: cd ~vdi: (List. hd vdis)
5151
+ | _ :: _ :: _ ->
5152
+ failwith " Two or more empty CD devices found. Please use vbd-insert"
5148
5153
in
5149
5154
ignore (do_vm_op printer rpc session_id op params [" cd-name" ])
5150
5155
@@ -5560,7 +5565,7 @@ let pool_retrieve_wlb_report fd _printer rpc session_id params =
5560
5565
in
5561
5566
download_file_with_task fd rpc session_id filename Constants. wlb_report_uri
5562
5567
(Printf. sprintf " report=%s%s%s" (Http. urlencode report)
5563
- (if List. length other_params = 0 then " " else " &" )
5568
+ (if other_params = [] then " " else " &" )
5564
5569
(String. concat " &"
5565
5570
(List. map
5566
5571
(fun (k , v ) ->
@@ -5983,7 +5988,7 @@ let vm_is_bios_customized printer rpc session_id params =
5983
5988
let bios_strings =
5984
5989
Client.VM. get_bios_strings ~rpc ~session_id ~self: (vm.getref () )
5985
5990
in
5986
- if List. length bios_strings = 0 then
5991
+ if bios_strings = [] then
5987
5992
printer
5988
5993
(Cli_printer. PMsg " The BIOS strings of this VM have not yet been set." )
5989
5994
else if bios_strings = Constants. generic_bios_strings then
@@ -7264,7 +7269,7 @@ let subject_role_common rpc session_id params =
7264
7269
let roles =
7265
7270
Client.Role. get_by_name_label ~rpc ~session_id ~label: role_name
7266
7271
in
7267
- if List. length roles > 0 then
7272
+ if roles <> [] then
7268
7273
List. hd roles (* names are unique, there's either 0 or 1*)
7269
7274
else
7270
7275
Ref. null
0 commit comments