1
0
Fork 0
mirror of https://github.com/sileht/bird-lg.git synced 2024-11-21 22:44:43 +01:00

Add resolv timeout, store asn in memcache

This commit is contained in:
Mehdi Abaakouk 2014-04-20 16:58:25 +02:00 committed by root
parent af2c305049
commit 9822e42e25
2 changed files with 14 additions and 2 deletions

10
lg.py
View file

@ -20,6 +20,7 @@
#
###
import memcache
import subprocess
import logging
from logging.handlers import TimedRotatingFileHandler
@ -45,6 +46,8 @@ file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="m
file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
app.logger.addHandler(file_handler)
memcache_server = app.config.get("MEMCACHE_SERVER", "127.0.0.1:11211")
mc = memcache.Client([memcache_server])
def get_asn_from_as(n):
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
@ -370,7 +373,12 @@ def get_as_name(_as):
if not _as.isdigit():
return _as.strip()
name = get_asn_from_as(_as)[-1].replace(" ","\r",1)
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)
if name:
mc.set(str("lg_%s" % _as), str(name), 3600)
return "AS%s | %s" % (_as, name)

View file

@ -24,8 +24,12 @@ import socket
import pickle
import xml.parsers.expat
resolv = resolver.Resolver()
resolv.timeout = 0.5
resolv.lifetime = 1
def resolve(n, q):
return str(resolver.query(n,q)[0])
return str(resolv.query(n,q)[0])
def mask_is_valid(n):
if not n: