Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions attributes/restapi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Cookbook Name:: ceph
# Attributes:: restapi
#
# Copyright 2011, DreamHost Web Hosting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default['ceph']['restapi']['admin_email'] = '[email protected]'
default['ceph']['restapi']['addr'] = '127.0.0.1:5000' # vhost port
default['ceph']['restapi']['name'] = nil # don't add a servername line
default['ceph']['restapi']['port'] = 5000 # add this port to the listening ports
default['ceph']['restapi']['user'] = 'www-data' # owner of keyring and logfile
default['ceph']['restapi']['group'] = 'www-data' # owner of keyring and logfile
default['ceph']['restapi']['webserver_companion'] = 'apache2' # can be false
1 change: 1 addition & 0 deletions recipes/all_in_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
include_recipe 'ceph::mds'
include_recipe 'ceph::cephfs'
include_recipe 'ceph::radosgw'
include_recipe 'ceph::restapi'
43 changes: 43 additions & 0 deletions recipes/restapi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Author:: Kyle Bader <[email protected]>
# Cookbook Name:: ceph
# Recipe:: restapi
#
# Copyright 2011, DreamHost Web Hosting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

node.default['ceph']['is_restapi'] = true

include_recipe 'ceph::conf'

if node['ceph']['restapi']['webserver_companion']
# updates the webserver owner
include_recipe "ceph::restapi_#{node['ceph']['restapi']['webserver_companion']}"
end

config_section_name = 'client.restapi.' + node['hostname']
config_section = { 'log_file' => '/var/log/ceph/restapi/restapi.log' }
node.default['ceph']['config-sections'][config_section_name] = config_section

directory '/var/log/ceph/restapi' do
owner node['ceph']['restapi']['user']
group node['ceph']['restapi']['group']
mode 0755
action :create
end
ceph_client 'restapi' do
caps('mon' => 'allow *', 'osd' => 'allow *')
owner node['ceph']['restapi']['user']
group node['ceph']['restapi']['group']
end
49 changes: 49 additions & 0 deletions recipes/restapi_apache2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Author:: Kyle Bader <[email protected]>
# Cookbook Name:: ceph
# Recipe:: restapi_apache2
#
# Copyright 2011, DreamHost Web Hosting
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# For EL, delete the current fastcgi configuration
# and set the correct owners for dirs and logs
d_owner = d_group = 'root'
d_owner = d_group = 'apache' if node['platform_family'] == 'rhel'
node.default['ceph']['restapi']['user'] = node['apache']['user']
node.default['ceph']['restapi']['group'] = node['apache']['group']

template '/usr/lib/ceph/restapi.wsgi' do
mode 0644
owner 'root'
group 'root'
end

file '/var/log/ceph/rest.log' do
owner d_owner
group d_group
mode '0644'
action :create
end

if node['ceph']['restapi']['port']
node.default['apache']['listen_ports'].push(node['ceph']['restapi']['port'])
end

include_recipe 'apache2'
include_recipe 'apache2::mod_wsgi'

web_app 'restapi' do
template 'restapi.conf.erb'
end
25 changes: 25 additions & 0 deletions templates/default/restapi.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<VirtualHost <%= node['ceph']['restapi']['addr'] %> >
<% if node['ceph']['restapi']['name'] -%>
ServerName <%= node['ceph']['restapi']['name'] %>
<% end -%>
ServerAdmin <%= node['ceph']['restapi']['admin_email'] %>
DocumentRoot /var/www/

WSGIDaemonProcess cephrest user=<%=node['apache']['user']%> group=<%=node['apache']['group']%> processes=1 threads=5
WSGIScriptAlias / /usr/lib/ceph/restapi.wsgi

<Location />
WSGIProcessGroup cephrest
WSGIApplicationGroup %{GLOBAL}
<%- if node[:apache][:version].to_f < 2.4 %>
Order allow,deny
Allow from all
<%- else %>
Require all granted
<%- end %>
</Location>

ErrorLog /var/log/<%= node['apache']['package'] %>/error.log
CustomLog /var/log/<%= node['apache']['package'] %>/ceph-rest-access.log proxy_combined
ServerSignature Off
</VirtualHost>
23 changes: 23 additions & 0 deletions templates/default/restapi.wsgi.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
# vim: ts=4 sw=4 smarttab expandtab

import sys

# import now that env vars are available to imported module

try:
import ceph_rest_api
except EnvironmentError as e:
print >> sys.stderr, "Error importing ceph_rest_api: ", str(e)
sys.exit(1)

# let other exceptions generate traceback

application = ceph_rest_api.generate_app(
conf = None,
cluster = None,
clientname = 'client.restapi.<%=node['hostname']%>',
clientid = None,
args = []
)

16 changes: 16 additions & 0 deletions test/integration/aio/bats/restapi.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@test "restapi client key is generated" {
test -e /etc/ceph/ceph.client.restapi*
}

@test "restapi is configured" {
test -e /etc/apache2/sites-enabled/restapi.conf
grep -F 'WSGIScriptAlias / /usr/lib/ceph/restapi.wsgi' /etc/apache2/sites-enabled/restapi.conf > /dev/null
}

@test "restapi is listening on the port" {
netstat -lnpt | grep 5000
}

@test "restapi is responding with data" {
wget -q -O - http://127.0.0.1:5000/api/v0.1/mon_status | grep quorum > /dev/null
}