Convert application into python module
57
.gitignore
vendored
|
@ -1,2 +1,55 @@
|
||||||
*.pyc
|
*.py[cod]
|
||||||
*.pyo
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
*.egg*
|
||||||
|
*.egg-info
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
eggs
|
||||||
|
parts
|
||||||
|
bin
|
||||||
|
var
|
||||||
|
sdist
|
||||||
|
develop-eggs
|
||||||
|
.installed.cfg
|
||||||
|
lib
|
||||||
|
lib64
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
cover/
|
||||||
|
.coverage*
|
||||||
|
!.coveragerc
|
||||||
|
.tox
|
||||||
|
nosetests.xml
|
||||||
|
.testrepository
|
||||||
|
.venv
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
|
||||||
|
# Mr Developer
|
||||||
|
.mr.developer.cfg
|
||||||
|
.project
|
||||||
|
.pydevproject
|
||||||
|
|
||||||
|
# Complexity
|
||||||
|
output/*.html
|
||||||
|
output/*/index.html
|
||||||
|
|
||||||
|
# Sphinx
|
||||||
|
doc/build
|
||||||
|
|
||||||
|
# pbr generates these
|
||||||
|
AUTHORS
|
||||||
|
ChangeLog
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
*~
|
||||||
|
.*.swp
|
||||||
|
.*sw?
|
||||||
|
|
4
CONTRIBUTING.rst
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Bugs should be filed on Github: https://github.com/sileht/bird-lg/issues
|
||||||
|
|
||||||
|
Contribution can be via Github pull requests: https://github.com/sileht/bird-lg/pulls
|
||||||
|
|
|
@ -4,7 +4,7 @@ BIRD-LG
|
||||||
This is a looking glass for the Internet Routing Daemon "Bird".
|
This is a looking glass for the Internet Routing Daemon "Bird".
|
||||||
|
|
||||||
|
|
||||||
Software is split in two parts:
|
Software is split in two parts::
|
||||||
|
|
||||||
- lgproxy.py:
|
- lgproxy.py:
|
||||||
|
|
||||||
|
@ -23,11 +23,11 @@ Software is split in two parts:
|
||||||
***************
|
***************
|
||||||
+--> * lgproxy.py *
|
+--> * lgproxy.py *
|
||||||
| ***************
|
| ***************
|
||||||
|
|
|
|
||||||
******** ******************* | ***************
|
******** ******************* | ***************
|
||||||
* USER * ----> * webserver/lg.py *--+--> * lgproxy.py *
|
* USER * ----> * webserver/lg.py *--+--> * lgproxy.py *
|
||||||
******** ******************* | ***************
|
******** ******************* | ***************
|
||||||
|
|
|
|
||||||
| ***************
|
| ***************
|
||||||
+--> * lgproxy.py *
|
+--> * lgproxy.py *
|
||||||
***************
|
***************
|
||||||
|
@ -36,9 +36,9 @@ Software is split in two parts:
|
||||||
|
|
||||||
bird-lg depends on :
|
bird-lg depends on :
|
||||||
|
|
||||||
- python-flask >= 0.8
|
* python-flask >= 0.9
|
||||||
- python-dnspython
|
* python-dnspython
|
||||||
- python-pydot
|
* python-pydot
|
||||||
|
|
||||||
Each services can be embedded in any webserver by following regular python-flask configuration.
|
Each services can be embedded in any webserver by following regular python-flask configuration.
|
||||||
|
|
0
bird_lg/__init__.py
Normal file
|
@ -435,11 +435,11 @@ def show_bgpmap():
|
||||||
e = edges[edge_tuple]
|
e = edges[edge_tuple]
|
||||||
|
|
||||||
label_without_star = kwargs["label"].replace("*", "")
|
label_without_star = kwargs["label"].replace("*", "")
|
||||||
labels = e.get_label().split("\r")
|
labels = e.get_label().split("\r")
|
||||||
if "%s*" % label_without_star not in labels:
|
if "%s*" % label_without_star not in labels:
|
||||||
labels = [ kwargs["label"] ] + [ l for l in labels if not l.startswith(label_without_star) ]
|
labels = [ kwargs["label"] ] + [ l for l in labels if not l.startswith(label_without_star) ]
|
||||||
labels = sorted(labels, cmp=lambda x,y: x.endswith("*") and -1 or 1)
|
labels = sorted(labels, cmp=lambda x,y: x.endswith("*") and -1 or 1)
|
||||||
|
|
||||||
label = escape("\r".join(labels))
|
label = escape("\r".join(labels))
|
||||||
e.set_label(label)
|
e.set_label(label)
|
||||||
return edges[edge_tuple]
|
return edges[edge_tuple]
|
||||||
|
@ -453,7 +453,7 @@ def show_bgpmap():
|
||||||
edge = add_edge(as_number, nodes[host])
|
edge = add_edge(as_number, nodes[host])
|
||||||
edge.set_color("red")
|
edge.set_color("red")
|
||||||
edge.set_style("bold")
|
edge.set_style("bold")
|
||||||
|
|
||||||
#colors = [ "#009e23", "#1a6ec1" , "#d05701", "#6f879f", "#939a0e", "#0e9a93", "#9a0e85", "#56d8e1" ]
|
#colors = [ "#009e23", "#1a6ec1" , "#d05701", "#6f879f", "#939a0e", "#0e9a93", "#9a0e85", "#56d8e1" ]
|
||||||
previous_as = None
|
previous_as = None
|
||||||
hosts = data.keys()
|
hosts = data.keys()
|
||||||
|
@ -473,14 +473,14 @@ def show_bgpmap():
|
||||||
if not hop:
|
if not hop:
|
||||||
hop = True
|
hop = True
|
||||||
if _as not in hosts:
|
if _as not in hosts:
|
||||||
hop_label = _as
|
hop_label = _as
|
||||||
if first:
|
if first:
|
||||||
hop_label = hop_label + "*"
|
hop_label = hop_label + "*"
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
hop_label = ""
|
hop_label = ""
|
||||||
|
|
||||||
|
|
||||||
add_node(_as, fillcolor=(first and "#F5A9A9" or "white"))
|
add_node(_as, fillcolor=(first and "#F5A9A9" or "white"))
|
||||||
if hop_label:
|
if hop_label:
|
||||||
edge = add_edge(nodes[previous_as], nodes[_as], label=hop_label, fontsize="7")
|
edge = add_edge(nodes[previous_as], nodes[_as], label=hop_label, fontsize="7")
|
||||||
|
@ -547,7 +547,7 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text):
|
||||||
# ugly hack for good printing
|
# ugly hack for good printing
|
||||||
path = [ peer_protocol_name ]
|
path = [ peer_protocol_name ]
|
||||||
# path = ["%s\r%s" % (peer_protocol_name, get_as_name(get_as_number_from_protocol_name(host, proto, peer_protocol_name)))]
|
# path = ["%s\r%s" % (peer_protocol_name, get_as_name(get_as_number_from_protocol_name(host, proto, peer_protocol_name)))]
|
||||||
|
|
||||||
expr2 = re.search(r'(.*)unreachable\s+\[(\w+)\s+', line)
|
expr2 = re.search(r'(.*)unreachable\s+\[(\w+)\s+', line)
|
||||||
if expr2:
|
if expr2:
|
||||||
if path:
|
if path:
|
||||||
|
@ -560,7 +560,7 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text):
|
||||||
|
|
||||||
if line.startswith("BGP.as_path:"):
|
if line.startswith("BGP.as_path:"):
|
||||||
path.extend(line.replace("BGP.as_path:", "").strip().split(" "))
|
path.extend(line.replace("BGP.as_path:", "").strip().split(" "))
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
path.append(net_dest)
|
path.append(net_dest)
|
||||||
paths.append(path)
|
paths.append(path)
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
74
doc/source/conf.py
Executable file
|
@ -0,0 +1,74 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 3 as
|
||||||
|
# published by the Free Software Foundation
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath('../..'))
|
||||||
|
# -- General configuration ----------------------------------------------------
|
||||||
|
|
||||||
|
# Add any Sphinx extension module names here, as strings. They can be
|
||||||
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||||
|
extensions = [
|
||||||
|
'sphinx.ext.autodoc',
|
||||||
|
]
|
||||||
|
|
||||||
|
# autodoc generation is a bit aggressive and a nuisance when doing heavy
|
||||||
|
# text edit cycles.
|
||||||
|
# execute "export SPHINX_DEBUG=1" in your terminal to disable
|
||||||
|
|
||||||
|
# The suffix of source filenames.
|
||||||
|
source_suffix = '.rst'
|
||||||
|
|
||||||
|
# The master toctree document.
|
||||||
|
master_doc = 'index'
|
||||||
|
|
||||||
|
# General information about the project.
|
||||||
|
project = u'bird-lg'
|
||||||
|
copyright = u'2016, Mehdi Abaakouk'
|
||||||
|
|
||||||
|
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||||
|
add_function_parentheses = True
|
||||||
|
|
||||||
|
# If true, the current module name will be prepended to all description
|
||||||
|
# unit titles (such as .. function::).
|
||||||
|
add_module_names = True
|
||||||
|
|
||||||
|
# The name of the Pygments (syntax highlighting) style to use.
|
||||||
|
pygments_style = 'sphinx'
|
||||||
|
|
||||||
|
# -- Options for HTML output --------------------------------------------------
|
||||||
|
|
||||||
|
# The theme to use for HTML and HTML Help pages. Major themes that come with
|
||||||
|
# Sphinx are currently 'default' and 'sphinxdoc'.
|
||||||
|
# html_theme_path = ["."]
|
||||||
|
# html_theme = '_theme'
|
||||||
|
# html_static_path = ['static']
|
||||||
|
|
||||||
|
# Output file base name for HTML help builder.
|
||||||
|
htmlhelp_basename = '%sdoc' % project
|
||||||
|
|
||||||
|
# Grouping the document tree into LaTeX files. List of tuples
|
||||||
|
# (source start file, target name, title, author, documentclass
|
||||||
|
# [howto/manual]).
|
||||||
|
latex_documents = [
|
||||||
|
('index',
|
||||||
|
'%s.tex' % project,
|
||||||
|
u'%s Documentation' % project,
|
||||||
|
u'Mehdi Abaakouk', 'manual'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Example configuration for intersphinx: refer to the Python standard library.
|
||||||
|
# intersphinx_mapping = {'http://docs.python.org/': None}
|
4
doc/source/contributing.rst
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
============
|
||||||
|
Contributing
|
||||||
|
============
|
||||||
|
.. include:: ../../CONTRIBUTING.rst
|
24
doc/source/index.rst
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
.. cotyledon documentation master file, created by
|
||||||
|
sphinx-quickstart on Tue Jul 9 22:26:36 2013.
|
||||||
|
You can adapt this file completely to your liking, but it should at least
|
||||||
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
|
Welcome to cotyledon's documentation!
|
||||||
|
========================================================
|
||||||
|
|
||||||
|
Contents:
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
readme
|
||||||
|
installation
|
||||||
|
contributing
|
||||||
|
|
||||||
|
Indices and tables
|
||||||
|
==================
|
||||||
|
|
||||||
|
* :ref:`genindex`
|
||||||
|
* :ref:`modindex`
|
||||||
|
* :ref:`search`
|
||||||
|
|
12
doc/source/installation.rst
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
============
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
At the command line::
|
||||||
|
|
||||||
|
$ pip install bird-lg
|
||||||
|
|
||||||
|
Or, if you have virtualenvwrapper installed::
|
||||||
|
|
||||||
|
$ mkvirtualenv bird-lg
|
||||||
|
$ pip install bird-lg
|
1
doc/source/readme.rst
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.. include:: ../../README.rst
|
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pbr
|
||||||
|
flask>=0.8
|
||||||
|
dnspython
|
||||||
|
pydot
|
59
setup.cfg
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
[metadata]
|
||||||
|
name = bird-lg
|
||||||
|
url = https://github.com/sileht/bird-lg
|
||||||
|
summary = bird looking glass
|
||||||
|
description-file =
|
||||||
|
README.rst
|
||||||
|
author = Mehdi Abaakouk
|
||||||
|
author-email = sileht@sileht.net
|
||||||
|
home-page = https://github.com/sileht/bird-lg
|
||||||
|
classifier =
|
||||||
|
Intended Audience :: Information Technology
|
||||||
|
Intended Audience :: System Administrators
|
||||||
|
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
||||||
|
Operating System :: POSIX :: Linux
|
||||||
|
Programming Language :: Python
|
||||||
|
Programming Language :: Python :: 2
|
||||||
|
Programming Language :: Python :: 2.7
|
||||||
|
Programming Language :: Python :: 3.5
|
||||||
|
Topic :: System :: Monitoring
|
||||||
|
|
||||||
|
[extras]
|
||||||
|
test =
|
||||||
|
gabbi>=1.21.0
|
||||||
|
wsgi_intercept>=1.4.1
|
||||||
|
hacking<0.11,>=0.10.0
|
||||||
|
coverage>=3.6
|
||||||
|
fixtures
|
||||||
|
mock
|
||||||
|
oslotest
|
||||||
|
python-subunit>=0.0.18
|
||||||
|
os-testr
|
||||||
|
testrepository
|
||||||
|
testtools>=0.9.38
|
||||||
|
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
|
||||||
|
oslosphinx>=2.5.0 # Apache-2.0
|
||||||
|
|
||||||
|
[global]
|
||||||
|
setup-hooks =
|
||||||
|
pbr.hooks.setup_hook
|
||||||
|
|
||||||
|
[files]
|
||||||
|
packages =
|
||||||
|
bird_lg
|
||||||
|
data_files =
|
||||||
|
etc/bird-lg = etc/bird-lg/*
|
||||||
|
|
||||||
|
[entry_points]
|
||||||
|
wsgi_scripts =
|
||||||
|
bird-lg-api = bird_lg.lg:app
|
||||||
|
bird-lg-proxy-api = bird_lg.lg_proxy:app
|
||||||
|
|
||||||
|
|
||||||
|
[build_sphinx]
|
||||||
|
all_files = 1
|
||||||
|
build-dir = doc/build
|
||||||
|
source-dir = doc/source
|
||||||
|
|
||||||
|
[wheel]
|
||||||
|
universal = 1
|
17
setup.py
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 3 as
|
||||||
|
# published by the Free Software Foundation
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(setup_requires=['pbr'], pbr=True)
|
16
tools/pretty_tox.sh
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
TESTRARGS=$1
|
||||||
|
|
||||||
|
# --until-failure is not compatible with --subunit see:
|
||||||
|
#
|
||||||
|
# https://bugs.launchpad.net/testrepository/+bug/1411804
|
||||||
|
#
|
||||||
|
# this work around exists until that is addressed
|
||||||
|
if [[ "$TESTARGS" =~ "until-failure" ]]; then
|
||||||
|
python setup.py testr --slowest --testr-args="$TESTRARGS"
|
||||||
|
else
|
||||||
|
python setup.py testr --slowest --testr-args="--subunit $TESTRARGS" | subunit-trace -f
|
||||||
|
fi
|
34
tox.ini
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[tox]
|
||||||
|
minversion = 2.0
|
||||||
|
skipsdist = True
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
usedevelop = True
|
||||||
|
install_command = pip install -U {opts} {packages}
|
||||||
|
setenv =
|
||||||
|
VIRTUAL_ENV={envdir}
|
||||||
|
deps = .[test]
|
||||||
|
commands = {toxinidir}/tools/pretty_tox.sh
|
||||||
|
|
||||||
|
[testenv:pep8]
|
||||||
|
deps =
|
||||||
|
flake8
|
||||||
|
doc8
|
||||||
|
commands =
|
||||||
|
doc8 --ignore-path doc/source/rest.rst doc/source
|
||||||
|
flake8 {posargs}
|
||||||
|
|
||||||
|
[testenv:venv]
|
||||||
|
commands = {posargs}
|
||||||
|
|
||||||
|
[testenv:cover]
|
||||||
|
commands = python setup.py test --coverage --testr-args='{posargs}'
|
||||||
|
|
||||||
|
[testenv:docs]
|
||||||
|
commands = python setup.py build_sphinx
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
show-source = True
|
||||||
|
builtins = _
|
||||||
|
ignores = H103
|
||||||
|
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|