mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-29 15:07:51 +00:00
frr-reload.py: Add python2 & python3 compatibility.
Signed-off-by: jpmondet <jp@mondet.org>
This commit is contained in:
parent
890ca17a08
commit
1c64265f86
@ -4,7 +4,7 @@ Priority: optional
|
|||||||
Maintainer: Nobody <nobody@frrouting.org>
|
Maintainer: Nobody <nobody@frrouting.org>
|
||||||
Uploaders: Nobody <nobody@frrouting.org>
|
Uploaders: Nobody <nobody@frrouting.org>
|
||||||
XSBC-Original-Maintainer: <maintainers@frrouting.org>
|
XSBC-Original-Maintainer: <maintainers@frrouting.org>
|
||||||
Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, libpython-dev
|
Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddress, libpython-dev
|
||||||
Standards-Version: 3.9.6
|
Standards-Version: 3.9.6
|
||||||
Homepage: http://www.frrouting.org/
|
Homepage: http://www.frrouting.org/
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (documentation)
|
|||||||
Package: frr-pythontools
|
Package: frr-pythontools
|
||||||
Section: net
|
Section: net
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, frr (= ${binary:Version}), python (>= 2.7), python-ipaddr
|
Depends: ${misc:Depends}, frr (= ${binary:Version}), python (>= 2.7), python-ipaddress
|
||||||
Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (Python Tools)
|
Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (Python Tools)
|
||||||
This package includes info files for frr, a free software which manages
|
This package includes info files for frr, a free software which manages
|
||||||
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
|
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
|
||||||
|
@ -4,7 +4,7 @@ Priority: optional
|
|||||||
Maintainer: Nobody <nobody@frrouting.org>
|
Maintainer: Nobody <nobody@frrouting.org>
|
||||||
Uploaders: Nobody <nobody@frrouting.org>
|
Uploaders: Nobody <nobody@frrouting.org>
|
||||||
XSBC-Original-Maintainer: <maintainers@frrouting.org>
|
XSBC-Original-Maintainer: <maintainers@frrouting.org>
|
||||||
Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, python-sphinx, libpython-dev
|
Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddress, python-sphinx, libpython-dev
|
||||||
Standards-Version: 3.9.6
|
Standards-Version: 3.9.6
|
||||||
Homepage: http://www.frrouting.org/
|
Homepage: http://www.frrouting.org/
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (documentation)
|
|||||||
Package: frr-pythontools
|
Package: frr-pythontools
|
||||||
Section: net
|
Section: net
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, frr (= ${binary:Version}), python (>= 2.7), python-ipaddr
|
Depends: ${misc:Depends}, frr (= ${binary:Version}), python (>= 2.7), python-ipaddress
|
||||||
Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (Python Tools)
|
Description: BGP/OSPF/RIP/RIPng/ISIS/PIM/LDP routing daemon (Python Tools)
|
||||||
This package includes info files for frr, a free software which manages
|
This package includes info files for frr, a free software which manages
|
||||||
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
|
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
|
||||||
|
@ -16,8 +16,8 @@ Add packages:
|
|||||||
apt-get install \
|
apt-get install \
|
||||||
git autoconf automake libtool make gawk libreadline-dev texinfo dejagnu \
|
git autoconf automake libtool make gawk libreadline-dev texinfo dejagnu \
|
||||||
pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest \
|
pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest \
|
||||||
libc-ares-dev python3-dev libsystemd-dev python-ipaddr python3-sphinx \
|
libc-ares-dev python3-dev libsystemd-dev python-ipaddress \
|
||||||
install-info
|
python3-sphinx install-info
|
||||||
|
|
||||||
Get FRR, compile it and install it (from Git)
|
Get FRR, compile it and install it (from Git)
|
||||||
---------------------------------------------
|
---------------------------------------------
|
||||||
|
@ -12,8 +12,8 @@ Required packages
|
|||||||
sudo apt-get install \
|
sudo apt-get install \
|
||||||
git autoconf automake libtool make gawk libreadline-dev texinfo \
|
git autoconf automake libtool make gawk libreadline-dev texinfo \
|
||||||
pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest \
|
pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest \
|
||||||
libc-ares-dev python3-dev libsystemd-dev python-ipaddr python3-sphinx \
|
libc-ares-dev python3-dev libsystemd-dev python-ipaddress \
|
||||||
install-info
|
python3-sphinx install-info
|
||||||
|
|
||||||
Optional packages
|
Optional packages
|
||||||
^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^
|
||||||
|
@ -216,7 +216,7 @@ Contributed/3rd party tools which may be of use with frr.
|
|||||||
%package pythontools
|
%package pythontools
|
||||||
Summary: python tools for frr
|
Summary: python tools for frr
|
||||||
BuildRequires: python
|
BuildRequires: python
|
||||||
Requires: python-ipaddr
|
Requires: python-ipaddress
|
||||||
Group: System Environment/Daemons
|
Group: System Environment/Daemons
|
||||||
|
|
||||||
%description pythontools
|
%description pythontools
|
||||||
|
@ -28,6 +28,7 @@ This program
|
|||||||
text file
|
text file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function, unicode_literals
|
||||||
import argparse
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
@ -38,9 +39,22 @@ import string
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from ipaddr import IPv6Address, IPNetwork
|
try:
|
||||||
|
from ipaddress import IPv6Address, ip_network
|
||||||
|
except ImportError:
|
||||||
|
from ipaddr import IPv6Address, IPNetwork
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
|
try:
|
||||||
|
dict.iteritems
|
||||||
|
except AttributeError:
|
||||||
|
# Python 3
|
||||||
|
def iteritems(d):
|
||||||
|
return iter(d.items())
|
||||||
|
else:
|
||||||
|
# Python 2
|
||||||
|
def iteritems(d):
|
||||||
|
return d.iteritems()
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -116,7 +130,7 @@ class Config(object):
|
|||||||
ve.output = e.output
|
ve.output = e.output
|
||||||
raise ve
|
raise ve
|
||||||
|
|
||||||
for line in file_output.split('\n'):
|
for line in file_output.decode('utf-8').split('\n'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
||||||
# Compress duplicate whitespaces
|
# Compress duplicate whitespaces
|
||||||
@ -147,7 +161,7 @@ class Config(object):
|
|||||||
ve.output = e.output
|
ve.output = e.output
|
||||||
raise ve
|
raise ve
|
||||||
|
|
||||||
for line in config_text.split('\n'):
|
for line in config_text.decode('utf-8').split('\n'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
||||||
if (line == 'Building configuration...' or
|
if (line == 'Building configuration...' or
|
||||||
@ -171,8 +185,8 @@ class Config(object):
|
|||||||
Return the parsed context as strings for display, log etc.
|
Return the parsed context as strings for display, log etc.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for (_, ctx) in sorted(self.contexts.iteritems()):
|
for (_, ctx) in sorted(iteritems(self.contexts)):
|
||||||
print str(ctx) + '\n'
|
print(str(ctx) + '\n')
|
||||||
|
|
||||||
def save_contexts(self, key, lines):
|
def save_contexts(self, key, lines):
|
||||||
"""
|
"""
|
||||||
@ -195,11 +209,18 @@ class Config(object):
|
|||||||
addr = re_key_rt.group(2)
|
addr = re_key_rt.group(2)
|
||||||
if '/' in addr:
|
if '/' in addr:
|
||||||
try:
|
try:
|
||||||
newaddr = IPNetwork(addr)
|
if 'ipaddress' not in sys.modules:
|
||||||
key[0] = '%s route %s/%s%s' % (re_key_rt.group(1),
|
newaddr = IPNetwork(addr)
|
||||||
newaddr.network,
|
key[0] = '%s route %s/%s%s' % (re_key_rt.group(1),
|
||||||
newaddr.prefixlen,
|
newaddr.network,
|
||||||
re_key_rt.group(3))
|
newaddr.prefixlen,
|
||||||
|
re_key_rt.group(3))
|
||||||
|
else:
|
||||||
|
newaddr = ip_network(addr, strict=False)
|
||||||
|
key[0] = '%s route %s/%s%s' % (re_key_rt.group(1),
|
||||||
|
str(newaddr.network_address),
|
||||||
|
newaddr.prefixlen,
|
||||||
|
re_key_rt.group(3))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -211,8 +232,13 @@ class Config(object):
|
|||||||
addr = re_key_rt.group(4)
|
addr = re_key_rt.group(4)
|
||||||
if '/' in addr:
|
if '/' in addr:
|
||||||
try:
|
try:
|
||||||
newaddr = '%s/%s' % (IPNetwork(addr).network,
|
if 'ipaddress' not in sys.modules:
|
||||||
IPNetwork(addr).prefixlen)
|
newaddr = '%s/%s' % (IPNetwork(addr).network,
|
||||||
|
IPNetwork(addr).prefixlen)
|
||||||
|
else:
|
||||||
|
network_addr = ip_network(addr, strict=False)
|
||||||
|
newaddr = '%s/%s' % (str(network_addr.network_address),
|
||||||
|
network_addr.prefixlen)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
newaddr = addr
|
newaddr = addr
|
||||||
else:
|
else:
|
||||||
@ -253,10 +279,16 @@ class Config(object):
|
|||||||
addr = addr + '/8'
|
addr = addr + '/8'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
newaddr = IPNetwork(addr)
|
if 'ipaddress' not in sys.modules:
|
||||||
line = 'network %s/%s %s' % (newaddr.network,
|
newaddr = IPNetwork(addr)
|
||||||
newaddr.prefixlen,
|
line = 'network %s/%s %s' % (newaddr.network,
|
||||||
re_net.group(2))
|
newaddr.prefixlen,
|
||||||
|
re_net.group(2))
|
||||||
|
else:
|
||||||
|
network_addr = ip_network(addr, strict=False)
|
||||||
|
line = 'network %s/%s %s' % (str(network_addr.network_address),
|
||||||
|
network_addr.prefixlen,
|
||||||
|
re_net.group(2))
|
||||||
newlines.append(line)
|
newlines.append(line)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Really this should be an error. Whats a network
|
# Really this should be an error. Whats a network
|
||||||
@ -598,8 +630,12 @@ def get_normalized_ipv6_line(line):
|
|||||||
norm_word = None
|
norm_word = None
|
||||||
if "/" in word:
|
if "/" in word:
|
||||||
try:
|
try:
|
||||||
v6word = IPNetwork(word)
|
if 'ipaddress' not in sys.modules:
|
||||||
norm_word = '%s/%s' % (v6word.network, v6word.prefixlen)
|
v6word = IPNetwork(word)
|
||||||
|
norm_word = '%s/%s' % (v6word.network, v6word.prefixlen)
|
||||||
|
else:
|
||||||
|
v6word = ip_network(word, strict=False)
|
||||||
|
norm_word = '%s/%s' % (str(v6word.network_address), v6word.prefixlen)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if not norm_word:
|
if not norm_word:
|
||||||
@ -926,7 +962,7 @@ def compare_context_objects(newconf, running):
|
|||||||
|
|
||||||
# Find contexts that are in newconf but not in running
|
# Find contexts that are in newconf but not in running
|
||||||
# Find contexts that are in running but not in newconf
|
# Find contexts that are in running but not in newconf
|
||||||
for (running_ctx_keys, running_ctx) in running.contexts.iteritems():
|
for (running_ctx_keys, running_ctx) in iteritems(running.contexts):
|
||||||
|
|
||||||
if running_ctx_keys not in newconf.contexts:
|
if running_ctx_keys not in newconf.contexts:
|
||||||
|
|
||||||
@ -977,7 +1013,7 @@ def compare_context_objects(newconf, running):
|
|||||||
|
|
||||||
# Find the lines within each context to add
|
# Find the lines within each context to add
|
||||||
# Find the lines within each context to del
|
# Find the lines within each context to del
|
||||||
for (newconf_ctx_keys, newconf_ctx) in newconf.contexts.iteritems():
|
for (newconf_ctx_keys, newconf_ctx) in iteritems(newconf.contexts):
|
||||||
|
|
||||||
if newconf_ctx_keys in running.contexts:
|
if newconf_ctx_keys in running.contexts:
|
||||||
running_ctx = running.contexts[newconf_ctx_keys]
|
running_ctx = running.contexts[newconf_ctx_keys]
|
||||||
@ -990,7 +1026,7 @@ def compare_context_objects(newconf, running):
|
|||||||
if line not in newconf_ctx.dlines:
|
if line not in newconf_ctx.dlines:
|
||||||
lines_to_del.append((newconf_ctx_keys, line))
|
lines_to_del.append((newconf_ctx_keys, line))
|
||||||
|
|
||||||
for (newconf_ctx_keys, newconf_ctx) in newconf.contexts.iteritems():
|
for (newconf_ctx_keys, newconf_ctx) in iteritems(newconf.contexts):
|
||||||
|
|
||||||
if newconf_ctx_keys not in running.contexts:
|
if newconf_ctx_keys not in running.contexts:
|
||||||
lines_to_add.append((newconf_ctx_keys, None))
|
lines_to_add.append((newconf_ctx_keys, None))
|
||||||
@ -1016,14 +1052,14 @@ def vtysh_config_available():
|
|||||||
cmd = ['/usr/bin/vtysh', '-c', 'conf t']
|
cmd = ['/usr/bin/vtysh', '-c', 'conf t']
|
||||||
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
|
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
|
||||||
|
|
||||||
if 'VTY configuration is locked by other VTY' in output:
|
if 'VTY configuration is locked by other VTY' in output.decode('utf-8'):
|
||||||
print output
|
print(output)
|
||||||
log.error("'%s' returned\n%s\n" % (' '.join(cmd), output))
|
log.error("'%s' returned\n%s\n" % (' '.join(cmd), output))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
msg = "vtysh could not connect with any frr daemons"
|
msg = "vtysh could not connect with any frr daemons"
|
||||||
print msg
|
print(msg)
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1070,13 +1106,13 @@ if __name__ == '__main__':
|
|||||||
# Verify the new config file is valid
|
# Verify the new config file is valid
|
||||||
if not os.path.isfile(args.filename):
|
if not os.path.isfile(args.filename):
|
||||||
msg = "Filename %s does not exist" % args.filename
|
msg = "Filename %s does not exist" % args.filename
|
||||||
print msg
|
print(msg)
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not os.path.getsize(args.filename):
|
if not os.path.getsize(args.filename):
|
||||||
msg = "Filename %s is an empty file" % args.filename
|
msg = "Filename %s is an empty file" % args.filename
|
||||||
print msg
|
print(msg)
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -1095,7 +1131,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if not service_integrated_vtysh_config:
|
if not service_integrated_vtysh_config:
|
||||||
msg = "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'"
|
msg = "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'"
|
||||||
print msg
|
print(msg)
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -1123,8 +1159,8 @@ if __name__ == '__main__':
|
|||||||
lines_to_configure = []
|
lines_to_configure = []
|
||||||
|
|
||||||
if lines_to_del:
|
if lines_to_del:
|
||||||
print "\nLines To Delete"
|
print("\nLines To Delete")
|
||||||
print "==============="
|
print("===============")
|
||||||
|
|
||||||
for (ctx_keys, line) in lines_to_del:
|
for (ctx_keys, line) in lines_to_del:
|
||||||
|
|
||||||
@ -1133,11 +1169,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
cmd = line_for_vtysh_file(ctx_keys, line, True)
|
cmd = line_for_vtysh_file(ctx_keys, line, True)
|
||||||
lines_to_configure.append(cmd)
|
lines_to_configure.append(cmd)
|
||||||
print cmd
|
print(cmd)
|
||||||
|
|
||||||
if lines_to_add:
|
if lines_to_add:
|
||||||
print "\nLines To Add"
|
print("\nLines To Add")
|
||||||
print "============"
|
print("============")
|
||||||
|
|
||||||
for (ctx_keys, line) in lines_to_add:
|
for (ctx_keys, line) in lines_to_add:
|
||||||
|
|
||||||
@ -1146,7 +1182,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
cmd = line_for_vtysh_file(ctx_keys, line, False)
|
cmd = line_for_vtysh_file(ctx_keys, line, False)
|
||||||
lines_to_configure.append(cmd)
|
lines_to_configure.append(cmd)
|
||||||
print cmd
|
print(cmd)
|
||||||
|
|
||||||
elif args.reload:
|
elif args.reload:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user