summaryrefslogtreecommitdiff
path: root/tools/frr-reload.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/frr-reload.py')
-rwxr-xr-xtools/frr-reload.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/tools/frr-reload.py b/tools/frr-reload.py
index 25922e3bf7..a72e5c2772 100755
--- a/tools/frr-reload.py
+++ b/tools/frr-reload.py
@@ -63,14 +63,17 @@ class VtyshException(Exception):
pass
class Vtysh(object):
- def __init__(self, bindir=None, confdir=None, sockdir=None):
+ def __init__(self, bindir=None, confdir=None, sockdir=None, pathspace=None):
self.bindir = bindir
self.confdir = confdir
+ self.pathspace = pathspace
self.common_args = [os.path.join(bindir or '', 'vtysh')]
if confdir:
self.common_args.extend(['--config_dir', confdir])
if sockdir:
self.common_args.extend(['--vty_socket', sockdir])
+ if pathspace:
+ self.common_args.extend(['-N', pathspace])
def _call(self, args, stdin=None, stdout=None, stderr=None):
kwargs = {}
@@ -728,6 +731,36 @@ def line_exist(lines, target_ctx_keys, target_line, exact_match=True):
return True
return False
+def check_for_exit_vrf(lines_to_add, lines_to_del):
+
+ # exit-vrf is a bit tricky. If the new config is missing it but we
+ # have configs under a vrf, we need to add it at the end to do the
+ # right context changes. If exit-vrf exists in both the running and
+ # new config, we cannot delete it or it will break context changes.
+ add_exit_vrf = False
+ index = 0
+
+ for (ctx_keys, line) in lines_to_add:
+ if add_exit_vrf == True:
+ if ctx_keys[0] != prior_ctx_key:
+ insert_key=(prior_ctx_key),
+ lines_to_add.insert(index, ((insert_key, "exit-vrf")))
+ add_exit_vrf = False
+
+ if ctx_keys[0].startswith('vrf') and line:
+ if line is not "exit-vrf":
+ add_exit_vrf = True
+ prior_ctx_key = (ctx_keys[0])
+ else:
+ add_exit_vrf = False
+ index+=1
+
+ for (ctx_keys, line) in lines_to_del:
+ if line == "exit-vrf":
+ if (line_exist(lines_to_add, ctx_keys, line)):
+ lines_to_del.remove((ctx_keys, line))
+
+ return (lines_to_add, lines_to_del)
def ignore_delete_re_add_lines(lines_to_add, lines_to_del):
@@ -1155,6 +1188,7 @@ def compare_context_objects(newconf, running):
for line in newconf_ctx.lines:
lines_to_add.append((newconf_ctx_keys, line))
+ (lines_to_add, lines_to_del) = check_for_exit_vrf(lines_to_add, lines_to_del)
(lines_to_add, lines_to_del) = ignore_delete_re_add_lines(lines_to_add, lines_to_del)
(lines_to_add, lines_to_del) = ignore_unconfigurable_lines(lines_to_add, lines_to_del)
@@ -1174,6 +1208,7 @@ if __name__ == '__main__':
level_group.add_argument('--log-level', help='Log level', default="info",
choices=("critical", "error", "warning", "info", "debug"))
parser.add_argument('--stdout', action='store_true', help='Log to STDOUT', default=False)
+ parser.add_argument('--pathspace', '-N', metavar='NAME', help='Reload specified path/namespace', default=None)
parser.add_argument('filename', help='Location of new frr config file')
parser.add_argument('--overwrite', action='store_true', help='Overwrite frr.conf with running config output', default=False)
parser.add_argument('--bindir', help='path to the vtysh executable', default='/usr/bin')
@@ -1251,10 +1286,13 @@ if __name__ == '__main__':
log.error("Daemon %s is not a valid option for 'show running-config'" % args.daemon)
sys.exit(1)
- vtysh = Vtysh(args.bindir, args.confdir, args.vty_socket)
+ vtysh = Vtysh(args.bindir, args.confdir, args.vty_socket, args.pathspace)
# Verify that 'service integrated-vtysh-config' is configured
- vtysh_filename = args.confdir + '/vtysh.conf'
+ if args.pathspace:
+ vtysh_filename = args.confdir + '/' + args.pathspace + '/vtysh.conf'
+ else:
+ vtysh_filename = args.confdir + '/vtysh.conf'
service_integrated_vtysh_config = True
if os.path.isfile(vtysh_filename):