summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/session.ml26
-rw-r--r--src/session.mli2
-rw-r--r--src/vyconfd.ml14
3 files changed, 38 insertions, 4 deletions
diff --git a/src/session.ml b/src/session.ml
index 4829d76..5f70feb 100644
--- a/src/session.ml
+++ b/src/session.ml
@@ -269,6 +269,32 @@ let prepare_commit ?(dry_run=false) w config id pid sudo_user user =
in
CC.make_commit_data ~dry_run:dry_run rt at config id pid sudo_user user
+let post_process_commit w s ((c_data: CC.commit_data), proposed_config) =
+ let ident n v y =
+ if (y.script_name <> n || y.tag_value <> v) then false
+ else true
+ in
+ let func (running, proposed) (n_data: CC.node_data) =
+ match n_data.reply with
+ | None -> (running, proposed)
+ | Some reply ->
+ match reply.success with
+ | false -> (running, proposed)
+ | true ->
+ begin
+ let post =
+ VL.find
+ (ident n_data.script_name n_data.tag_value)
+ s.aux_changeset
+ in
+ match post with
+ | None -> (running, proposed)
+ | Some p ->
+ (apply_changes w p.changeset running, apply_changes w p.changeset proposed)
+ end
+ in
+ List.fold_left func (c_data.config_result, proposed_config) c_data.node_list
+
let get_config w s id =
let at = w.running_config in
let wt = get_proposed_config w s in
diff --git a/src/session.mli b/src/session.mli
index 96fa4d1..a08f873 100644
--- a/src/session.mli
+++ b/src/session.mli
@@ -71,6 +71,8 @@ val string_of_op : cfg_op -> string
val prepare_commit : ?dry_run:bool -> world -> Vyos1x.Config_tree.t -> string -> int32 -> string -> string -> Commitd_client.Commit.commit_data
+val post_process_commit : world -> session_data -> Commitd_client.Commit.commit_data * Vyos1x.Config_tree.t -> Vyos1x.Config_tree.t * Vyos1x.Config_tree.t
+
val get_config : world -> session_data -> string -> string
val cleanup_config : world -> string -> unit
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index 9e8c57e..05cd693 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -295,21 +295,27 @@ let commit world token (req: request_commit) =
let res, out =
init_data.success, init_data.out
in
+ let () =
+ (Lwt_log.debug @@ Printf.sprintf "aux_changeset: %s" (Session.sprint_changeset s.aux_changeset)) |> Lwt.ignore_result
+ in
match res with
| false ->
Lwt.return {response_tmpl with status=Internal_error; error=(Some out)}
| true ->
- (* partial commit *)
if not req_dry_run then
- world.Session.running_config <- result_commit_data.config_result;
+ let post_running, post_proposed =
+ Session.post_process_commit world s (result_commit_data, proposed_config)
+ in
+ world.Session.running_config <- post_running;
let session =
{ s with changeset =
Session.get_changeset
world
world.Session.running_config
- proposed_config;
+ post_proposed;
aux_changeset = []; }
- in Hashtbl.replace sessions token session;
+ in Hashtbl.replace sessions token session
+ else ();
let success, msg_str =
result_commit_data.result.success, result_commit_data.result.out