-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·67 lines (51 loc) · 1.83 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
import tornado.httpserver
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado_pyuv import UVLoop
IOLoop.configure(UVLoop)
from tornado.escape import json_encode
import cjson
import tornado.web
import socket
from tornado.options import options
from settings import settings
from urls import url_patterns
import urllib
class TornadoBoilerplate(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((viceIp, vicePort))
address = s.getsockname()[0]
body = cjson.encode(Status(address))
headers = {"Content-Type": "application/json"}
print body
request = tornado.httpclient.HTTPRequest(url='%s/frontend_test.php/role_status' % viceServer, method='POST', body=body, headers=headers)
client = tornado.httpclient.AsyncHTTPClient()
client.fetch(request, callback=self.web_handle_request)
def web_handle_request(self, response):
if response.error:
print "Error:", response.error
else:
print response.body
viceIp = settings['server']
vicePort = settings['port']
vicePath = settings['path']
viceServer = 'http://' + viceIp + ':' + str(vicePort) + '/' + vicePath
def Status(ip):
grabberstatus = {}
grabberstatus['uptime'] = 1
grabberstatus['role_type'] = "grab_digital"
grabberstatus['port'] = "8668"
grabberstatus['ip'] = ip
grabberstatus['version'] = settings['version']
return grabberstatus
def main():
app = TornadoBoilerplate()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
loop = tornado.ioloop.IOLoop.instance()
loop.start()
if __name__ == "__main__":
main()