diff options
| author | John Estabrook <jestabro@vyos.io> | 2025-05-09 21:32:41 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2025-05-12 17:24:24 -0500 |
| commit | b50a8d2b1d7af48a66446d71dd3875307cc2b1e0 (patch) | |
| tree | be11d3f1e97ca5818e02c9155f953e0df42a552b /src/session.ml | |
| parent | d4d8d619a70e81229927bf0268d8c1257fd7e5cd (diff) | |
| download | vyconf-b50a8d2b1d7af48a66446d71dd3875307cc2b1e0.tar.gz vyconf-b50a8d2b1d7af48a66446d71dd3875307cc2b1e0.zip | |
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.
Diffstat (limited to 'src/session.ml')
| -rw-r--r-- | src/session.ml | 30 |
1 files changed, 30 insertions, 0 deletions
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")) |
