Maintainer: Nobody <nobody@frrouting.org>
Uploaders: Nobody <nobody@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
Homepage: http://www.frrouting.org/
Package: frr-pythontools
Section: net
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)
This package includes info files for frr, a free software which manages
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
Maintainer: Nobody <nobody@frrouting.org>
Uploaders: Nobody <nobody@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
Homepage: http://www.frrouting.org/
Package: frr-pythontools
Section: net
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)
This package includes info files for frr, a free software which manages
TCP/IP based routing protocols. It supports BGP4, BGP4+, OSPFv2, OSPFv3,
text file
"""
+from __future__ import print_function, unicode_literals
import argparse
import copy
import logging
import subprocess
import sys
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
+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__)
ve.output = e.output
raise ve
- for line in file_output.split('\n'):
+ for line in file_output.decode('utf-8').split('\n'):
line = line.strip()
# Compress duplicate whitespaces
ve.output = e.output
raise ve
- for line in config_text.split('\n'):
+ for line in config_text.decode('utf-8').split('\n'):
line = line.strip()
if (line == 'Building configuration...' or
Return the parsed context as strings for display, log etc.
"""
- for (_, ctx) in sorted(self.contexts.iteritems()):
- print str(ctx) + '\n'
+ for (_, ctx) in sorted(iteritems(self.contexts)):
+ print(str(ctx) + '\n')
def save_contexts(self, key, lines):
"""
addr = re_key_rt.group(2)
if '/' in addr:
try:
- newaddr = IPNetwork(addr)
- key[0] = '%s route %s/%s%s' % (re_key_rt.group(1),
- newaddr.network,
- newaddr.prefixlen,
- re_key_rt.group(3))
+ if 'ipaddress' not in sys.modules:
+ newaddr = IPNetwork(addr)
+ key[0] = '%s route %s/%s%s' % (re_key_rt.group(1),
+ newaddr.network,
+ 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:
pass
addr = re_key_rt.group(4)
if '/' in addr:
try:
- newaddr = '%s/%s' % (IPNetwork(addr).network,
- IPNetwork(addr).prefixlen)
+ if 'ipaddress' not in sys.modules:
+ 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:
newaddr = addr
else:
addr = addr + '/8'
try:
- newaddr = IPNetwork(addr)
- line = 'network %s/%s %s' % (newaddr.network,
- newaddr.prefixlen,
- re_net.group(2))
+ if 'ipaddress' not in sys.modules:
+ newaddr = IPNetwork(addr)
+ line = 'network %s/%s %s' % (newaddr.network,
+ 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)
except ValueError:
# Really this should be an error. Whats a network
norm_word = None
if "/" in word:
try:
- v6word = IPNetwork(word)
- norm_word = '%s/%s' % (v6word.network, v6word.prefixlen)
+ if 'ipaddress' not in sys.modules:
+ 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:
pass
if not norm_word:
# Find contexts that are in newconf but not in running
# 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:
# Find the lines within each context to add
# 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:
running_ctx = running.contexts[newconf_ctx_keys]
if line not in newconf_ctx.dlines:
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:
lines_to_add.append((newconf_ctx_keys, None))
cmd = ['/usr/bin/vtysh', '-c', 'conf t']
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
- if 'VTY configuration is locked by other VTY' in output:
- print output
+ if 'VTY configuration is locked by other VTY' in output.decode('utf-8'):
+ print(output)
log.error("'%s' returned\n%s\n" % (' '.join(cmd), output))
return False
except subprocess.CalledProcessError as e:
msg = "vtysh could not connect with any frr daemons"
- print msg
+ print(msg)
log.error(msg)
return False
# Verify the new config file is valid
if not os.path.isfile(args.filename):
msg = "Filename %s does not exist" % args.filename
- print msg
+ print(msg)
log.error(msg)
sys.exit(1)
if not os.path.getsize(args.filename):
msg = "Filename %s is an empty file" % args.filename
- print msg
+ print(msg)
log.error(msg)
sys.exit(1)
if not service_integrated_vtysh_config:
msg = "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'"
- print msg
+ print(msg)
log.error(msg)
sys.exit(1)
lines_to_configure = []
if lines_to_del:
- print "\nLines To Delete"
- print "==============="
+ print("\nLines To Delete")
+ print("===============")
for (ctx_keys, line) in lines_to_del:
cmd = line_for_vtysh_file(ctx_keys, line, True)
lines_to_configure.append(cmd)
- print cmd
+ print(cmd)
if lines_to_add:
- print "\nLines To Add"
- print "============"
+ print("\nLines To Add")
+ print("============")
for (ctx_keys, line) in lines_to_add:
cmd = line_for_vtysh_file(ctx_keys, line, False)
lines_to_configure.append(cmd)
- print cmd
+ print(cmd)
elif args.reload: