]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/manifests/wsgi/apache.pp
43e3b8515177a260514a8d48ea7b713d6d13deed
[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 #   [*ssl_key*]
50 #   [*ssl_chain*]
51 #   [*ssl_ca*]
52 #   [*ssl_crl_path*]
53 #   [*ssl_crl*]
54 #   [*ssl_certs_dir*]
55 #     apache::vhost ssl parameters.
56 #     Optional. Default to apache::vhost 'ssl_*' defaults.
57 #
58 # == Dependencies
59 #
60 #   requires Class['apache'] & Class['keystone']
61 #
62 # == Examples
63 #
64 #   include apache
65 #
66 #   class { 'keystone::wsgi::apache': }
67 #
68 # == Note about ports & paths
69 #
70 #   When using same port for both endpoints (443 anyone ?), you *MUST* use two
71 #  different public_path & admin_path !
72 #
73 # == Authors
74 #
75 #   Francois Charlier <francois.charlier@enovance.com>
76 #
77 # == Copyright
78 #
79 #   Copyright 2013 eNovance <licensing@enovance.com>
80 #
81 class keystone::wsgi::apache (
82   $servername    = $::fqdn,
83   $public_port   = 5000,
84   $admin_port    = 35357,
85   $bind_host     = undef,
86   $public_path   = '/',
87   $admin_path    = '/',
88   $ssl           = true,
89   $workers       = 1,
90   $ssl_cert      = undef,
91   $ssl_key       = undef,
92   $ssl_chain     = undef,
93   $ssl_ca        = undef,
94   $ssl_crl_path  = undef,
95   $ssl_crl       = undef,
96   $ssl_certs_dir = undef,
97   $threads       = $::processorcount,
98   $priority      = '10',
99 ) {
100
101   include ::keystone::params
102   include ::apache
103   include ::apache::mod::wsgi
104   if $ssl {
105     include ::apache::mod::ssl
106   }
107
108   Package['keystone'] -> Package['httpd']
109   Package['keystone'] ~> Service['httpd']
110   Keystone_config <| |> ~> Service['httpd']
111   Service['httpd'] -> Keystone_endpoint <| |>
112   Service['httpd'] -> Keystone_role <| |>
113   Service['httpd'] -> Keystone_service <| |>
114   Service['httpd'] -> Keystone_tenant <| |>
115   Service['httpd'] -> Keystone_user <| |>
116   Service['httpd'] -> Keystone_user_role <| |>
117
118   ## Sanitize parameters
119
120   # Ensure there's no trailing '/' except if this is also the only character
121   $public_path_real = regsubst($public_path, '(^/.*)/$', '\1')
122   # Ensure there's no trailing '/' except if this is also the only character
123   $admin_path_real = regsubst($admin_path, '(^/.*)/$', '\1')
124
125   if $public_port == $admin_port and $public_path_real == $admin_path_real {
126     fail('When using the same port for public & private endpoints, public_path and admin_path should be different.')
127   }
128
129   file { $::keystone::params::keystone_wsgi_script_path:
130     ensure  => directory,
131     owner   => 'keystone',
132     group   => 'keystone',
133     require => Package['httpd'],
134   }
135
136   file { 'keystone_wsgi_admin':
137     ensure  => file,
138     path    => "${::keystone::params::keystone_wsgi_script_path}/admin",
139     source  => $::keystone::params::keystone_wsgi_script_source,
140     owner   => 'keystone',
141     group   => 'keystone',
142     mode    => '0644',
143     # source file provided by keystone package
144     require => [File[$::keystone::params::keystone_wsgi_script_path], Package['keystone']],
145   }
146
147   file { 'keystone_wsgi_main':
148     ensure  => file,
149     path    => "${::keystone::params::keystone_wsgi_script_path}/main",
150     source  => $::keystone::params::keystone_wsgi_script_source,
151     owner   => 'keystone',
152     group   => 'keystone',
153     mode    => '0644',
154     # source file provided by keystone package
155     require => [File[$::keystone::params::keystone_wsgi_script_path], Package['keystone']],
156   }
157
158   $wsgi_daemon_process_options_main = {
159     user         => 'keystone',
160     group        => 'keystone',
161     processes    => $workers,
162     threads      => $threads,
163     display-name => 'keystone-main',
164   }
165
166   $wsgi_daemon_process_options_admin = {
167     user         => 'keystone',
168     group        => 'keystone',
169     processes    => $workers,
170     threads      => $threads,
171     display-name => 'keystone-admin',
172   }
173
174   $wsgi_script_aliases_main = hash([$public_path_real,"${::keystone::params::keystone_wsgi_script_path}/main"])
175   $wsgi_script_aliases_admin = hash([$admin_path_real, "${::keystone::params::keystone_wsgi_script_path}/admin"])
176
177   if $public_port == $admin_port {
178     $wsgi_script_aliases_main_real = merge($wsgi_script_aliases_main, $wsgi_script_aliases_admin)
179   } else {
180     $wsgi_script_aliases_main_real = $wsgi_script_aliases_main
181   }
182
183   ::apache::vhost { 'keystone_wsgi_main':
184     ensure                      => 'present',
185     servername                  => $servername,
186     ip                          => $bind_host,
187     port                        => $public_port,
188     docroot                     => $::keystone::params::keystone_wsgi_script_path,
189     docroot_owner               => 'keystone',
190     docroot_group               => 'keystone',
191     priority                    => $priority,
192     ssl                         => $ssl,
193     ssl_cert                    => $ssl_cert,
194     ssl_key                     => $ssl_key,
195     ssl_chain                   => $ssl_chain,
196     ssl_ca                      => $ssl_ca,
197     ssl_crl_path                => $ssl_crl_path,
198     ssl_crl                     => $ssl_crl,
199     ssl_certs_dir               => $ssl_certs_dir,
200     wsgi_daemon_process         => 'keystone_main',
201     wsgi_daemon_process_options => $wsgi_daemon_process_options_main,
202     wsgi_process_group          => 'keystone_main',
203     wsgi_script_aliases         => $wsgi_script_aliases_main_real,
204     require                     => File['keystone_wsgi_main'],
205   }
206
207   if $public_port != $admin_port {
208     ::apache::vhost { 'keystone_wsgi_admin':
209       ensure                      => 'present',
210       servername                  => $servername,
211       ip                          => $bind_host,
212       port                        => $admin_port,
213       docroot                     => $::keystone::params::keystone_wsgi_script_path,
214       docroot_owner               => 'keystone',
215       docroot_group               => 'keystone',
216       priority                    => $priority,
217       ssl                         => $ssl,
218       ssl_cert                    => $ssl_cert,
219       ssl_key                     => $ssl_key,
220       ssl_chain                   => $ssl_chain,
221       ssl_ca                      => $ssl_ca,
222       ssl_crl_path                => $ssl_crl_path,
223       ssl_crl                     => $ssl_crl,
224       ssl_certs_dir               => $ssl_certs_dir,
225       wsgi_daemon_process         => 'keystone_admin',
226       wsgi_daemon_process_options => $wsgi_daemon_process_options_admin,
227       wsgi_process_group          => 'keystone_admin',
228       wsgi_script_aliases         => $wsgi_script_aliases_admin,
229       require                     => File['keystone_wsgi_admin'],
230     }
231   }
232 }