# HG changeset patch # User Rob Hoes # Date 1278671712 -3600 # Node ID 2c476bb5574a9e4c53960dd759d03578c20a31ea # Parent db0b2881600350f6051dbfd2ca8b8dd7237fab4d Tunnelling: add CLI support (xe tunnel-...) Signed-off-by: Rob Hoes diff -r db0b28816003 -r 2c476bb5574a ocaml/client_records/records.ml --- a/ocaml/client_records/records.ml +++ b/ocaml/client_records/records.ml @@ -156,6 +156,29 @@ make_field ~name:"tag" ~get:(fun () -> Int64.to_string (x ()).API.vLAN_tag) (); ] } + +let tunnel_record rpc session_id tunnel = + let _ref = ref tunnel in + let empty_record = ToGet (fun () -> Client.Tunnel.get_record rpc session_id !_ref) in + let record = ref empty_record in + let x () = lzy_get record in + { setref=(fun r -> _ref := r; record := empty_record ); + setrefrec=(fun (a,b) -> _ref := a; record := Got b); + record=x; + getref=(fun () -> !_ref); + fields= + [ + make_field ~name:"uuid" ~get:(fun () -> (x ()).API.tunnel_uuid) (); + make_field ~name:"access-PIF" ~get:(fun () -> get_uuid_from_ref (x ()).API.tunnel_access_PIF) (); + make_field ~name:"transport-PIF" ~get:(fun () -> get_uuid_from_ref (x ()).API.tunnel_transport_PIF) (); + make_field ~name:"status" ~get:(fun () -> Record_util.s2sm_to_string "; " (x ()).API.tunnel_status) (); + make_field ~name:"other-config" ~get:(fun () -> Record_util.s2sm_to_string "; " (x ()).API.tunnel_other_config) + ~add_to_map:(fun k v -> Client.Tunnel.add_to_other_config rpc session_id tunnel k v) + ~remove_from_map:(fun k -> Client.Tunnel.remove_from_other_config rpc session_id tunnel k) + ~get_map:(fun () -> (x ()).API.tunnel_other_config) (); + + ] + } let message_record rpc session_id message = let _ref = ref message in diff -r db0b28816003 -r 2c476bb5574a ocaml/xapi/cli_frontend.ml --- a/ocaml/xapi/cli_frontend.ml +++ b/ocaml/xapi/cli_frontend.ml @@ -1353,6 +1353,24 @@ implementation=No_fd Cli_operations.vlan_destroy; flags=[]; }; + + "tunnel-create", + { + reqd=["pif-uuid"; "network-uuid"]; + optn=[]; + help="Create a new tunnel on a host."; + implementation= No_fd Cli_operations.tunnel_create; + flags=[]; + }; + + "tunnel-destroy", + { + reqd=["uuid"]; + optn=[]; + help="Destroy a tunnel."; + implementation=No_fd Cli_operations.tunnel_destroy; + flags=[]; + }; "pif-unplug", { diff -r db0b28816003 -r 2c476bb5574a ocaml/xapi/cli_operations.ml --- a/ocaml/xapi/cli_operations.ml +++ b/ocaml/xapi/cli_operations.ml @@ -680,7 +680,8 @@ (make_param_funs (Client.Pool.get_all) (Client.Pool.get_all_records_where) (Client.Pool.get_by_uuid) (pool_record) "pool" [] ["uuid";"name-label";"name-description";"master";"default-SR"] rpc session_id) @ (make_param_funs (Client.PIF.get_all) (Client.PIF.get_all_records_where) (Client.PIF.get_by_uuid) (pif_record) "pif" [] ["uuid";"device";"VLAN";"mac";"network-uuid"; "currently-attached"] rpc session_id) @ (make_param_funs (Client.Bond.get_all) (Client.Bond.get_all_records_where) (Client.Bond.get_by_uuid) (bond_record) "bond" [] ["uuid";"master";"slaves"] rpc session_id) @ - (make_param_funs (Client.VLAN.get_all) (Client.VLAN.get_all_records_where) (Client.VLAN.get_by_uuid) (vlan_record) "vlan" [] ["uuid";"tagged-PIF";"untagged-PIF"; "tag"] rpc session_id) @ + (make_param_funs (Client.VLAN.get_all) (Client.VLAN.get_all_records_where) (Client.VLAN.get_by_uuid) (vlan_record) "vlan" [] ["uuid";"tagged-PIF";"untagged-PIF"; "tag"] rpc session_id) @ + (make_param_funs (Client.Tunnel.get_all) (Client.Tunnel.get_all_records_where) (Client.Tunnel.get_by_uuid) (tunnel_record) "tunnel" [] ["uuid";"transport-PIF";"access-PIF";"status"] rpc session_id) @ (make_param_funs (Client.VIF.get_all) (Client.VIF.get_all_records_where) (Client.VIF.get_by_uuid) (vif_record) "vif" [] ["uuid";"device";"vm-uuid";"network-uuid"] rpc session_id) @ (make_param_funs (Client.Network.get_all) (Client.Network.get_all_records_where) (Client.Network.get_by_uuid) (net_record) "network" [] ["uuid";"name-label";"name-description";"bridge"] rpc session_id) @ (make_param_funs (Client.Console.get_all) (Client.Console.get_all_records_where) (Client.Console.get_by_uuid) (console_record) "console" [] ["uuid";"vm-uuid";"vm-name-label";"protocol";"location"] rpc session_id) @ @@ -3205,6 +3206,18 @@ let pif = Client.PIF.get_by_uuid rpc session_id uuid in Client.PIF.destroy rpc session_id pif +let tunnel_create printer rpc session_id params = + let network = Client.Network.get_by_uuid rpc session_id (List.assoc "network-uuid" params) in + let pif = Client.PIF.get_by_uuid rpc session_id (List.assoc "pif-uuid" params) in + let tunnel = Client.Tunnel.create rpc session_id pif network in + let pif' = Client.Tunnel.get_access_PIF rpc session_id tunnel in + let uuid = Client.PIF.get_uuid rpc session_id pif' in + printer (Cli_printer.PList [uuid]) + +let tunnel_destroy printer rpc session_id params = + let uuid = List.assoc "uuid" params in + let tunnel = Client.Tunnel.get_by_uuid rpc session_id uuid in + Client.Tunnel.destroy rpc session_id tunnel let pif_reconfigure_ip printer rpc session_id params = let read_optional_case_insensitive key =