Skip to content

Commit

Permalink
Merge pull request #84 from jonludlam/packed-stdext
Browse files Browse the repository at this point in the history
Use packed stdext
  • Loading branch information
euanh authored Jul 1, 2016
2 parents 5335071 + 37c9a1e commit 7aa4234
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 28 deletions.
10 changes: 6 additions & 4 deletions .merlin
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ S lib
S networkd
S networkd_db
S test
B dist/build/lib-network-libs/
B dist/build/xcp-networkd
B dist/build/networkd_db
B dist/build/network_test
S profiling
B _build/profiling
B _build/lib
B _build/networkd
PKG forkexec
PKG rpclib
PKG stdext
Expand All @@ -17,3 +17,5 @@ PKG xcp-inventory
PKG xcp.network
PKG xcp.network
PKG xen-api-client
PKG oUnit
PKG bisect_ppx.runtime
7 changes: 3 additions & 4 deletions cli/network_cli.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
open Network_interface
open Network_client
open Cmdliner
open Xstringext

let dbg = "cli"

Expand Down Expand Up @@ -220,11 +219,11 @@ let get_dns_cmd =
let set_dns iface nameservers domains =
try
let ns = match nameservers with
| Some x -> List.map Unix.inet_addr_of_string (String.split ',' x)
| Some x -> List.map Unix.inet_addr_of_string (Stdext.Xstringext.String.split ',' x)
| None -> []
in
let d = match domains with
| Some x -> String.split ',' x
| Some x -> Stdext.Xstringext.String.split ',' x
| None -> []
in
Client.Interface.set_dns dbg iface ns d;
Expand Down Expand Up @@ -317,7 +316,7 @@ let list_br_cmd =
Term.info "list-br" ~doc ~man

let read_config path =
let config_json = Unixext.string_of_file path in
let config_json = Stdext.Unixext.string_of_file path in
config_json |> Jsonrpc.of_string |> config_t_of_rpc

let config path =
Expand Down
1 change: 1 addition & 0 deletions lib/network_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

open Network_interface

open Stdext
open Fun
open Xstringext

Expand Down
1 change: 1 addition & 0 deletions lib/network_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* GNU Lesser General Public License for more details.
*)

open Stdext
open Listext
open Xstringext
open Pervasiveext
Expand Down
6 changes: 1 addition & 5 deletions networkd/network_monitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
open Network_interface
include Network_stats

open Fun
open Xstringext
open Threadext

let write_stats stats =
let payload = stats |> rpc_of_stats_t |> Jsonrpc.to_string in
let checksum = payload |> Digest.string |> Digest.to_hex in
let length = String.length payload in
let data = Printf.sprintf "%s%s%08x%s" magic checksum length payload in
Unixext.write_string_to_file stats_file (data)
Stdext.Unixext.write_string_to_file stats_file (data)
2 changes: 1 addition & 1 deletion networkd/network_monitor_thread.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

open Network_utils

open Fun
open Stdext
open Xstringext
open Listext
open Threadext
Expand Down
20 changes: 10 additions & 10 deletions networkd/network_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
open Network_utils
open Network_interface

open Fun
open Xstringext
open Listext
(*open Fun*)
open Stdext.Xstringext
open Stdext.Listext

module D = Debug.Make(struct let name = "network_server" end)
open D
Expand Down Expand Up @@ -141,7 +141,7 @@ module Interface = struct
Ip.flush_ip_addr name
end
| DHCP4 ->
let gateway = Opt.default [] (Opt.map (fun n -> [`gateway n]) !config.gateway_interface) in
let gateway = Stdext.Opt.default [] (Stdext.Opt.map (fun n -> [`gateway n]) !config.gateway_interface) in
let dns =
if !config.dns_interface = None || !config.dns_interface = Some name then begin
debug "%s is the DNS interface" name;
Expand Down Expand Up @@ -260,7 +260,7 @@ module Interface = struct

let get_dns _ dbg ~name =
Debug.with_thread_associated dbg (fun () ->
let nameservers, domains = Unixext.file_lines_fold (fun (nameservers, domains) line ->
let nameservers, domains = Stdext.Unixext.file_lines_fold (fun (nameservers, domains) line ->
if String.startswith "nameserver" line then
let server = List.nth (String.split_f String.isspace line) 1 in
(Unix.inet_addr_of_string server) :: nameservers, domains
Expand All @@ -284,7 +284,7 @@ module Interface = struct
let domains' = if domains <> [] then ["search " ^ (String.concat " " domains)] else [] in
let nameservers' = List.map (fun ip -> "nameserver " ^ (Unix.string_of_inet_addr ip)) nameservers in
let lines = domains' @ nameservers' in
Unixext.write_string_to_file resolv_conf ((String.concat "\n" lines) ^ "\n")
Stdext.Unixext.write_string_to_file resolv_conf ((String.concat "\n" lines) ^ "\n")
end else
debug "%s is NOT the DNS interface" name
) ()
Expand Down Expand Up @@ -424,7 +424,7 @@ module Bridge = struct

let determine_backend () =
try
let backend = String.strip String.isspace (Unixext.string_of_file !network_conf) in
let backend = String.strip String.isspace (Stdext.Unixext.string_of_file !network_conf) in
match backend with
| "openvswitch" | "vswitch" -> backend_kind := Openvswitch
| "bridge" -> backend_kind := Bridge
Expand Down Expand Up @@ -503,7 +503,7 @@ module Bridge = struct
ignore (Brctl.create_bridge name);
Brctl.set_forwarding_delay name 0;
Sysfs.set_multicast_snooping name false;
Opt.iter (Ip.set_mac name) mac;
Stdext.Opt.iter (Ip.set_mac name) mac;
match vlan with
| None -> ()
| Some (parent, vlan) ->
Expand Down Expand Up @@ -852,12 +852,12 @@ let on_startup () =
(* Remove DNSDEV and GATEWAYDEV from Centos networking file, because the interfere
* with this daemon. *)
try
let file = String.rtrim (Unixext.string_of_file "/etc/sysconfig/network") in
let file = String.rtrim (Stdext.Unixext.string_of_file "/etc/sysconfig/network") in
let args = String.split '\n' file in
let args = List.map (fun s -> match (String.split '=' s) with k :: [v] -> k, v | _ -> "", "") args in
let args = List.filter (fun (k, v) -> k <> "DNSDEV" && k <> "GATEWAYDEV") args in
let s = String.concat "\n" (List.map (fun (k, v) -> k ^ "=" ^ v) args) ^ "\n" in
Unixext.write_string_to_file "/etc/sysconfig/network" s
Stdext.Unixext.write_string_to_file "/etc/sysconfig/network" s
with _ -> ()
in
try
Expand Down
1 change: 1 addition & 0 deletions networkd/networkd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* GNU Lesser General Public License for more details.
*)

open Stdext
open Pervasiveext
open Fun
open Network_utils
Expand Down
1 change: 0 additions & 1 deletion networkd_db/networkd_db.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* GNU Lesser General Public License for more details.
*)

open Fun
open Network_interface

let name = "networkd_db"
Expand Down
5 changes: 2 additions & 3 deletions test/network_test_lacp_properties.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* GNU Lesser General Public License for more details.
*)

open Fun
open OUnit
open Network_utils

Expand Down Expand Up @@ -91,7 +90,7 @@ let test_lacp_aggregation_key_vsctl arg () = skip_if true "Unimplemented" ;
print_endline answer ;
assert_bool "lacp_aggregation_key is passed to ovs-vsctl command"
(List.exists
(fun s -> (Xstringext.String.(strip isspace s) == answer))
(fun s -> (Stdext.Xstringext.String.(strip isspace s) == answer))
!OVS_Cli_test.vsctl_output)

(* Test case for bond_create with default lacp-{time,aggregation-key} settings.
Expand All @@ -115,7 +114,7 @@ let test_lacp_defaults_bond_create () =
List.iter
(fun arg ->
assert_bool "key=value argument pairs can't have missing values"
(let open Xstringext.String in
(let open Stdext.Xstringext.String in
arg |> strip isspace |> endswith "=" |> not))
!OVS_Cli_test.vsctl_output

Expand Down

0 comments on commit 7aa4234

Please sign in to comment.