1515
1616# pylint: disable=import-outside-toplevel
1717
18+ import os
19+ from inspect import stack
20+
1821
1922def in_config_session ():
2023 """Vyatta bash completion uses the following environment variable for
@@ -23,3 +26,45 @@ def in_config_session():
2326 from os import environ
2427
2528 return '_OFR_CONFIGURE' in environ
29+
30+
31+ # utility for functions below
32+ def get_caller_name () -> str :
33+ filename = stack ()[2 ].filename
34+ return os .path .basename (filename )
35+
36+
37+ # OOB operations used (rarely) to update the session config during commit
38+ # execution of config mode scripts.
39+ # The standard use is for replacing plaintext with encrypted passwords in
40+ # the session config during commit.
41+ def delete_cli_node (cli_path : list ):
42+ from vyos .vyconf_session import VyconfSession
43+ from vyos .configsession import ConfigSessionError
44+
45+ pid = os .environ .get ('SESSION_PID' , '' )
46+ if not pid :
47+ raise ValueError ('Missing env var SESSION_PID' )
48+
49+ script_name = get_caller_name ()
50+ tag_value = os .environ .get ('VYOS_TAGNODE_VALUE' , None )
51+
52+ vs = VyconfSession (pid = pid , on_error = ConfigSessionError )
53+ vs .aux_delete (cli_path , script_name , tag_value )
54+
55+
56+ def add_cli_node (cli_path : list , value : str = None ):
57+ from vyos .vyconf_session import VyconfSession
58+ from vyos .configsession import ConfigSessionError
59+
60+ pid = os .environ .get ('SESSION_PID' , '' )
61+ if not pid :
62+ raise ValueError ('Missing env var SESSION_PID' )
63+
64+ script_name = get_caller_name ()
65+ tag_value = os .environ .get ('VYOS_TAGNODE_VALUE' , None )
66+
67+ cli_path = cli_path + [value ] if value else cli_path
68+
69+ vs = VyconfSession (pid = pid , on_error = ConfigSessionError )
70+ vs .aux_set (cli_path , script_name , tag_value )
0 commit comments