Skip to content

Commit 7becd79

Browse files
committed
Merge pull request #54 from ravippandey/CA-113824
CA-113824: Refactor code for getting devices
2 parents bf8ccd9 + a33b0dd commit 7becd79

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

networkd/network_monitor_thread.ml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ open D
2525
(** Table for bonds status. *)
2626
let bonds_status : (string, (int * int)) Hashtbl.t = Hashtbl.create 10
2727

28+
let monitor_blacklist = ref [
29+
"dummy";
30+
"xenbr";
31+
"xapi";
32+
"ovs-system";
33+
"xenapi";
34+
]
35+
2836
let xapi_rpc request =
2937
Rpc_client.do_rpc_unix
3038
~content_type:(Rpc_client.content_type_of_string "text/xml")
@@ -98,8 +106,17 @@ let get_link_stats () =
98106

99107
let cache = Link.cache_alloc s in
100108
let links = Link.cache_to_list cache in
101-
let devs = List.map (fun link ->
102-
let name = standardise_name (Link.get_name link) in
109+
let links =
110+
List.map (fun link ->
111+
(standardise_name (Link.get_name link)), link
112+
) links |>
113+
List.filter (fun (name,link) ->
114+
let is_monitor_blacklisted = List.exists (fun s -> String.startswith s name) !monitor_blacklist ||
115+
(String.startswith "eth" name && String.contains name '.') in
116+
not is_monitor_blacklisted
117+
) in
118+
119+
let devs = List.map (fun (name,link) ->
103120
let convert x = Int64.of_int (Unsigned.UInt64.to_int x) in
104121
let eth_stat = {default_stats with
105122
rx_bytes = Link.get_stat link Link.RX_BYTES |> convert;
@@ -111,13 +128,6 @@ let get_link_stats () =
111128
} in
112129
name, eth_stat
113130
) links in
114-
let devs = List.filter (fun (name, _) ->
115-
not(String.startswith "dummy" name) &&
116-
not(String.startswith "xenbr" name) &&
117-
not(String.startswith "xapi" name) &&
118-
not(String.startswith "eth" name && String.contains name '.') &&
119-
name <> "ovs-system"
120-
) devs in
121131

122132
Cache.free cache;
123133
Socket.close s;

networkd/networkd.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
open Pervasiveext
1616
open Fun
1717
open Network_utils
18+
open Xstringext
1819

1920
module D = Debug.Make(struct let name = "networkd" end)
2021
open D
@@ -42,6 +43,10 @@ let resources = [
4243
}
4344
]
4445

46+
let options = [
47+
"monitor_blacklist", Arg.String (fun x -> Network_monitor_thread.monitor_blacklist := String.split ',' x), (fun () -> String.concat "," !Network_monitor_thread.monitor_blacklist), "List of prefixes of interface names that are not to be monitored";
48+
]
49+
4550
let start server =
4651
Network_monitor_thread.start ();
4752
Network_server.on_startup ();
@@ -70,7 +75,7 @@ let _ =
7075
begin match Xcp_service.configure2
7176
~name:Sys.argv.(0)
7277
~version:Version.version
73-
~doc ~resources () with
78+
~doc ~options ~resources () with
7479
| `Ok () -> ()
7580
| `Error m ->
7681
Printf.fprintf stderr "%s\n" m;

xcp-networkd.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Configuration file for xcp-networkd
2+
3+
# Default paths to search for binaries
4+
# search-path=
5+
6+
# The location of the inventory file
7+
#inventory = /etc/xensource-inventory
8+
9+
# True to use the message switch; false for direct Unix domain socket
10+
# comms
11+
#use-switch = false
12+
13+
#The location of brctl tool
14+
#brctl=/usr/sbin/brctl
15+
16+
# The location for network config file in host
17+
#network-conf=/etc/xensource/network.conf
18+
19+
#The list of prefix interfaces that are not to be monitored
20+
#monitor-blacklist=dummy,xenbr,xapi,ovs-system,xenapi

0 commit comments

Comments
 (0)