diff --git a/saltapi/netapi/rest_cherrypy/__init__.py b/saltapi/netapi/rest_cherrypy/__init__.py index 29533a1062..b5ccda0406 100644 --- a/saltapi/netapi/rest_cherrypy/__init__.py +++ b/saltapi/netapi/rest_cherrypy/__init__.py @@ -83,10 +83,11 @@ def start(): # Start the development server cherrypy.quickstart(root, '/', conf) else: - # Mount and start the WSGI app using the production CherryPy server - verify_certs(apiconf['ssl_crt'], apiconf['ssl_key']) + from . import wsgi + application = wsgi.get_application(root, apiopts, conf) - app = cherrypy.tree.mount(app, '/', config=conf) + # Mount and start the WSGI app using the production CherryPy server + verify_certs(apiopts['ssl_crt'], apiopts['ssl_key']) ssl_a = wsgiserver.ssl_builtin.BuiltinSSLAdapter( apiopts['ssl_crt'], apiopts['ssl_key']) diff --git a/saltapi/netapi/rest_cherrypy/wsgi.py b/saltapi/netapi/rest_cherrypy/wsgi.py new file mode 100644 index 0000000000..1915420619 --- /dev/null +++ b/saltapi/netapi/rest_cherrypy/wsgi.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +''' +A WSGI app to start a REST interface to Salt + +This WSGI app can be used with any WSGI-compliant server. See the rest_cherrypy +netapi module to see how this app is run with the CherryPy WSGI server. + +Apache's mod_wsgi instructions +------------------------------ + +Add the path to this script as a WSGIScriptAlias in the Apache configuration +for your site. For example a virtual host configuration may look something +like:: + + + ServerName example.com + ServerAlias *.example.com + + ServerAdmin webmaster@example.com + + LogLevel warn + ErrorLog /var/www/example.com/logs/error.log + CustomLog /var/www/example.com/logs/access.log combined + + DocumentRoot /var/www/example.com/htdocs + + WSGIScriptAlias / /path/to/saltapi/netapi/rest_cherrypy/app.wsgi + + +''' +# pylint: disable=C0103 + +import cherrypy + +from . import app + +def bootstrap_app(): + ''' + Grab the opts dict of the master config by trying to import Salt + ''' + import salt.client + opts = salt.client.LocalClient().opts + return app.get_app(opts) + +def get_application(*args): + ''' + Returns a WSGI application function. If you supply the WSGI app and config + it will use that, otherwise it will try to obtain them from a local Salt + installation + ''' + opts_tuple = args + + def wsgi_app(environ, start_response): + root, _, conf = opts_tuple or bootstrap_app() + + cherrypy.tree.mount(root, '/', conf) + return cherrypy.tree(environ, start_response) + + return wsgi_app + +application = get_application()