-
Notifications
You must be signed in to change notification settings - Fork 3
/
sedi.py
executable file
·47 lines (37 loc) · 1.26 KB
/
sedi.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
#!/usr/bin/env python
"""
A simple service discovery proxy for Mesos-DNS, exposing a CORS-enabled HTTP API.
It is assumed to run on the same host as Mesos-DNS.
Usage:
./sedi.py
Make sure that Mesos-DNS is installed and running, see:
http://mesosphere.github.io/mesos-dns/docs/
@author: Michael Hausenblas, http://mhausenblas.info/#i
@since: 2015-06-19
@status: init
"""
import sys
import json
import urlparse
import urllib
from mc import lookup_service
from BaseHTTPServer import BaseHTTPRequestHandler
class SeDiProxy(BaseHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse.urlparse(self.path)
logical_service_name = parsed_path.path[1:]
self.resolve(logical_service_name)
return
def resolve(self, logical_service_name):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*') # enable CORS
self.end_headers()
(ip, port) = lookup_service('localhost', logical_service_name)
self.wfile.write( 'http://' + ip + ':' + port )
################################################################################
# Main script
#
if __name__ == '__main__':
from BaseHTTPServer import HTTPServer
server = HTTPServer(('', 31313), SeDiProxy)
server.serve_forever()