Using CherryPy as backend instead of Tornado

This commit is contained in:
Alexandre Dulaunoy 2014-01-02 14:59:37 +01:00
parent a7e3cdc77c
commit 039c4bd45d

View file

@ -15,9 +15,7 @@
# Copyright (c) 2013 Alexandre Dulaunoy - a@foo.be # Copyright (c) 2013 Alexandre Dulaunoy - a@foo.be
from datetime import date from datetime import date
import tornado.escape import cherrypy
import tornado.ioloop
import tornado.web
import iptools import iptools
import redis import redis
@ -105,36 +103,35 @@ def JsonQOF(rrfound = None, RemoveDuplicate=True):
rrqof = rrqof + json.dumps(rr) + "\n" rrqof = rrqof + json.dumps(rr) + "\n"
return rrqof return rrqof
class InfoHandler(tornado.web.RequestHandler): class Root:
def get(self): def info(self):
response = { 'version': 'git', response = { 'version': 'git','software': 'pdns-qof-server' }
'software': 'pdns-qof-server' } return json.dumps(response)
self.write(response)
class QueryHandler(tornado.web.RequestHandler): def query(self, q):
def get(self, q):
print ("query: "+q) print ("query: "+q)
o=""
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q): if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
for x in getAssociatedRecords(q): for x in getAssociatedRecords(q):
self.write(JsonQOF(getRecord(x))) o = o + JsonQOF(getRecord(x))
else: else:
self.write(JsonQOF(getRecord(t = q.strip()))) o = o + JsonQOF(getRecord(t = q.strip()))
return o
class FullQueryHandler(tornado.web.RequestHandler): def fquery(self, q):
def get(self, q):
print ("fquery: "+q) print ("fquery: "+q)
o=""
if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q): if iptools.ipv4.validate_ip(q) or iptools.ipv6.validate_ip(q):
for x in getAssociatedRecords(q): for x in getAssociatedRecords(q):
self.write(JsonQOF(getRecord(x))) o = o + JsonQOF(getRecord(x))
else: else:
for x in getAssociatedRecords(q): for x in getAssociatedRecords(q):
self.write(JsonQOF(getRecord(t = x.strip()))) o = o + JsonQOF(getRecord(t = x.strip()))
return o
application = tornado.web.Application([ info.exposed = True
(r"/query/(.*)",QueryHandler), query.exposed = True
(r"/fquery/(.*)",FullQueryHandler), fquery.exposed = True
(r"/info", InfoHandler)
])
if __name__ == "test": if __name__ == "test":
@ -147,6 +144,7 @@ if __name__ == "test":
else: else:
print (JsonQOF(getRecord(t = q))) print (JsonQOF(getRecord(t = q)))
else: else:
application.listen(8888) root = Root()
tornado.ioloop.IOLoop.instance().start() cherrypy.config.update({ 'server.socket_port': 8887, 'request.show_tracebacks': False, 'server.thread_pool': 30, 'server.socket_host': '::'})
cherrypy.quickstart(root)