Skip to content

Commit

Permalink
Merge pull request xapi-project#3 from djs55/xenswitch
Browse files Browse the repository at this point in the history
Update to use new switch-capable xcp-idl
  • Loading branch information
djs55 committed May 23, 2013
2 parents d371158 + e6b2f07 commit a42b543
Showing 1 changed file with 13 additions and 46 deletions.
59 changes: 13 additions & 46 deletions networkd/networkd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,15 @@
* GNU Lesser General Public License for more details.
*)

let name = "xcp-networkd"

open Pervasiveext
open Fun
open Network_utils

module D = Debug.Debugger(struct let name = "networkd" end)
open D

let server = Http_svr.Server.empty ()

let path = Filename.concat "/var/lib/xcp" name

module Server = Network_interface.Server(Network_server)

let xmlrpc_handler process req bio context =
let body = Http_svr.read_body req bio in
let s = Buf_io.fd_of bio in
let rpc = Xmlrpc.call_of_string body in
try
let result = process context rpc in
let str = Xmlrpc.string_of_response result in
Http_svr.response_str req s str
with e ->
debug "Caught %s" (Printexc.to_string e);
debug "Backtrace: %s" (Printexc.get_backtrace ());
Http_svr.response_unauthorised ~req (Printf.sprintf "Go away: %s" (Printexc.to_string e)) s

let start_server path process =
Http_svr.Server.add_handler server Http.Post "/" (Http_svr.BufIO (xmlrpc_handler process));

debug "Listening on %s" path;
Unixext.mkdir_safe (Filename.dirname path) 0o700;
Unixext.unlink_safe path;
let domain_sock = Http_svr.bind (Unix.ADDR_UNIX(path)) "unix_rpc" in
Http_svr.start server domain_sock;

let localhost = Unix.inet_addr_of_string "127.0.0.1" in
let localhost_sock = Http_svr.bind (Unix.ADDR_INET(localhost, 4094)) "inet-RPC" in
Http_svr.start server localhost_sock;

()

let resources = [
{ Xcp_service.name = "brctl";
description = "used to set up bridges";
Expand All @@ -70,10 +36,13 @@ let resources = [
}
]

let start () =
let start server =
Network_monitor_thread.start ();
Network_server.on_startup ();
start_server path Server.process
let (_: Thread.t) = Thread.create (fun () ->
Xcp_service.serve_forever server
) () in
()

let stop signal =
Network_server.on_shutdown signal;
Expand All @@ -86,25 +55,23 @@ let handle_shutdown () =
Sys.set_signal Sys.sigpipe Sys.Signal_ignore

let _ =
let pidfile = ref "" in
Xcp_service.configure ~resources ();

if !Xcp_service.daemon then begin
Xcp_service.daemonize ();
end;
let server = Xcp_service.make
~path:!Network_interface.default_path
~queue_name:!Network_interface.queue_name
~rpc_fn:(Server.process ())
() in

Xcp_service.maybe_daemonize ();

Debug.set_facility Syslog_transitional.Local5;

(* We should make the following configurable *)
Debug.disable "http";

handle_shutdown ();
Debug.with_thread_associated "main" start ();

if !pidfile <> "" then begin
Unixext.mkdir_rec (Filename.dirname !pidfile) 0o755;
Unixext.pidfile_write !pidfile;
end;
Debug.with_thread_associated "main" start server;

while true do
Thread.delay 300.;
Expand Down

0 comments on commit a42b543

Please sign in to comment.