From ad2d932768734b492a54c728b459437056460668 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Fri, 4 Apr 2025 22:48:30 -0500 Subject: T7321: add save config operation --- src/session.ml | 7 +++++++ src/session.mli | 2 ++ src/vyconfd.ml | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/src/session.ml b/src/session.ml index 1843682..5f0d5a3 100644 --- a/src/session.ml +++ b/src/session.ml @@ -114,6 +114,13 @@ let load w s file = | Ok config -> validate_tree w config; {s with proposed_config=config;} +let save w s file = + let ct = w.running_config in + let res = Vyos1x.Config_file.save_config ct file in + match res with + | Error e -> raise (Session_error (Printf.sprintf "Error saving config: %s" e)) + | Ok () -> s + let get_value w s path = if not (VT.exists s.proposed_config path) then raise (Session_error ("Config path does not exist")) diff --git a/src/session.mli b/src/session.mli index fec6a4b..f756858 100644 --- a/src/session.mli +++ b/src/session.mli @@ -34,6 +34,8 @@ val delete : world -> session_data -> string list -> session_data val load : world -> session_data -> string -> session_data +val save : world -> session_data -> string -> session_data + val get_value : world -> session_data -> string list -> string val get_values : world -> session_data -> string list -> string list diff --git a/src/vyconfd.ml b/src/vyconfd.ml index 960e523..e531278 100644 --- a/src/vyconfd.ml +++ b/src/vyconfd.ml @@ -171,6 +171,13 @@ let load world token (req: request_load) = response_tmpl with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)} +let save world token (req: request_save) = + try + let _ = Session.save world (find_session token) req.location + in + response_tmpl + with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)} + let commit world token (req: request_commit) = let s = find_session token in let at = world.Session.running_config in @@ -260,6 +267,7 @@ let rec handle_connection world ic oc () = | Some t, Set r -> set world t r | Some t, Delete r -> delete world t r | Some t, Load r -> load world t r + | Some t, Save r -> save world t r | _ -> failwith "Unimplemented" ) |> Lwt.return end -- cgit v1.2.3