File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -905,6 +905,28 @@ module Proc = struct
905905end
906906
907907module Ovs = struct
908+ let match_multiple patterns s =
909+ let rec loop = function
910+ | [] -> None
911+ | pattern :: rest ->
912+ match Re. exec_opt pattern s with
913+ | Some groups -> Some groups
914+ | None -> loop rest
915+ in
916+ loop patterns
917+
918+ let patterns = List. map Re.Perl. compile_pat [
919+ " no bridge named (.*)\n " ;
920+ " no row \" (.*)\" in table Bridge"
921+ ]
922+
923+ let error_handler script args stdout stderr exn =
924+ match match_multiple patterns stderr with
925+ | Some groups ->
926+ let bridge = Re.Group. get groups 1 in
927+ raise (Network_error (Bridge_does_not_exist bridge))
928+ | None ->
929+ default_error_handler script args stdout stderr exn
908930
909931 module Cli : sig
910932 val vsctl : string list -> string
@@ -915,12 +937,12 @@ module Ovs = struct
915937 let s = Semaphore. create 5
916938 let vsctl args =
917939 Semaphore. execute s (fun () ->
918- call_script ovs_vsctl (" --timeout=20" :: args)
940+ call_script ~on_error: error_handler ovs_vsctl (" --timeout=20" :: args)
919941 )
920942 let ofctl args =
921- call_script ovs_ofctl args
943+ call_script ~on_error: error_handler ovs_ofctl args
922944 let appctl args =
923- call_script ovs_appctl args
945+ call_script ~on_error: error_handler ovs_appctl args
924946 end
925947
926948 module type Cli_S = module type of Cli
You can’t perform that action at this time.
0 commit comments