From b50a8d2b1d7af48a66446d71dd3875307cc2b1e0 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Fri, 9 May 2025 21:32:41 -0500 Subject: T7363: add get_config(s) request for Config instance initialization Request cache of session running and proposed configs for loading on intialization of Config instance. As used elsewhere (for example vyos-commitd), this is a much faster method of exchanging information than render and re-parse. --- src/session.ml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/session.ml') diff --git a/src/session.ml b/src/session.ml index e7be5d7..9ce2807 100644 --- a/src/session.ml +++ b/src/session.ml @@ -160,6 +160,36 @@ let prepare_commit ?(dry_run=false) w s id = in CC.make_commit_data ~dry_run:dry_run rt at wt id +let get_config w s id = + let at = w.running_config in + let wt = s.proposed_config in + let vc = w.vyconf_config in + let running_cache = Printf.sprintf "%s_%s" vc.running_cache id in + let session_cache = Printf.sprintf "%s_%s" vc.session_cache id in + let () = + try + IC.write_internal at (FP.concat vc.session_dir running_cache) + with + Vyos1x.Internal.Write_error msg -> raise (Session_error msg) + in + let () = + try + IC.write_internal wt (FP.concat vc.session_dir session_cache) + with + Vyos1x.Internal.Write_error msg -> raise (Session_error msg) + in id + +let cleanup_config w id = + let remove_file file = + if Sys.file_exists file then + Sys.remove file + in + let vc = w.vyconf_config in + let running_cache = Printf.sprintf "%s_%s" vc.running_cache id in + let session_cache = Printf.sprintf "%s_%s" vc.session_cache id in + remove_file (FP.concat vc.session_dir running_cache); + remove_file (FP.concat vc.session_dir session_cache) + let get_value w s path = if not (VT.exists s.proposed_config path) then raise (Session_error ("Config path does not exist")) -- cgit v1.2.3