From 6502d8b21e0dd7fb5efe012742dd46d3547cdfff Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 24 Feb 2026 21:54:04 -0600 Subject: T8313: add copy/rename request handlers --- src/session.ml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/session.ml') diff --git a/src/session.ml b/src/session.ml index 53a8c7f..7658028 100644 --- a/src/session.ml +++ b/src/session.ml @@ -267,6 +267,53 @@ let aux_delete w s path name tagval = let discard _w s = { s with changeset = []; } +let copy w s p1 p2 = + if Vyos1x.Util.is_empty p1 + then raise (Session_error "Cannot copy an empty path") + else + if Vyos1x.Util.is_empty p2 + then raise (Session_error "Cannot copy to an empty path") + else + let p1_total = s.edit_level @ p1 in + let p2_total = s.edit_level @ p2 in + let ct = get_proposed_config w s in + if not ((VT.exists[@alert "-exn"]) ct p1_total) + then + let p1_str = Vyos1x.Util.string_of_list p1_total in + let out = Printf.sprintf "Configuration path \"%s\" does not exist" p1_str in + raise (Session_error out) + else + let _ = validate w s p2_total in + let ct' = (VT.copy[@alert "-exn"]) ct p1_total p2_total in + let changeset' = get_changeset w s ct ct' in + { s with changeset = changeset' @ s.changeset } + +let rename w s p1 p2 = + if Vyos1x.Util.is_empty p1 + then raise (Session_error "Cannot rename an empty path") + else + let p2_last = + match Vyos1x.Util.get_last p2 with + | None -> raise (Session_error "Cannot rename to an empty value") + | Some v -> v + in + if (Vyos1x.Util.drop_last p1) <> (Vyos1x.Util.drop_last p2) + then raise (Session_error "Cannot rename a node: paths are inconsistent") + else + let p1_total = s.edit_level @ p1 in + let p2_total = s.edit_level @ p2 in + let ct = get_proposed_config w s in + if not ((VT.exists[@alert "-exn"]) ct p1_total) + then + let p1_str = Vyos1x.Util.string_of_list p1_total in + let out = Printf.sprintf "Configuration path \"%s\" does not exist" p1_str in + raise (Session_error out) + else + let _ = validate w s p2_total in + let ct' = (VT.rename[@alert "-exn"]) ct p1_total p2_last in + let changeset' = get_changeset w s ct ct' in + { s with changeset = changeset' @ s.changeset } + let edit_env_str s = (* To maintain consistency with classic CLI, we return env variable for PS1 on changes to edit level. -- cgit v1.2.3