]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/manifests/wsgi/apache.pp
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / keystone / manifests / wsgi / apache.pp
1 #
2 # Class to serve keystone with apache mod_wsgi in place of keystone service
3 #
4 # Serving keystone from apache is the recommended way to go for production
5 # systems as the current keystone implementation is not multi-processor aware,
6 # thus limiting the performance for concurrent accesses.
7 #
8 # See the following URIs for reference:
9 #    https://etherpad.openstack.org/havana-keystone-performance
10 #    http://adam.younglogic.com/2012/03/keystone-should-move-to-apache-httpd/
11 #
12 # When using this class you should disable your keystone service.
13 #
14 # == Parameters
15 #
16 #   [*servername*]
17 #     The servername for the virtualhost.
18 #     Optional. Defaults to $::fqdn
19 #
20 #   [*public_port*]
21 #     The public port.
22 #     Optional. Defaults to 5000
23 #
24 #   [*admin_port*]
25 #     The admin port.
26 #     Optional. Defaults to 35357
27 #
28 #   [*bind_host*]
29 #     The host/ip address Apache will listen on.
30 #     Optional. Defaults to undef (listen on all ip addresses).
31 #
32 #   [*public_path*]
33 #     The prefix for the public endpoint.
34 #     Optional. Defaults to '/'
35 #
36 #   [*admin_path*]
37 #     The prefix for the admin endpoint.
38 #     Optional. Defaults to '/'
39 #
40 #   [*ssl*]
41 #     Use ssl ? (boolean)
42 #     Optional. Defaults to true
43 #
44 #   [*workers*]
45 #     Number of WSGI workers to spawn.
46 #     Optional. Defaults to 1
47 #
48 #   [*ssl_cert*]
49 #     (optional) Path to SSL certificate
50 #     Default to apache::vhost 'ssl_*' defaults.
51 #
52 #   [*ssl_key*]
53 #     (optional) Path to SSL key
54 #     Default to apache::vhost 'ssl_*' defaults.
55 #
56 #   [*ssl_chain*]
57 #     (optional) SSL chain
58 #     Default to apache::vhost 'ssl_*' defaults.
59 #
60 #   [*ssl_ca*]
61 #     (optional) Path to SSL certificate authority
62 #     Default to apache::vhost 'ssl_*' defaults.
63 #
64 #   [*ssl_crl_path*]
65 #     (optional) Path to SSL certificate revocation list
66 #     Default to apache::vhost 'ssl_*' defaults.
67 #
68 #   [*ssl_crl*]
69 #     (optional) SSL certificate revocation list name
70 #     Default to apache::vhost 'ssl_*' defaults.
71 #
72 #   [*ssl_certs_dir*]
73 #     apache::vhost ssl parameters.
74 #     Optional. Default to apache::vhost 'ssl_*' defaults.
75 #
76 #   [*priority*]
77 #     (optional) The priority for the vhost.
78 #     Defaults to '10'
79 #
80 #   [*threads*]
81 #     (optional) The number of threads for the vhost.
82 #     Defaults to $::processorcount
83 #
84 #   [*wsgi_script_ensure*]
85 #     (optional) File ensure parameter for wsgi scripts.
86 #     Defaults to 'file'.
87 #
88 #   [*wsgi_script_source*]
89 #     (optional) Wsgi script source.
90 #     Defaults to undef.
91 #
92 # == Dependencies
93 #
94 #   requires Class['apache'] & Class['keystone']
95 #
96 # == Examples
97 #
98 #   include apache
99 #
100 #   class { 'keystone::wsgi::apache': }
101 #
102 # == Note about ports & paths
103 #
104 #   When using same port for both endpoints (443 anyone ?), you *MUST* use two
105 #  different public_path & admin_path !
106 #
107 # == Authors
108 #
109 #   Francois Charlier <francois.charlier@enovance.com>
110 #
111 # == Copyright
112 #
113 #   Copyright 2013 eNovance <licensing@enovance.com>
114 #
115 class keystone::wsgi::apache (
116   $servername         = $::fqdn,
117   $public_port        = 5000,
118   $admin_port         = 35357,
119   $bind_host          = undef,
120   $public_path        = '/',
121   $admin_path         = '/',
122   $ssl                = true,
123   $workers            = 1,
124   $ssl_cert           = undef,
125   $ssl_key            = undef,
126   $ssl_chain          = undef,
127   $ssl_ca             = undef,
128   $ssl_crl_path       = undef,
129   $ssl_crl            = undef,
130   $ssl_certs_dir      = undef,
131   $threads            = $::processorcount,
132   $priority           = '10',
133   $wsgi_script_ensure = 'file',
134   $wsgi_script_source = undef,
135 ) {
136
137   include ::keystone::params
138   include ::apache
139   include ::apache::mod::wsgi
140   if $ssl {
141     include ::apache::mod::ssl
142   }
143
144   Package['keystone'] -> Package['httpd']
145   Package['keystone'] ~> Service['httpd']
146   Keystone_config <| |> ~> Service['httpd']
147   Service['httpd'] -> Keystone_endpoint <| |>
148   Service['httpd'] -> Keystone_role <| |>
149   Service['httpd'] -> Keystone_service <| |>
150   Service['httpd'] -> Keystone_tenant <| |>
151   Service['httpd'] -> Keystone_user <| |>
152   Service['httpd'] -> Keystone_user_role <| |>
153
154   ## Sanitize parameters
155
156   # Ensure there's no trailing '/' except if this is also the only character
157   $public_path_real = regsubst($public_path, '(^/.*)/$', '\1')
158   # Ensure there's no trailing '/' except if this is also the only character
159   $admin_path_real = regsubst($admin_path, '(^/.*)/$', '\1')
160
161   if $public_port == $admin_port and $public_path_real == $admin_path_real {
162     fail('When using the same port for public & private endpoints, public_path and admin_path should be different.')
163   }
164
165   file { $::keystone::params::keystone_wsgi_script_path:
166     ensure  => directory,
167     owner   => 'keystone',
168     group   => 'keystone',
169     require => Package['httpd'],
170   }
171
172   $wsgi_files = {
173     'keystone_wsgi_admin' => {
174       'path' => "${::keystone::params::keystone_wsgi_script_path}/admin",
175     },
176     'keystone_wsgi_main'  => {
177       'path' => "${::keystone::params::keystone_wsgi_script_path}/main",
178     },
179   }
180
181   $wsgi_file_defaults = {
182     'ensure'  => $wsgi_script_ensure,
183     'owner'   => 'keystone',
184     'group'   => 'keystone',
185     'mode'    => '0644',
186     'require' => [File[$::keystone::params::keystone_wsgi_script_path], Package['keystone']],
187   }
188
189   $wsgi_script_source_real = $wsgi_script_source ? {
190     default => $wsgi_script_source,
191     undef   => $::keystone::params::keystone_wsgi_script_source,
192   }
193
194   case $wsgi_script_ensure {
195     'link':  { $wsgi_file_source = { 'target' => $wsgi_script_source_real } }
196     default: { $wsgi_file_source = { 'source' => $wsgi_script_source_real } }
197   }
198
199   create_resources('file', $wsgi_files, merge($wsgi_file_defaults, $wsgi_file_source))
200
201   $wsgi_daemon_process_options_main = {
202     user         => 'keystone',
203     group        => 'keystone',
204     processes    => $workers,
205     threads      => $threads,
206     display-name => 'keystone-main',
207   }
208
209   $wsgi_daemon_process_options_admin = {
210     user         => 'keystone',
211     group        => 'keystone',
212     processes    => $workers,
213     threads      => $threads,
214     display-name => 'keystone-admin',
215   }
216
217   $wsgi_script_aliases_main = hash([$public_path_real,"${::keystone::params::keystone_wsgi_script_path}/main"])
218   $wsgi_script_aliases_admin = hash([$admin_path_real, "${::keystone::params::keystone_wsgi_script_path}/admin"])
219
220   if $public_port == $admin_port {
221     $wsgi_script_aliases_main_real = merge($wsgi_script_aliases_main, $wsgi_script_aliases_admin)
222   } else {
223     $wsgi_script_aliases_main_real = $wsgi_script_aliases_main
224   }
225
226   ::apache::vhost { 'keystone_wsgi_main':
227     ensure                      => 'present',
228     servername                  => $servername,
229     ip                          => $bind_host,
230     port                        => $public_port,
231     docroot                     => $::keystone::params::keystone_wsgi_script_path,
232     docroot_owner               => 'keystone',
233     docroot_group               => 'keystone',
234     priority                    => $priority,
235     ssl                         => $ssl,
236     ssl_cert                    => $ssl_cert,
237     ssl_key                     => $ssl_key,
238     ssl_chain                   => $ssl_chain,
239     ssl_ca                      => $ssl_ca,
240     ssl_crl_path                => $ssl_crl_path,
241     ssl_crl                     => $ssl_crl,
242     ssl_certs_dir               => $ssl_certs_dir,
243     wsgi_daemon_process         => 'keystone_main',
244     wsgi_daemon_process_options => $wsgi_daemon_process_options_main,
245     wsgi_process_group          => 'keystone_main',
246     wsgi_script_aliases         => $wsgi_script_aliases_main_real,
247     require                     => File['keystone_wsgi_main'],
248   }
249
250   if $public_port != $admin_port {
251     ::apache::vhost { 'keystone_wsgi_admin':
252       ensure                      => 'present',
253       servername                  => $servername,
254       ip                          => $bind_host,
255       port                        => $admin_port,
256       docroot                     => $::keystone::params::keystone_wsgi_script_path,
257       docroot_owner               => 'keystone',
258       docroot_group               => 'keystone',
259       priority                    => $priority,
260       ssl                         => $ssl,
261       ssl_cert                    => $ssl_cert,
262       ssl_key                     => $ssl_key,
263       ssl_chain                   => $ssl_chain,
264       ssl_ca                      => $ssl_ca,
265       ssl_crl_path                => $ssl_crl_path,
266       ssl_crl                     => $ssl_crl,
267       ssl_certs_dir               => $ssl_certs_dir,
268       wsgi_daemon_process         => 'keystone_admin',
269       wsgi_daemon_process_options => $wsgi_daemon_process_options_admin,
270       wsgi_process_group          => 'keystone_admin',
271       wsgi_script_aliases         => $wsgi_script_aliases_admin,
272       require                     => File['keystone_wsgi_admin'],
273     }
274   }
275 }