try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / glance / manifests / api.pp
1 # == Class glance::api
2 #
3 # Configure API service in glance
4 #
5 # == Parameters
6 #
7 # [*keystone_password*]
8 #   (required) Password used to authentication.
9 #
10 # [*verbose*]
11 #   (optional) Rather to log the glance api service at verbose level.
12 #   Default: false
13 #
14 # [*debug*]
15 #   (optional) Rather to log the glance api service at debug level.
16 #   Default: false
17 #
18 # [*bind_host*]
19 #   (optional) The address of the host to bind to.
20 #   Default: 0.0.0.0
21 #
22 # [*bind_port*]
23 #   (optional) The port the server should bind to.
24 #   Default: 9292
25 #
26 # [*backlog*]
27 #   (optional) Backlog requests when creating socket
28 #   Default: 4096
29 #
30 # [*workers*]
31 #   (optional) Number of Glance API worker processes to start
32 #   Default: $::processorcount
33 #
34 # [*log_file*]
35 #   (optional) The path of file used for logging
36 #   If set to boolean false, it will not log to any file.
37 #   Default: /var/log/glance/api.log
38 #
39 #  [*log_dir*]
40 #    (optional) directory to which glance logs are sent.
41 #    If set to boolean false, it will not log to any directory.
42 #    Defaults to '/var/log/glance'
43 #
44 # [*registry_host*]
45 #   (optional) The address used to connect to the registry service.
46 #   Default: 0.0.0.0
47 #
48 # [*registry_port*]
49 #   (optional) The port of the Glance registry service.
50 #   Default: 9191
51 #
52 # [*registry_client_protocol*]
53 #   (optional) The protocol of the Glance registry service.
54 #   Default: http
55 #
56 # [*auth_type*]
57 #   (optional) Type is authorization being used.
58 #   Defaults to 'keystone'
59 #
60 # [* auth_host*]
61 #   (optional) Host running auth service.
62 #   Defaults to '127.0.0.1'.
63 #
64 # [*auth_url*]
65 #   (optional) Authentication URL.
66 #   Defaults to 'http://localhost:5000/v2.0'.
67 #
68 # [* auth_port*]
69 #   (optional) Port to use for auth service on auth_host.
70 #   Defaults to '35357'.
71 #
72 # [* auth_uri*]
73 #   (optional) Complete public Identity API endpoint.
74 #   Defaults to false.
75 #
76 # [*auth_admin_prefix*]
77 #   (optional) Path part of the auth url.
78 #   This allow admin auth URIs like http://auth_host:35357/keystone/admin.
79 #   (where '/keystone/admin' is auth_admin_prefix)
80 #   Defaults to false for empty. If defined, should be a string with a leading '/' and no trailing '/'.
81 #
82 # [* auth_protocol*]
83 #   (optional) Protocol to use for auth.
84 #   Defaults to 'http'.
85 #
86 # [*pipeline*]
87 #   (optional) Partial name of a pipeline in your paste configuration file with the
88 #   service name removed.
89 #   Defaults to 'keystone+cachemanagement'.
90 #
91 # [*keystone_tenant*]
92 #   (optional) Tenant to authenticate to.
93 #   Defaults to services.
94 #
95 # [*keystone_user*]
96 #   (optional) User to authenticate as with keystone.
97 #   Defaults to 'glance'.
98 #
99 # [*manage_service*]
100 #   (optional) If Puppet should manage service startup / shutdown.
101 #   Defaults to true.
102 #
103 # [*enabled*]
104 #   (optional) Whether to enable services.
105 #   Defaults to true.
106 #
107 # [*sql_idle_timeout*]
108 #   (optional) Deprecated. Use database_idle_timeout instead
109 #   Defaults to false
110 #
111 # [*sql_connection*]
112 #   (optional) Deprecated. Use database_connection instead.
113 #   Defaults to false
114 #
115 # [*database_connection*]
116 #   (optional) Connection url to connect to nova database.
117 #   Defaults to 'sqlite:///var/lib/glance/glance.sqlite'
118 #
119 # [*database_idle_timeout*]
120 #   (optional) Timeout before idle db connections are reaped.
121 #   Defaults to 3600
122 #
123 # [*use_syslog*]
124 #   (optional) Use syslog for logging.
125 #   Defaults to false.
126 #
127 # [*log_facility*]
128 #   (optional) Syslog facility to receive log lines.
129 #   Defaults to 'LOG_USER'.
130 #
131 # [*show_image_direct_url*]
132 #   (optional) Expose image location to trusted clients.
133 #   Defaults to false.
134 #
135 # [*purge_config*]
136 #   (optional) Whether to set only the specified config options
137 #   in the api config.
138 #   Defaults to false.
139 #
140 # [*cert_file*]
141 #   (optinal) Certificate file to use when starting API server securely
142 #   Defaults to false, not set
143 #
144 # [*key_file*]
145 #   (optional) Private key file to use when starting API server securely
146 #   Defaults to false, not set
147 #
148 # [*ca_file*]
149 #   (optional) CA certificate file to use to verify connecting clients
150 #   Defaults to false, not set
151 #
152 # [*mysql_module*]
153 #   (optional) Deprecated. Does nothing.
154 #
155 # [*known_stores*]
156 #   (optional)List of which store classes and store class locations are
157 #    currently known to glance at startup.
158 #    Defaults to false.
159 #    Example: ['glance.store.filesystem.Store','glance.store.http.Store']
160 #
161 # [*image_cache_dir*]
162 #   (optional) Base directory that the Image Cache uses.
163 #    Defaults to '/var/lib/glance/image-cache'.
164 #
165 # [*os_region_name*]
166 #   (optional) Sets the keystone region to use.
167 #   Defaults to 'RegionOne'.
168 #
169 # [*validate*]
170 #   (optional) Whether to validate the service is working after any service refreshes
171 #   Defaults to false
172 #
173 # [*validation_options*]
174 #   (optional) Service validation options
175 #   Should be a hash of options defined in openstacklib::service_validation
176 #   If empty, defaults values are taken from openstacklib function.
177 #   Default command list images.
178 #   Require validate set at True.
179 #   Example:
180 #   glance::api::validation_options:
181 #     glance-api:
182 #       command: check_glance-api.py
183 #       path: /usr/bin:/bin:/usr/sbin:/sbin
184 #       provider: shell
185 #       tries: 5
186 #       try_sleep: 10
187 #   Defaults to {}
188 #
189 class glance::api(
190   $keystone_password,
191   $verbose                  = false,
192   $debug                    = false,
193   $bind_host                = '0.0.0.0',
194   $bind_port                = '9292',
195   $backlog                  = '4096',
196   $workers                  = $::processorcount,
197   $log_file                 = '/var/log/glance/api.log',
198   $log_dir                  = '/var/log/glance',
199   $registry_host            = '0.0.0.0',
200   $registry_port            = '9191',
201   $registry_client_protocol = 'http',
202   $auth_type                = 'keystone',
203   $auth_host                = '127.0.0.1',
204   $auth_url                 = 'http://localhost:5000/v2.0',
205   $auth_port                = '35357',
206   $auth_uri                 = false,
207   $auth_admin_prefix        = false,
208   $auth_protocol            = 'http',
209   $pipeline                 = 'keystone+cachemanagement',
210   $keystone_tenant          = 'services',
211   $keystone_user            = 'glance',
212   $manage_service           = true,
213   $enabled                  = true,
214   $use_syslog               = false,
215   $log_facility             = 'LOG_USER',
216   $show_image_direct_url    = false,
217   $purge_config             = false,
218   $cert_file                = false,
219   $key_file                 = false,
220   $ca_file                  = false,
221   $known_stores             = false,
222   $database_connection      = 'sqlite:///var/lib/glance/glance.sqlite',
223   $database_idle_timeout    = 3600,
224   $image_cache_dir          = '/var/lib/glance/image-cache',
225   $os_region_name           = 'RegionOne',
226   $validate                 = false,
227   $validation_options       = {},
228   # DEPRECATED PARAMETERS
229   $mysql_module             = undef,
230   $sql_idle_timeout         = false,
231   $sql_connection           = false,
232 ) inherits glance {
233
234   include glance::policy
235   require keystone::python
236
237   if $mysql_module {
238     warning('The mysql_module parameter is deprecated. The latest 2.x mysql module will be used.')
239   }
240
241   if ( $glance::params::api_package_name != $glance::params::registry_package_name ) {
242     ensure_packages([$glance::params::api_package_name],
243       {
244         tag    => ['openstack'],
245       }
246     )
247   }
248
249   Package[$glance::params::api_package_name] -> File['/etc/glance/']
250   Package[$glance::params::api_package_name] -> Class['glance::policy']
251   Package[$glance::params::api_package_name] -> Glance_api_config<||>
252   Package[$glance::params::api_package_name] -> Glance_cache_config<||>
253
254   # adding all of this stuff b/c it devstack says glance-api uses the
255   # db now
256   Glance_api_config<||>   ~> Exec<| title == 'glance-manage db_sync' |>
257   Glance_cache_config<||> ~> Exec<| title == 'glance-manage db_sync' |>
258   Exec<| title == 'glance-manage db_sync' |> ~> Service['glance-api']
259   Glance_api_config<||>   ~> Service['glance-api']
260   Glance_cache_config<||> ~> Service['glance-api']
261   Class['glance::policy'] ~> Service['glance-api']
262   Service['glance-api']   ~> Glance_image<||>
263
264   File {
265     ensure  => present,
266     owner   => 'glance',
267     group   => 'glance',
268     mode    => '0640',
269     notify  => Service['glance-api'],
270     require => Class['glance']
271   }
272
273   if $sql_connection {
274     warning('The sql_connection parameter is deprecated, use database_connection instead.')
275     $database_connection_real = $sql_connection
276   } else {
277     $database_connection_real = $database_connection
278   }
279
280   if $sql_idle_timeout {
281     warning('The sql_idle_timeout parameter is deprecated, use database_idle_timeout instead.')
282     $database_idle_timeout_real = $sql_idle_timeout
283   } else {
284     $database_idle_timeout_real = $database_idle_timeout
285   }
286
287   if $database_connection_real {
288     if($database_connection_real =~ /mysql:\/\/\S+:\S+@\S+\/\S+/) {
289       require 'mysql::bindings'
290       require 'mysql::bindings::python'
291     } elsif($database_connection_real =~ /postgresql:\/\/\S+:\S+@\S+\/\S+/) {
292
293     } elsif($database_connection_real =~ /sqlite:\/\//) {
294
295     } else {
296       fail("Invalid db connection ${database_connection_real}")
297     }
298     glance_api_config {
299       'database/connection':   value => $database_connection_real, secret => true;
300       'database/idle_timeout': value => $database_idle_timeout_real;
301     }
302   }
303
304   # basic service config
305   glance_api_config {
306     'DEFAULT/verbose':               value => $verbose;
307     'DEFAULT/debug':                 value => $debug;
308     'DEFAULT/bind_host':             value => $bind_host;
309     'DEFAULT/bind_port':             value => $bind_port;
310     'DEFAULT/backlog':               value => $backlog;
311     'DEFAULT/workers':               value => $workers;
312     'DEFAULT/show_image_direct_url': value => $show_image_direct_url;
313     'DEFAULT/image_cache_dir':       value => $image_cache_dir;
314     'DEFAULT/os_region_name':        value => $os_region_name;
315   }
316
317   # known_stores config
318   if $known_stores {
319     glance_api_config {
320       'glance_store/stores':  value => join($known_stores, ',');
321     }
322   } else {
323     glance_api_config {
324       'glance_store/stores': ensure => absent;
325     }
326   }
327
328   glance_cache_config {
329     'DEFAULT/verbose':        value => $verbose;
330     'DEFAULT/debug':          value => $debug;
331     'DEFAULT/os_region_name': value => $os_region_name;
332   }
333
334   # configure api service to connect registry service
335   glance_api_config {
336     'DEFAULT/registry_host':            value => $registry_host;
337     'DEFAULT/registry_port':            value => $registry_port;
338     'DEFAULT/registry_client_protocol': value => $registry_client_protocol;
339   }
340
341   glance_cache_config {
342     'DEFAULT/registry_host': value => $registry_host;
343     'DEFAULT/registry_port': value => $registry_port;
344   }
345
346   if $auth_uri {
347     glance_api_config { 'keystone_authtoken/auth_uri': value => $auth_uri; }
348   } else {
349     glance_api_config { 'keystone_authtoken/auth_uri': value => "${auth_protocol}://${auth_host}:5000/"; }
350   }
351
352   # auth config
353   glance_api_config {
354     'keystone_authtoken/auth_host':     value => $auth_host;
355     'keystone_authtoken/auth_port':     value => $auth_port;
356     'keystone_authtoken/auth_protocol': value => $auth_protocol;
357   }
358
359   if $auth_admin_prefix {
360     validate_re($auth_admin_prefix, '^(/.+[^/])?$')
361     glance_api_config {
362       'keystone_authtoken/auth_admin_prefix': value => $auth_admin_prefix;
363     }
364   } else {
365     glance_api_config {
366       'keystone_authtoken/auth_admin_prefix': ensure => absent;
367     }
368   }
369
370   # Set the pipeline, it is allowed to be blank
371   if $pipeline != '' {
372     validate_re($pipeline, '^(\w+([+]\w+)*)*$')
373     glance_api_config {
374       'paste_deploy/flavor':
375         ensure => present,
376         value  => $pipeline,
377     }
378   } else {
379     glance_api_config { 'paste_deploy/flavor': ensure => absent }
380   }
381
382   # keystone config
383   if $auth_type == 'keystone' {
384     glance_api_config {
385       'keystone_authtoken/admin_tenant_name': value => $keystone_tenant;
386       'keystone_authtoken/admin_user'       : value => $keystone_user;
387       'keystone_authtoken/admin_password'   : value => $keystone_password, secret => true;
388     }
389     glance_cache_config {
390       'DEFAULT/auth_url'         : value => $auth_url;
391       'DEFAULT/admin_tenant_name': value => $keystone_tenant;
392       'DEFAULT/admin_user'       : value => $keystone_user;
393       'DEFAULT/admin_password'   : value => $keystone_password, secret => true;
394     }
395   }
396
397   # SSL Options
398   if $cert_file {
399     glance_api_config {
400       'DEFAULT/cert_file' : value => $cert_file;
401     }
402   } else {
403     glance_api_config {
404       'DEFAULT/cert_file': ensure => absent;
405     }
406   }
407   if $key_file {
408     glance_api_config {
409       'DEFAULT/key_file'  : value => $key_file;
410     }
411   } else {
412     glance_api_config {
413       'DEFAULT/key_file': ensure => absent;
414     }
415   }
416   if $ca_file {
417     glance_api_config {
418       'DEFAULT/ca_file'   : value => $ca_file;
419     }
420   } else {
421     glance_api_config {
422       'DEFAULT/ca_file': ensure => absent;
423     }
424   }
425
426   # Logging
427   if $log_file {
428     glance_api_config {
429       'DEFAULT/log_file': value  => $log_file;
430     }
431   } else {
432     glance_api_config {
433       'DEFAULT/log_file': ensure => absent;
434     }
435   }
436
437   if $log_dir {
438     glance_api_config {
439       'DEFAULT/log_dir': value  => $log_dir;
440     }
441   } else {
442     glance_api_config {
443       'DEFAULT/log_dir': ensure => absent;
444     }
445   }
446
447   # Syslog
448   if $use_syslog {
449     glance_api_config {
450       'DEFAULT/use_syslog'          : value => true;
451       'DEFAULT/syslog_log_facility' : value => $log_facility;
452     }
453   } else {
454     glance_api_config {
455       'DEFAULT/use_syslog': value => false;
456     }
457   }
458
459   resources { 'glance_api_config':
460     purge => $purge_config,
461   }
462
463   file { ['/etc/glance/glance-api.conf',
464           '/etc/glance/glance-api-paste.ini',
465           '/etc/glance/glance-cache.conf']:
466   }
467
468   if $manage_service {
469     if $enabled {
470       $service_ensure = 'running'
471     } else {
472       $service_ensure = 'stopped'
473     }
474   }
475
476   service { 'glance-api':
477     ensure     => $service_ensure,
478     name       => $::glance::params::api_service_name,
479     enable     => $enabled,
480     hasstatus  => true,
481     hasrestart => true,
482   }
483
484   if $validate {
485     $defaults = {
486       'glance-api' => {
487         'command'  => "glance --os-auth-url ${auth_url} --os-tenant-name ${keystone_tenant} --os-username ${keystone_user} --os-password ${keystone_password} image-list",
488       }
489     }
490     $validation_options_hash = merge ($defaults, $validation_options)
491     create_resources('openstacklib::service_validation', $validation_options_hash, {'subscribe' => 'Service[glance-api]'})
492   }
493
494 }