File: api.pp

package info (click to toggle)
puppet-module-magnum 25.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,180 kB
  • sloc: ruby: 2,768; python: 38; makefile: 21; sh: 10
file content (172 lines) | stat: -rw-r--r-- 5,176 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# == Class: magnum::api
#
# Setup and configure the Magnum API endpoint
#
# === Parameters
#
# [*package_ensure*]
#   (Optional) Sets the ensure parameter for the package resource.
#   Defaults to 'present'
#
# [*enabled*]
#   (Optional) Define if the service should be enabled or not.
#   Defaults to true
#
# [*manage_service*]
#   (Optional) Whether the service should be managed by Puppet.
#   Defaults to true
#
# [*service_name*]
#   (Optional) Name of the service that will be providing the
#   server functionality of magnum-api.
#   If the value is 'httpd', this means magnum-api will be a web
#   service, and you must use another class to configure that
#   web service. For example, use class { 'magnum::wsgi::apache'...}
#   to make magnum-api be a web app using apache mod_wsgi.
#   Defaults to $::magnum::params::api_service
#
# [*port*]
#   (Optional) The port for the Magnum API server.
#   Defaults to '9511'
#
# [*host*]
#   (Optional) The listen IP for the Magnum API server.
#   Defaults to '127.0.0.1'
#
# [*max_limit*]
#   (Optional) The maximum number of items returned in a single response
#   from a collection resource.
#   Defaults to '1000'
#
# [*sync_db*]
#   (Optional) Enable DB sync
#   Defaults to true
#
# [*auth_strategy*]
#   (optional) Type of authentication to be used.
#   Defaults to 'keystone'
#
# [*enabled_ssl*]
#   (Optional) Whether to use ssl or not.
#   Defaults to 'false'.
#
# [*ssl_cert_file*]
#   (Optional) Location of the SSL certificate file to use for SSL mode.
#   Required when $enabled_ssl is set to 'true'.
#   Defaults to $facts['os_service_default'].
#
# [*ssl_key_file*]
#   (Optional) Location of the SSL key file to use for enabling SSL mode.
#   Required when $enabled_ssl is set to 'true'.
#   Defaults to $facts['os_service_default'].
#
# [*workers*]
#   (Optional) Number of API workers.
#   Defaults to $facts['os_workers']
#
# [*enable_proxy_headers_parsing*]
#   (optional) This determines if the HTTPProxyToWSGI
#   middleware should parse the proxy headers or not.(boolean value)
#   Defaults to $facts['os_service_default']
#
class magnum::api(
  $package_ensure               = 'present',
  Boolean $enabled              = true,
  Boolean $manage_service       = true,
  $service_name                 = $::magnum::params::api_service,
  $port                         = '9511',
  $host                         = '127.0.0.1',
  $max_limit                    = '1000',
  Boolean $sync_db              = true,
  $auth_strategy                = 'keystone',
  Boolean $enabled_ssl          = false,
  $ssl_cert_file                = $facts['os_service_default'],
  $ssl_key_file                 = $facts['os_service_default'],
  $workers                      = $facts['os_workers'],
  $enable_proxy_headers_parsing = $facts['os_service_default'],
) inherits magnum::params {

  include magnum::deps
  include magnum::params
  include magnum::policy

  if $enabled_ssl {
    if is_service_default($ssl_cert_file) {
      fail('The ssl_cert_file parameter is required when enabled_ssl is true')
    }
    if is_service_default($ssl_key_file) {
      fail('The ssl_key_file parameter is required when enabled_ssl is true')
    }
  }

  if $sync_db {
    include magnum::db::sync
  }

  # Configure API conf
  magnum_config {
    'api/port' :         value => $port;
    'api/host' :         value => $host;
    'api/max_limit' :    value => $max_limit;
    'api/enabled_ssl':   value => $enabled_ssl;
    'api/ssl_cert_file': value => $ssl_cert_file;
    'api/ssl_key_file':  value => $ssl_key_file;
    'api/workers':       value => $workers;
  }

  # Install package
  if $::magnum::params::api_package {
    package { 'magnum-api':
      ensure => $package_ensure,
      name   => $::magnum::params::api_package,
      tag    => ['openstack', 'magnum-package'],
    }
  }

  if $manage_service {
    if $enabled {
      $ensure = 'running'
    } else {
      $ensure = 'stopped'
    }

    if $service_name == $::magnum::params::api_service {
      service { 'magnum-api':
        ensure    => $ensure,
        name      => $::magnum::params::api_service,
        enable    => $enabled,
        hasstatus => true,
        tag       => 'magnum-service',
      }

      # On any paste config change, we must restart Magnum API.
      Magnum_api_paste_ini<||> ~> Service['magnum-api']

      # On any uwsgi config change, we must restart Magnum API.
      Magnum_api_uwsgi_config<||> ~> Service['magnum-api']

    } elsif $service_name == 'httpd' {
      service { 'magnum-api':
        ensure    => 'stopped',
        name      => $::magnum::params::api_service,
        enable    => false,
        hasstatus => true,
        tag       => 'magnum-service',
      }
      Service['magnum-api'] -> Service[$service_name]
      Service<| title == 'httpd' |> { tag +> 'magnum-service' }

      # On any paste config change, we must restart Magnum API.
      Magnum_api_paste_ini<||> ~> Service[$service_name]
    }
  }

  if $auth_strategy == 'keystone' {
    include magnum::keystone::authtoken
  }

  oslo::middleware {'magnum_config':
    enable_proxy_headers_parsing => $enable_proxy_headers_parsing,
  }

}