@@ -75,12 +75,13 @@ let default_error_handler script args stdout stderr status =
7575 " stdout" , stdout;
7676 " stderr" , stderr]))
7777
78- let check_n_run ?(on_error =default_error_handler) run_func script args =
78+ let check_n_run ?(on_error =default_error_handler) ?( log = true ) run_func script args =
7979 try
8080 Unix. access script [ Unix. X_OK ];
8181 (* Use the same $PATH as xapi *)
8282 let env = [| " PATH=" ^ (Sys. getenv " PATH" ) |] in
83- info " %s %s" script (String. concat " " args);
83+ if log then
84+ info " %s %s" script (String. concat " " args);
8485 run_func env script args
8586 with
8687 | Unix. Unix_error (e , a , b ) ->
@@ -90,19 +91,19 @@ let check_n_run ?(on_error=default_error_handler) run_func script args =
9091 | Forkhelpers. Spawn_internal_error (stderr , stdout , status )->
9192 on_error script args stdout stderr status
9293
93- let call_script ?(timeout =Some 60.0 ) ?on_error script args =
94+ let call_script ?(timeout =Some 60.0 ) ?on_error ? log script args =
9495 let call_script_internal env script args =
9596 let (out,err) = Forkhelpers. execute_command_get_output ~env ?timeout script args in
9697 out
9798 in
98- check_n_run ?on_error call_script_internal script args
99+ check_n_run ?on_error ?log call_script_internal script args
99100
100- let fork_script ?on_error script args =
101+ let fork_script ?on_error ? log script args =
101102 let fork_script_internal env script args =
102103 let pid = Forkhelpers. safe_close_and_exec ~env None None None [] script args in
103104 Forkhelpers. dontwaitpid pid;
104105 in
105- check_n_run ?on_error fork_script_internal script args
106+ check_n_run ?on_error ?log fork_script_internal script args
106107
107108module Sysfs = struct
108109 let list () =
@@ -357,19 +358,17 @@ module Ip = struct
357358 | V6 -> [" -6" ]
358359 | V46 -> []
359360
360- let call args =
361- call_script iproute2 args
361+ let call ? log args =
362+ call_script ?log iproute2 args
362363
363364 let find output attr =
364- info " Looking for %s in [%s]" attr output;
365365 let args = Astring.String. fields ~empty: false output in
366366 let indices = (Xapi_stdext_std.Listext.List. position (fun s -> s = attr) args) in
367- info " Found at [ %s ]" (String. concat " , " (List. map string_of_int indices));
368367 List. map (fun i -> List. nth args (succ i)) indices
369368
370369 let get_link_flags dev =
371370 Sysfs. assert_exists dev;
372- let output = call [" link" ; " show" ; " dev" ; dev] in
371+ let output = call ~log: false [" link" ; " show" ; " dev" ; dev] in
373372 let i = String. index output '<' in
374373 let j = String. index output '>' in
375374 let flags = String. sub output (i + 1 ) (j - i - 1 ) in
@@ -406,13 +405,13 @@ module Ip = struct
406405 let link ?(version =V46 ) dev attr =
407406 Sysfs. assert_exists dev;
408407 let v = string_of_version version in
409- let output = call (v @ [" link" ; " show" ; " dev" ; dev]) in
408+ let output = call ~log: false (v @ [" link" ; " show" ; " dev" ; dev]) in
410409 find output attr
411410
412411 let addr ?(version =V46 ) dev attr =
413412 Sysfs. assert_exists dev;
414413 let v = string_of_version version in
415- let output = call (v @ [" addr" ; " show" ; " dev" ; dev]) in
414+ let output = call ~log: false (v @ [" addr" ; " show" ; " dev" ; dev]) in
416415 find output attr
417416
418417 let get_mtu dev =
@@ -517,7 +516,7 @@ module Ip = struct
517516
518517 let route_show ?(version =V46 ) dev =
519518 let v = string_of_version version in
520- call (v @ [" route" ; " show" ; " dev" ; dev])
519+ call ~log: false (v @ [" route" ; " show" ; " dev" ; dev])
521520
522521 let set_route ?network dev gateway =
523522 try
@@ -819,12 +818,12 @@ module Dhclient = struct
819818end
820819
821820module Fcoe = struct
822- let call args =
823- call_script ~timeout: (Some 10.0 ) ! fcoedriver args
821+ let call ? log args =
822+ call_script ?log ~timeout: (Some 10.0 ) ! fcoedriver args
824823
825824 let get_capabilities name =
826825 try
827- let output = call [" --xapi" ; name; " capable" ] in
826+ let output = call ~log: false [" --xapi" ; name; " capable" ] in
828827 if Astring.String. is_infix ~affix: " True" output then [" fcoe" ] else []
829828 with _ ->
830829 debug " Failed to get fcoe support status on device %s" name;
@@ -929,20 +928,20 @@ module Ovs = struct
929928 default_error_handler script args stdout stderr exn
930929
931930 module Cli : sig
932- val vsctl : string list -> string
933- val ofctl : string list -> string
934- val appctl : string list -> string
931+ val vsctl : ? log : bool -> string list -> string
932+ val ofctl : ? log : bool -> string list -> string
933+ val appctl : ? log : bool -> string list -> string
935934 end = struct
936935 open Xapi_stdext_threads
937936 let s = Semaphore. create 5
938- let vsctl args =
937+ let vsctl ? log args =
939938 Semaphore. execute s (fun () ->
940- call_script ~on_error: error_handler ovs_vsctl (" --timeout=20" :: args)
939+ call_script ~on_error: error_handler ?log ovs_vsctl (" --timeout=20" :: args)
941940 )
942- let ofctl args =
943- call_script ~on_error: error_handler ovs_ofctl args
944- let appctl args =
945- call_script ~on_error: error_handler ovs_appctl args
941+ let ofctl ? log args =
942+ call_script ~on_error: error_handler ?log ovs_ofctl args
943+ let appctl ? log args =
944+ call_script ~on_error: error_handler ?log ovs_appctl args
946945 end
947946
948947 module type Cli_S = module type of Cli
@@ -958,15 +957,15 @@ module Ovs = struct
958957 let raw_list = (Astring.String. cuts ~empty: false ~sep: " ," (String. sub raw 1 (String. length raw - 2 ))) in
959958 let uuids = List. map (String. trim) raw_list in
960959 List. map (fun uuid ->
961- let raw = String. trim (vsctl [" get" ; " interface" ; uuid; " name" ]) in
960+ let raw = String. trim (vsctl ~log: false [" get" ; " interface" ; uuid; " name" ]) in
962961 String. sub raw 1 (String. length raw - 2 )) uuids
963962 else
964963 []
965964 with _ -> []
966965
967966 let bridge_to_ports name =
968967 try
969- let ports = String. trim (vsctl [" list-ports" ; name]) in
968+ let ports = String. trim (vsctl ~log: false [" list-ports" ; name]) in
970969 let ports' =
971970 if ports <> " " then
972971 Astring.String. cuts ~empty: false ~sep: " \n " ports
@@ -978,7 +977,7 @@ module Ovs = struct
978977
979978 let bridge_to_interfaces name =
980979 try
981- let ifaces = String. trim (vsctl [" list-ifaces" ; name]) in
980+ let ifaces = String. trim (vsctl ~log: false [" list-ifaces" ; name]) in
982981 if ifaces <> " " then
983982 Astring.String. cuts ~empty: false ~sep: " \n " ifaces
984983 else
@@ -987,8 +986,8 @@ module Ovs = struct
987986
988987 let bridge_to_vlan name =
989988 try
990- let parent = vsctl [" br-to-parent" ; name] |> String. trim in
991- let vlan = vsctl [" br-to-vlan" ; name] |> String. trim |> int_of_string in
989+ let parent = vsctl ~log: false [" br-to-parent" ; name] |> String. trim in
990+ let vlan = vsctl ~log: false [" br-to-vlan" ; name] |> String. trim |> int_of_string in
992991 Some (parent, vlan)
993992 with e ->
994993 debug " bridge_to_vlan: %s" (Printexc. to_string e);
@@ -1001,7 +1000,7 @@ module Ovs = struct
10011000
10021001 let get_bond_link_status name =
10031002 try
1004- let raw = appctl [" bond/show" ; name] in
1003+ let raw = appctl ~log: false [" bond/show" ; name] in
10051004 let lines = Astring.String. cuts ~empty: false ~sep: " \n " raw in
10061005 List. fold_left (fun (slaves , active_slave ) line ->
10071006 let slaves =
@@ -1027,7 +1026,7 @@ module Ovs = struct
10271026
10281027 let get_bond_mode name =
10291028 try
1030- let output = String. trim (vsctl [" get" ; " port" ; name; " bond_mode" ]) in
1029+ let output = String. trim (vsctl ~log: false [" get" ; " port" ; name; " bond_mode" ]) in
10311030 if output <> " []" then Some output else None
10321031 with _ ->
10331032 None
@@ -1076,15 +1075,15 @@ module Ovs = struct
10761075 let get_vlans name =
10771076 try
10781077 let vlans_with_uuid =
1079- let raw = vsctl [" --bare" ; " -f" ; " table" ; " --" ; " --columns=name,_uuid" ; " find" ; " port" ; " fake_bridge=true" ] in
1078+ let raw = vsctl ~log: false [" --bare" ; " -f" ; " table" ; " --" ; " --columns=name,_uuid" ; " find" ; " port" ; " fake_bridge=true" ] in
10801079 if raw <> " " then
10811080 let lines = Astring.String. cuts ~empty: false ~sep: " \n " (String. trim raw) in
10821081 List. map (fun line -> Scanf. sscanf line " %s %s" (fun a b -> a, b)) lines
10831082 else
10841083 []
10851084 in
10861085 let bridge_ports =
1087- let raw = vsctl [" get" ; " bridge" ; name; " ports" ] in
1086+ let raw = vsctl ~log: false [" get" ; " bridge" ; name; " ports" ] in
10881087 let raw = String. trim raw in
10891088 if raw <> " []" then
10901089 let raw_list = (Astring.String. cuts ~empty: false ~sep: " ," (String. sub raw 1 (String. length raw - 2 ))) in
@@ -1106,7 +1105,7 @@ module Ovs = struct
11061105
11071106 let get_mcast_snooping_enable ~name =
11081107 try
1109- vsctl [" --" ; " get" ; " bridge" ; name; " mcast_snooping_enable" ]
1108+ vsctl ~log: false [" --" ; " get" ; " bridge" ; name; " mcast_snooping_enable" ]
11101109 |> String. trim
11111110 |> bool_of_string
11121111 with _ -> false
@@ -1190,7 +1189,7 @@ module Ovs = struct
11901189 vsctl [" --" ; " --if-exists" ; " del-br" ; name]
11911190
11921191 let list_bridges () =
1193- let bridges = String. trim (vsctl [" list-br" ]) in
1192+ let bridges = String. trim (vsctl ~log: false [" list-br" ]) in
11941193 if bridges <> " " then
11951194 Astring.String. cuts ~empty: false ~sep: " \n " bridges
11961195 else
@@ -1205,7 +1204,7 @@ module Ovs = struct
12051204 vsctl [" --" ; " --with-iface" ; " --if-exists" ; " del-port" ; name]
12061205
12071206 let port_to_bridge name =
1208- vsctl [" port-to-br" ; name]
1207+ vsctl ~log: false [" port-to-br" ; name]
12091208
12101209 let make_bond_properties name properties =
12111210 let known_props = [" mode" ; " hashing-algorithm" ; " updelay" ; " downdelay" ;
@@ -1285,7 +1284,7 @@ module Ovs = struct
12851284 mac_args @ args @ per_iface_args)
12861285
12871286 let get_fail_mode bridge =
1288- vsctl [" get-fail-mode" ; bridge]
1287+ vsctl ~log: false [" get-fail-mode" ; bridge]
12891288
12901289 let add_default_flows bridge mac interfaces =
12911290 let ports = List. map (fun interface -> vsctl [" get" ; " interface" ; interface; " ofport" ]) interfaces in
0 commit comments