diff options
Diffstat (limited to 'python/vyos/frr.py')
| -rw-r--r-- | python/vyos/frr.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/python/vyos/frr.py b/python/vyos/frr.py index 69c7a14ce..668489636 100644 --- a/python/vyos/frr.py +++ b/python/vyos/frr.py @@ -68,6 +68,7 @@ Apply the new configuration: import tempfile import re from vyos import util +from vyos.util import chown import logging from logging.handlers import SysLogHandler import os @@ -86,6 +87,7 @@ _frr_daemons = ['zebra', 'bgpd', 'fabricd', 'isisd', 'ospf6d', 'ospfd', 'pbrd', path_vtysh = '/usr/bin/vtysh' path_frr_reload = '/usr/lib/frr/frr-reload.py' +path_config = '/run/frr' class FrrError(Exception): @@ -207,6 +209,30 @@ def reload_configuration(config, daemon=None): return output +def save_configuration(daemon=None): + """Save FRR configuration to /run/frr/{daemon}.conf + It save configuration on each commit. + """ + if daemon and daemon not in _frr_daemons: + raise ValueError(f'The specified daemon type is not supported {repr(daemon)}') + + cmd = f"{path_vtysh} -d {daemon} -c 'show run no-header'" + output, code = util.popen(cmd, stderr=util.STDOUT) + if code: + raise OSError(code, output) + + daemon_conf = f'{path_config}/{daemon}.conf' + + with open(daemon_conf, "w") as f: + f.write(output) + # Set permissions (frr:frr) for /run/frr/{daemon}.conf + if os.path.exists(daemon_conf): + chown(daemon_conf, 'frr', 'frr') + config = output + + return config + + def execute(command): """ Run commands inside vtysh command: str containing commands to execute inside a vtysh session |
