from gevent import pywsgi
# Append PLC to the system path
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
-#from PLC.API import PLCAPI
+from PLC.API import PLCAPI
+from PLC.Config import Config
+from PLC.Logger import logger
class App:
def __init__(self, api=None):
+ if not api:
+ api = PLCAPI()
self.api = api
def __call__(self, *args, **kwds):
def do_post(self, env, start_response):
try:
- request_size = int(environ.get('CONTENT_LENGTH', 0))
+ request_size = int(env.get('CONTENT_LENGTH', 0))
except (ValueError):
request_size = 0
- request = environ['wsgi.input'].read(request_size)
- client_address = environ['REMOTE_ADDR']
+ request = env['wsgi.input'].read(request_size)
+ client_address = env['REMOTE_ADDR']
try:
response = self.api.handle(client_address, request)
response = "'<h1>Internal Server Error</h1>"
status = '500 Internal Server Error'
headers = [('Content-Type', 'text/html')]
+ logger.log_exc(status)
start_response(status, headers)
return [response]
# Defaults
addr = "0.0.0.0"
port = 8000
-config = '/etc/planetlab/plc_config'
+config_file = '/etc/planetlab/plcapi_config'
keyfile=None
certfile=None
if options.config:
config = Config(options.config)
- addr = config
- keyfile = config.ssl_key_file
- certfile = config.ssl_cert_file
-
-
+ addr = config.api_host
+ keyfile = config.api_ssl_key
+ certfile = config.api_ssl_cert
+
if options.port:
port = int(options.port)
-# Start server
if keyfile and certfile:
server = pywsgi.WSGIServer((addr, port), App(), keyfile=keyfile, certfile=certfile)
else: