Skip to content

Instantly share code, notes, and snippets.

@wido
Created May 28, 2014 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wido/8bf032e5f482bfef949c to your computer and use it in GitHub Desktop.
Save wido/8bf032e5f482bfef949c to your computer and use it in GitHub Desktop.
Ceph REST API WSGI wrapper
'''
WSGI wrapper for the Ceph REST API to be run behind Apache with mod_wsgi.
Place this script in /var/www as ceph-rest-api.wsgi and use this VirtualHost:
<VirtualHost *:80>
DocumentRoot /var/www
ServerName ceph-rest-api
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
WSGIScriptAlias / /var/www/ceph-rest-api.wsgi
</VirtualHost>
You have to specify a Ceph configuration file to use, that will be used
to detect which monitors to connect to and which keyring to use.
A sample Ceph configuration:
[global]
keyring = /var/www/ceph.client.admin.keyring
mon_host = 1.2.3.4,2.3.4.5,3.4.5.6
log_file = /dev/null
Make sure that the configuration file and keyring are readable by the webserver.
Logging has to be disabled, otherwise librados will try to create a logfile
in /var/log which is not allowed by when running under the webserver's user.
Now go to http://localhost/api/v0.1 and you should see the API!
Tested with:
- Ubuntu 14.04
- Apache 2.4 (apache2-mpm-worker)
- mod_wsgi (libapache2-mod-wsgi)
- Python 2.7.6
'''
conffile="/var/www/ceph.conf"
cluster="ceph"
clientname=None
clientid="admin"
args=None
import ceph_rest_api
application = ceph_rest_api.generate_app(conffile, cluster, clientname, clientid, args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment