Skip to content

Commit

Permalink
Interface.update
Browse files Browse the repository at this point in the history
  • Loading branch information
robhoes committed Nov 23, 2010
1 parent 5b334ab commit 91166f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
39 changes: 24 additions & 15 deletions openvswitch.ml
Expand Up @@ -60,22 +60,24 @@ module Interface = struct
| Select_result [row] -> make row
| _ -> failwith "Unexpected response"

let make_row ?ty name =
[
"name", Atom (String name);
] @
match ty with
| None -> []
| Some System -> ["type", Atom (String "system")]
| Some Internal -> ["type", Atom (String "internal")]
| Some Tap -> ["type", Atom (String "tap")]
| Some (Gre (remote_ip, options)) ->
["type", Atom (String "gre"); "options", Map [String "remote_ip", String remote_ip]]
| Some (Capwap (remote_ip, options)) ->
["type", Atom (String "capwap"); "options", Map [String "remote_ip", String remote_ip]]
| Some (Patch peer) ->
["type", Atom (String "patch"); "options", Map [String "peer", String peer]]

let create ?port ?ty name =
let row = [
"name", Atom (String name);
] @
match ty with
| None -> []
| Some System -> ["type", Atom (String "system")]
| Some Internal -> ["type", Atom (String "internal")]
| Some Tap -> ["type", Atom (String "tap")]
| Some (Gre (remote_ip, options)) ->
["type", Atom (String "gre"); "options", Map [String "remote_ip", String remote_ip]]
| Some (Capwap (remote_ip, options)) ->
["type", Atom (String "capwap"); "options", Map [String "remote_ip", String remote_ip]]
| Some (Patch peer) ->
["type", Atom (String "patch"); "options", Map [String "peer", String peer]]
in
let row = make_row ?ty name in
let result = do_call (insert "Interface" row None) in
let uuid = match result with
| Insert_result u -> u
Expand All @@ -97,6 +99,13 @@ module Interface = struct
match results with
| [_; Delete_result count] -> count
| _ -> failwith "Unexpected response"

let update uuid interface =
let row = make_row ~ty:interface.ty interface.name in
let result = do_call (update "Interface" ["_uuid", Eq, Atom (Uuid uuid)] row) in
match result with
| Update_result count -> count
| _ -> failwith "Unexpected response"
end

module Port = struct
Expand Down
1 change: 1 addition & 0 deletions openvswitch.mli
Expand Up @@ -60,6 +60,7 @@ module Interface :
val get : string -> t
val create : ?port:string -> ?ty:iftype -> string -> string
val destroy : string -> int
val update: string -> t -> int
end
module Port :
sig
Expand Down
4 changes: 4 additions & 0 deletions openvswitch_test.ml
Expand Up @@ -32,6 +32,10 @@ let _ =
let interface = Interface.create ~port ~ty:(Interface.Gre("10.80.3.142", [])) "newif" in
print_endline ("Created interface: " ^ interface);

let interface_rec = Interface.get interface in
let n = Interface.update interface {interface_rec with Interface.name = "newerif"} in
print_endline ("Modified interface: " ^ interface);

let bridges = Bridge.get_all () in
List.iter show_bridge bridges;
print_endline "====";
Expand Down

0 comments on commit 91166f1

Please sign in to comment.