File tree 3 files changed +62
-40
lines changed
3 files changed +62
-40
lines changed Original file line number Diff line number Diff line change @@ -933,7 +933,7 @@ let xl_cmd = ref "/usr/sbin/xl"
933
933
934
934
let depmod = ref " /usr/sbin/depmod"
935
935
936
- let driver_tool = ref " /opt/xensource/debug/drivertool.sh "
936
+ let driver_tool = ref " /usr/sbin/driver-tool "
937
937
938
938
let dracut = ref " /usr/bin/dracut"
939
939
Original file line number Diff line number Diff line change @@ -74,7 +74,8 @@ module Variant = struct
74
74
if v.API. driver_variant_hardware_present = false then
75
75
no_hardware (Ref. string_of self) ;
76
76
let stdout =
77
- Tool. call [" select" ; d.API. host_driver_name; v.API. driver_variant_name]
77
+ Tool. call
78
+ [" -s" ; " -n" ; d.API. host_driver_name; " -v" ; v.API. driver_variant_name]
78
79
in
79
80
info " %s: %s" __FUNCTION__ stdout ;
80
81
Db.Host_driver. set_selected_variant ~__context ~self: drv ~value: self
@@ -171,10 +172,12 @@ let remove ~__context ~host ~except =
171
172
(* * Runs on [host]. We update or create an entry for each driver
172
173
reported by drivertool and remove any extra driver that is in xapi. *)
173
174
let scan ~__context ~host =
174
- Tool.Mock. install () ;
175
+ let path = ! Xapi_globs. driver_tool in
176
+ (* if the real tool is not installed, install a mock *)
177
+ if not (Sys. file_exists path) then Tool.Mock. install () ;
175
178
let null = Ref. null in
176
179
let drivers (* on this host *) =
177
- Tool. call [" list " ]
180
+ Tool. call [" -l " ]
178
181
|> Tool. parse
179
182
|> List. map @@ fun (_name , driver ) ->
180
183
let driver_ref =
Original file line number Diff line number Diff line change @@ -242,26 +242,6 @@ module Mock = struct
242
242
243
243
set - o errexit
244
244
set - o pipefail
245
- if [[ - n " $TRACE" ]]; then set - o xtrace; fi
246
- set - o nounset
247
-
248
- if [[ " ${1-}" =~ ^-* h(elp)?$ ]]; then
249
- cat << EOF
250
- Usage : $ 0 arg- one arg- two
251
-
252
- This is an awesome bash script to make your life better.
253
- EOF
254
- fi
255
-
256
- function deselect {
257
- cat << EOF
258
- {
259
- " driver" : " $1" ,
260
- " exit" : 0
261
- }
262
- EOF
263
- }
264
-
265
245
266
246
function selection {
267
247
cat << EOF
@@ -621,22 +601,61 @@ function list() {
621
601
EOF
622
602
}
623
603
604
+ # Initialize variables with default values
605
+ l_flag= false
606
+ s_flag= false
607
+ n_value= " "
608
+ v_value= " "
609
+
610
+ # Use getopt to parse command- line options
611
+ while getopts " lsn:v:" opt; do
612
+ case " $opt" in
613
+ l)
614
+ l_flag= true
615
+ ;;
616
+ s)
617
+ s_flag= true
618
+ ;;
619
+ n)
620
+ n_value= " $OPTARG"
621
+ ;;
622
+ v)
623
+ v_value= " $OPTARG"
624
+ ;;
625
+ \?) # Invalid option
626
+ echo " Invalid option: -$OPTARG" > & 2 #> & 2 redirects error message to stderr
627
+ exit 1
628
+ ;;
629
+ :) # Missing argument for option
630
+ echo " Option -$OPTARG requires an argument." > & 2
631
+ exit 1
632
+ ;;
633
+ esac
634
+ done
635
+
636
+ # Shift the remaining positional parameters (if any)
637
+ shift $ ((OPTIND - 1 ))
638
+
639
+ # We don't properly prevent illegal combinations because this is just a
640
+ # mock. So we recognise - l first.
641
+ if $ l_flag; then
642
+ list
643
+ exit 0
644
+ fi
624
645
625
- case " $1" in
626
- list )
627
- list
628
- ;;
629
- select)
630
- selection " $2" " $3"
631
- ;;
632
- deselect)
633
- deselect " $2"
634
- ;;
635
- * )
636
- echo " unknown command $1" 2 > & 1
646
+ if $ s_flag; then
647
+ if [ - z " $n_value" ]; then
648
+ echo " missing -n" > & 2
649
+ exit 1
650
+ fi
651
+ if [ - z " $v_value" ]; then
652
+ echo " missing -v" > & 2
637
653
exit 1
638
- ;;
639
- esac
654
+ fi
655
+
656
+ selection " $n_value" " $v_value"
657
+ exit 0
658
+ fi
640
659
| }
641
660
642
661
let install () =
645
664
Xapi_stdext_unix.Unixext. write_string_to_file path drivertool_sh ;
646
665
Unix. chmod path 0o755
647
666
with e ->
648
- Helpers. internal_error ~log_err: true " %s: can't install %s: %s"
649
- __FUNCTION__ path (Printexc. to_string e)
667
+ Helpers. internal_error " %s: can't install %s: %s" __FUNCTION__ path
668
+ (Printexc. to_string e)
650
669
end
You can’t perform that action at this time.
0 commit comments