memcached (openstack) is no longer in use
[mirror/dsa-puppet.git] / 3rdparty / modules / cinder / manifests / api.pp
1 # == Class: cinder::api
2 #
3 # Setup and configure the cinder API endpoint
4 #
5 # === Parameters
6 #
7 # [*keystone_password*]
8 #   The password to use for authentication (keystone)
9 #
10 # [*keystone_enabled*]
11 #   (optional) Use keystone for authentification
12 #   Defaults to true
13 #
14 # [*keystone_tenant*]
15 #   (optional) The tenant of the auth user
16 #   Defaults to services
17 #
18 # [*keystone_user*]
19 #   (optional) The name of the auth user
20 #   Defaults to cinder
21 #
22 # [*keystone_auth_host*]
23 #   (optional) The keystone host
24 #   Defaults to localhost
25 #
26 # [*keystone_auth_port*]
27 #   (optional) The keystone auth port
28 #   Defaults to 35357
29 #
30 # [*keystone_auth_protocol*]
31 #   (optional) The protocol used to access the auth host
32 #   Defaults to http.
33 #
34 # [*os_region_name*]
35 #   (optional) Some operations require cinder to make API requests
36 #   to Nova. This sets the keystone region to be used for these
37 #   requests. For example, boot-from-volume.
38 #   Defaults to undef.
39 #
40 # [*keystone_auth_admin_prefix*]
41 #   (optional) The admin_prefix used to admin endpoint of the auth host
42 #   This allow admin auth URIs like http://auth_host:35357/keystone.
43 #   (where '/keystone' is the admin prefix)
44 #   Defaults to false for empty. If defined, should be a string with a
45 #   leading '/' and no trailing '/'.
46 #
47 # [*service_port*]
48 #   (optional) The cinder api port
49 #   Defaults to 5000
50 #
51 # [*service_workers*]
52 #   (optional) Number of cinder-api workers
53 #   Defaults to $::processorcount
54 #
55 # [*package_ensure*]
56 #   (optional) The state of the package
57 #   Defaults to present
58 #
59 # [*bind_host*]
60 #   (optional) The cinder api bind address
61 #   Defaults to 0.0.0.0
62 #
63 # [*enabled*]
64 #   (optional) The state of the service
65 #   Defaults to true
66 #
67 # [*manage_service*]
68 #   (optional) Whether to start/stop the service
69 #   Defaults to true
70 #
71 # [*ratelimits*]
72 #   (optional) The state of the service
73 #   Defaults to undef. If undefined the default ratelimiting values are used.
74 #
75 # [*ratelimits_factory*]
76 #   (optional) Factory to use for ratelimiting
77 #   Defaults to 'cinder.api.v1.limits:RateLimitingMiddleware.factory'
78 #
79 # [*default_volume_type*]
80 #   (optional) default volume type to use.
81 #   This should contain the name of the default volume type to use.
82 #   If not configured, it produces an error when creating a volume
83 #   without specifying a type.
84 #   Defaults to 'false'.
85 #
86 # [*validate*]
87 #   (optional) Whether to validate the service is working after any service refreshes
88 #   Defaults to false
89 #
90 # [*validation_options*]
91 #   (optional) Service validation options
92 #   Should be a hash of options defined in openstacklib::service_validation
93 #   If empty, defaults values are taken from openstacklib function.
94 #   Default command list volumes.
95 #   Require validate set at True.
96 #   Example:
97 #   glance::api::validation_options:
98 #     glance-api:
99 #       command: check_cinder-api.py
100 #       path: /usr/bin:/bin:/usr/sbin:/sbin
101 #       provider: shell
102 #       tries: 5
103 #       try_sleep: 10
104 #   Defaults to {}
105 #
106 class cinder::api (
107   $keystone_password,
108   $keystone_enabled           = true,
109   $keystone_tenant            = 'services',
110   $keystone_user              = 'cinder',
111   $keystone_auth_host         = 'localhost',
112   $keystone_auth_port         = '35357',
113   $keystone_auth_protocol     = 'http',
114   $keystone_auth_admin_prefix = false,
115   $keystone_auth_uri          = false,
116   $os_region_name             = undef,
117   $service_port               = '5000',
118   $service_workers            = $::processorcount,
119   $package_ensure             = 'present',
120   $bind_host                  = '0.0.0.0',
121   $enabled                    = true,
122   $manage_service             = true,
123   $ratelimits                 = undef,
124   $default_volume_type        = false,
125   $ratelimits_factory =
126     'cinder.api.v1.limits:RateLimitingMiddleware.factory',
127   $validate                   = false,
128   $validation_options         = {},
129 ) {
130
131   include cinder::params
132   include cinder::policy
133
134   Cinder_config<||> ~> Service['cinder-api']
135   Cinder_api_paste_ini<||> ~> Service['cinder-api']
136   Class['cinder::policy'] ~> Service['cinder-api']
137
138   if $::cinder::params::api_package {
139     Package['cinder-api'] -> Class['cinder::policy']
140     Package['cinder-api'] -> Cinder_config<||>
141     Package['cinder-api'] -> Cinder_api_paste_ini<||>
142     Package['cinder-api'] -> Service['cinder-api']
143     package { 'cinder-api':
144       ensure  => $package_ensure,
145       name    => $::cinder::params::api_package,
146     }
147   }
148
149   if $enabled {
150
151     Cinder_config<||> ~> Exec['cinder-manage db_sync']
152
153     exec { 'cinder-manage db_sync':
154       command     => $::cinder::params::db_sync_command,
155       path        => '/usr/bin',
156       user        => 'cinder',
157       refreshonly => true,
158       logoutput   => 'on_failure',
159       require     => Package['cinder'],
160     }
161     if $manage_service {
162       $ensure = 'running'
163     }
164   } else {
165     if $manage_service {
166       $ensure = 'stopped'
167     }
168   }
169
170   service { 'cinder-api':
171     ensure    => $ensure,
172     name      => $::cinder::params::api_service,
173     enable    => $enabled,
174     hasstatus => true,
175     require   => Package['cinder'],
176   }
177
178   cinder_config {
179     'DEFAULT/osapi_volume_listen':  value => $bind_host;
180     'DEFAULT/osapi_volume_workers': value => $service_workers;
181   }
182
183   if $os_region_name {
184     cinder_config {
185       'DEFAULT/os_region_name': value => $os_region_name;
186     }
187   }
188
189   if $keystone_auth_uri {
190     $auth_uri = $keystone_auth_uri
191   } else {
192     $auth_uri = "${keystone_auth_protocol}://${keystone_auth_host}:${service_port}/"
193   }
194   cinder_api_paste_ini { 'filter:authtoken/auth_uri': value => $auth_uri; }
195
196   if $keystone_enabled {
197     cinder_config {
198       'DEFAULT/auth_strategy':     value => 'keystone' ;
199     }
200     cinder_api_paste_ini {
201       'filter:authtoken/service_protocol':  value => $keystone_auth_protocol;
202       'filter:authtoken/service_host':      value => $keystone_auth_host;
203       'filter:authtoken/service_port':      value => $service_port;
204       'filter:authtoken/auth_protocol':     value => $keystone_auth_protocol;
205       'filter:authtoken/auth_host':         value => $keystone_auth_host;
206       'filter:authtoken/auth_port':         value => $keystone_auth_port;
207       'filter:authtoken/admin_tenant_name': value => $keystone_tenant;
208       'filter:authtoken/admin_user':        value => $keystone_user;
209       'filter:authtoken/admin_password':    value => $keystone_password, secret => true;
210     }
211
212   if ($ratelimits != undef) {
213     cinder_api_paste_ini {
214       'filter:ratelimit/paste.filter_factory': value => $ratelimits_factory;
215       'filter:ratelimit/limits':               value => $ratelimits;
216     }
217   }
218
219     if $keystone_auth_admin_prefix {
220       validate_re($keystone_auth_admin_prefix, '^(/.+[^/])?$')
221       cinder_api_paste_ini {
222         'filter:authtoken/auth_admin_prefix': value => $keystone_auth_admin_prefix;
223       }
224     } else {
225       cinder_api_paste_ini {
226         'filter:authtoken/auth_admin_prefix': ensure => absent;
227       }
228     }
229   }
230
231   if $default_volume_type {
232     cinder_config {
233       'DEFAULT/default_volume_type': value => $default_volume_type;
234     }
235   } else {
236     cinder_config {
237       'DEFAULT/default_volume_type': ensure => absent;
238     }
239   }
240
241   if $validate {
242     $defaults = {
243       'cinder-api' => {
244         'command'  => "cinder --os-auth-url ${auth_uri} --os-tenant-name ${keystone_tenant} --os-username ${keystone_user} --os-password ${keystone_password} list",
245       }
246     }
247     $validation_options_hash = merge ($defaults, $validation_options)
248     create_resources('openstacklib::service_validation', $validation_options_hash, {'subscribe' => 'Service[cinder-api]'})
249   }
250
251 }