Skip to content

Commit 6a2e175

Browse files
committed
T7737: use vyconf aware add/delete_cli_node if enabled
1 parent 8ca1475 commit 6a2e175

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

python/vyos/utils/configfs.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,57 @@
1313
# You should have received a copy of the GNU Lesser General Public
1414
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
1515

16+
# pylint: disable=import-outside-toplevel
17+
1618
import os
1719

20+
from vyos.utils.backend import vyconf_backend
21+
from vyos.utils.boot import boot_configuration_complete
22+
23+
1824
def delete_cli_node(cli_path: list):
19-
from shutil import rmtree
20-
for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
21-
tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
22-
# delete CLI node
23-
if os.path.exists(tmp):
24-
rmtree(tmp)
25-
26-
def add_cli_node(cli_path: list, value: str=None):
27-
from vyos.utils.auth import get_current_user
28-
from vyos.utils.file import write_file
29-
30-
current_user = get_current_user()
31-
for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
32-
# store new value
33-
tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
34-
write_file(f'{tmp}/node.val', value, user=current_user, group='vyattacfg', mode=0o664)
35-
# mark CLI node as modified
36-
if config_dir == 'VYATTA_CHANGES_ONLY_DIR':
37-
write_file(f'{tmp}/.modified', '', user=current_user, group='vyattacfg', mode=0o664)
25+
if vyconf_backend() and boot_configuration_complete():
26+
# pylint: disable=redefined-outer-name
27+
from vyos.utils.session import delete_cli_node
28+
29+
delete_cli_node(cli_path)
30+
else:
31+
from shutil import rmtree
32+
33+
for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
34+
tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
35+
# delete CLI node
36+
if os.path.exists(tmp):
37+
rmtree(tmp)
38+
39+
40+
def add_cli_node(cli_path: list, value: str = None):
41+
if vyconf_backend() and boot_configuration_complete():
42+
# pylint: disable=redefined-outer-name
43+
from vyos.utils.session import add_cli_node
44+
45+
add_cli_node(cli_path, value)
46+
else:
47+
from vyos.utils.auth import get_current_user
48+
from vyos.utils.file import write_file
49+
50+
current_user = get_current_user()
51+
for config_dir in ['VYATTA_TEMP_CONFIG_DIR', 'VYATTA_CHANGES_ONLY_DIR']:
52+
# store new value
53+
tmp = os.path.join(os.environ[config_dir], '/'.join(cli_path))
54+
write_file(
55+
f'{tmp}/node.val',
56+
value,
57+
user=current_user,
58+
group='vyattacfg',
59+
mode=0o664,
60+
)
61+
# mark CLI node as modified
62+
if config_dir == 'VYATTA_CHANGES_ONLY_DIR':
63+
write_file(
64+
f'{tmp}/.modified',
65+
'',
66+
user=current_user,
67+
group='vyattacfg',
68+
mode=0o664,
69+
)

0 commit comments

Comments
 (0)