From 64164078c1eab5a408e7ce15a8e533486281b320 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Sat, 5 Nov 2011 22:15:50 -0700 Subject: [PATCH] simple metadata service --- tools/uec/meta.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tools/uec/meta.py diff --git a/tools/uec/meta.py b/tools/uec/meta.py new file mode 100644 index 0000000000..5b845d81a6 --- /dev/null +++ b/tools/uec/meta.py @@ -0,0 +1,29 @@ +import sys +from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler +from SimpleHTTPServer import SimpleHTTPRequestHandler + +def main(host, port, HandlerClass = SimpleHTTPRequestHandler, + ServerClass = HTTPServer, protocol="HTTP/1.0"): + """simple http server that listens on a give address:port""" + + server_address = (host, port) + + HandlerClass.protocol_version = protocol + httpd = ServerClass(server_address, HandlerClass) + + sa = httpd.socket.getsockname() + print "Serving HTTP on", sa[0], "port", sa[1], "..." + httpd.serve_forever() + +if __name__ == '__main__': + if sys.argv[1:]: + address = sys.argv[1] + else: + address = '0.0.0.0' + if ':' in address: + host, port = address.split(':') + else: + host = address + port = 8080 + + main(host, int(port))