3 # Simple standalone HTTP server for testing PLCAPI
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
8 # $Id: Server.py,v 1.1 2006/09/06 15:33:59 mlhuang Exp $
17 from PLC.API import PLCAPI
19 class PLCAPIRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
21 Simple standalone HTTP request handler for testing PLCAPI.
27 request = self.rfile.read(int(self.headers["Content-length"]))
30 response = self.server.api.handle(self.client_address, request)
33 self.send_response(200)
34 self.wfile.write(response)
37 self.connection.shutdown(1)
41 sys.stderr.write(traceback.format_exc())
45 self.send_response(200)
46 self.send_header("Content-type", 'text/html')
50 <title>PLCAPI XML-RPC/SOAP Interface</title>
52 <h1>PLCAPI XML-RPC/SOAP Interface</h1>
53 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
57 class PLCAPIServer(BaseHTTPServer.HTTPServer):
59 Simple standalone HTTP server for testing PLCAPI.
62 def __init__(self, addr, config):
63 self.api = PLCAPI(config)
64 self.allow_reuse_address = 1
65 BaseHTTPServer.HTTPServer.__init__(self, addr, PLCAPIRequestHandler)
70 config = "/etc/planetlab/plc_config"
73 print "Usage: %s [OPTION]..." % sys.argv[0]
75 print " -p PORT, --port=PORT TCP port number to listen on (default: %d)" % port
76 print " -f FILE, --config=FILE PLC configuration file (default: %s)" % config
77 print " -h, --help This message"
82 (opts, argv) = getopt.getopt(sys.argv[1:], "p:f:h", ["port=", "config=", "help"])
83 except getopt.GetoptError, err:
84 print "Error: " + err.msg
87 for (opt, optval) in opts:
88 if opt == "-p" or opt == "--port":
93 elif opt == "-f" or opt == "--config":
95 elif opt == "-h" or opt == "--help":
99 PLCAPIServer((addr, port), config).serve_forever()