1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-16 12:24:42 +01:00

Remove the need for memcached

From a deployment perspective, it's annoying to depend on memcached, and
it's only used to cache DNS answers for the BGPmap.

Fixes #73
This commit is contained in:
Baptiste Jonglez 2021-05-10 18:41:21 +02:00
parent 96249a36d0
commit 8f091cf27e
2 changed files with 2 additions and 15 deletions

View file

@ -38,7 +38,6 @@ bird-lg depends on :
- python-flask >= 0.8 - python-flask >= 0.8
- python-dnspython - python-dnspython
- python-pydot - python-pydot
- python-memcache
- graphviz - graphviz
- whois - whois
- traceroute - traceroute

14
lg.py
View file

@ -22,7 +22,6 @@
import base64 import base64
from datetime import datetime from datetime import datetime
import memcache
import subprocess import subprocess
import logging import logging
from logging.handlers import TimedRotatingFileHandler from logging.handlers import TimedRotatingFileHandler
@ -52,9 +51,6 @@ file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="m
file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper())) file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
app.logger.addHandler(file_handler) app.logger.addHandler(file_handler)
memcache_server = app.config.get("MEMCACHE_SERVER", "127.0.0.1:11211")
memcache_expiration = int(app.config.get("MEMCACHE_EXPIRATION", "1296000")) # 15 days by default
mc = memcache.Client([memcache_server])
def get_asn_from_as(n): def get_asn_from_as(n):
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com") asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
@ -383,10 +379,7 @@ def show_route_for_bgpmap(hosts, proto):
def get_as_name(_as): def get_as_name(_as):
"""return a string that contain the as number following by the as name """Returns a string that contain the as number following by the as name
It's the use whois database informations
# Warning, the server can be blacklisted from ripe is too many requests are done
""" """
if not _as: if not _as:
return "AS?????" return "AS?????"
@ -394,12 +387,7 @@ def get_as_name(_as):
if not _as.isdigit(): if not _as.isdigit():
return _as.strip() return _as.strip()
name = mc.get(str('lg_%s' % _as))
if not name:
app.logger.info("asn for as %s not found in memcache", _as)
name = get_asn_from_as(_as)[-1].replace(" ", "\r", 1) name = get_asn_from_as(_as)[-1].replace(" ", "\r", 1)
if name:
mc.set(str("lg_%s" % _as), str(name), memcache_expiration)
return "AS%s | %s" % (_as, name) return "AS%s | %s" % (_as, name)