summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-09-10 21:15:06 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-09-18 07:43:21 -0500
commit6a2e175e584795216ea67c8aed29df69bfeb3715 (patch)
treedb36ed1a9feda385ce0f0136974d6ffecc2e4ecf /python
parent8ca1475b2b1c43819be74c94b53f9cc3509fdc81 (diff)
downloadvyos-1x-6a2e175e584795216ea67c8aed29df69bfeb3715.tar.gz
vyos-1x-6a2e175e584795216ea67c8aed29df69bfeb3715.zip
T7737: use vyconf aware add/delete_cli_node if enabled
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/configfs.py70
1 files changed, 51 insertions, 19 deletions
diff --git a/python/vyos/utils/configfs.py b/python/vyos/utils/configfs.py
index 307e1446c..72332ae42 100644
--- a/python/vyos/utils/configfs.py
+++ b/python/vyos/utils/configfs.py
@@ -13,25 +13,57 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+# pylint: disable=import-outside-toplevel
+
import os
+from vyos.utils.backend import vyconf_backend
+from vyos.utils.boot import boot_configuration_complete
+
+
def delete_cli_node(cli_path: list):
- from shutil import rmtree
- for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
- tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
- # delete CLI node
- if os.path.exists(tmp):
- rmtree(tmp)
-
-def add_cli_node(cli_path: list, value: str=None):
- from vyos.utils.auth import get_current_user
- from vyos.utils.file import write_file
-
- current_user = get_current_user()
- for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
- # store new value
- tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
- write_file(f'{tmp}/node.val', value, user=current_user, group='vyattacfg', mode=0o664)
- # mark CLI node as modified
- if config_dir == 'VYATTA_CHANGES_ONLY_DIR':
- write_file(f'{tmp}/.modified', '', user=current_user, group='vyattacfg', mode=0o664)
+ if vyconf_backend() and boot_configuration_complete():
+ # pylint: disable=redefined-outer-name
+ from vyos.utils.session import delete_cli_node
+
+ delete_cli_node(cli_path)
+ else:
+ from shutil import rmtree
+
+ for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
+ tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
+ # delete CLI node
+ if os.path.exists(tmp):
+ rmtree(tmp)
+
+
+def add_cli_node(cli_path: list, value: str = None):
+ if vyconf_backend() and boot_configuration_complete():
+ # pylint: disable=redefined-outer-name
+ from vyos.utils.session import add_cli_node
+
+ add_cli_node(cli_path, value)
+ else:
+ from vyos.utils.auth import get_current_user
+ from vyos.utils.file import write_file
+
+ current_user = get_current_user()
+ for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
+ # store new value
+ tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
+ write_file(
+ f'{tmp}/node.val',
+ value,
+ user=current_user,
+ group='vyattacfg',
+ mode=0o664,
+ )
+ # mark CLI node as modified
+ if config_dir == 'VYATTA_CHANGES_ONLY_DIR':
+ write_file(
+ f'{tmp}/.modified',
+ '',
+ user=current_user,
+ group='vyattacfg',
+ mode=0o664,
+ )