-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
T6489: Add support for CLI config scripts that change the underlaying working configuration
- Loading branch information
Showing
7 changed files
with
70 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2018-2023 VyOS maintainers and contributors <[email protected]> | ||
# Copyright 2018-2024 VyOS maintainers and contributors <[email protected]> | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
|
@@ -35,6 +35,7 @@ | |
'vyos_udev_dir' : '/run/udev/vyos', | ||
'isc_dhclient_dir' : '/run/dhclient', | ||
'dhcp6_client_dir' : '/run/dhcp6c', | ||
'vyos_configdir' : '/opt/vyatta/config' | ||
} | ||
|
||
config_status = '/tmp/vyos-config-status' | ||
|
@@ -44,7 +45,7 @@ | |
|
||
cfg_vintage = 'vyos' | ||
|
||
commit_lock = '/opt/vyatta/config/.lock' | ||
commit_lock = os.path.join(directories['vyos_configdir'], '.lock') | ||
|
||
component_version_json = os.path.join(directories['data'], 'component-versions.json') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 VyOS maintainers and contributors <[email protected]> | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# 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/>. | ||
|
||
import os | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters