f262bcb1a2fe974a9a5eb81502fe13b684484bfb
[apex-tripleo-heat-templates.git] / docker / services / nova-api.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack containerized Nova API service
5
6 parameters:
7   DockerNovaApiImage:
8     description: image
9     type: string
10   DockerNovaConfigImage:
11     description: The container image to use for the nova config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   EnableInternalTLS:
40     type: boolean
41     default: false
42   UpgradeRemoveUnusedPackages:
43     default: false
44     description: Remove package if the service is being disabled during upgrade
45     type: boolean
46
47 conditions:
48
49   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
50
51 resources:
52
53   ContainersCommon:
54     type: ./containers-common.yaml
55
56   MySQLClient:
57     type: ../../puppet/services/database/mysql-client.yaml
58
59   NovaApiBase:
60     type: ../../puppet/services/nova-api.yaml
61     properties:
62       EndpointMap: {get_param: EndpointMap}
63       ServiceData: {get_param: ServiceData}
64       ServiceNetMap: {get_param: ServiceNetMap}
65       DefaultPasswords: {get_param: DefaultPasswords}
66       RoleName: {get_param: RoleName}
67       RoleParameters: {get_param: RoleParameters}
68
69 outputs:
70   role_data:
71     description: Role data for the Nova API role.
72     value:
73       service_name: {get_attr: [NovaApiBase, role_data, service_name]}
74       config_settings:
75         map_merge:
76           - get_attr: [NovaApiBase, role_data, config_settings]
77           - apache::default_vhost: false
78       logging_source: {get_attr: [NovaApiBase, role_data, logging_source]}
79       logging_groups: {get_attr: [NovaApiBase, role_data, logging_groups]}
80       step_config: &step_config
81         list_join:
82           - "\n"
83           - - "['Nova_cell_v2'].each |String $val| { noop_resource($val) }"
84             - {get_attr: [NovaApiBase, role_data, step_config]}
85             - {get_attr: [MySQLClient, role_data, step_config]}
86       service_config_settings: {get_attr: [NovaApiBase, role_data, service_config_settings]}
87       # BEGIN DOCKER SETTINGS
88       puppet_config:
89         config_volume: nova
90         puppet_tags: nova_config
91         step_config: *step_config
92         config_image: {get_param: DockerNovaConfigImage}
93       kolla_config:
94         /var/lib/kolla/config_files/nova_api.json:
95           command: /usr/sbin/httpd -DFOREGROUND
96           config_files:
97             - source: "/var/lib/kolla/config_files/src/*"
98               dest: "/"
99               merge: true
100               preserve_properties: true
101           permissions:
102             - path: /var/log/nova
103               owner: nova:nova
104               recurse: true
105         /var/lib/kolla/config_files/nova_api_cron.json:
106           command: /usr/sbin/crond -n
107           config_files:
108             - source: "/var/lib/kolla/config_files/src/*"
109               dest: "/"
110               merge: true
111               preserve_properties: true
112           permissions:
113             - path: /var/log/nova
114               owner: nova:nova
115               recurse: true
116       docker_config:
117         # db sync runs before permissions set by kolla_config
118         step_2:
119           nova_init_logs:
120             image: &nova_api_image {get_param: DockerNovaApiImage}
121             privileged: false
122             user: root
123             volumes:
124               - /var/log/containers/nova:/var/log/nova
125               - /var/log/containers/httpd/nova-api:/var/log/httpd
126             command: ['/bin/bash', '-c', 'chown -R nova:nova /var/log/nova']
127         step_3:
128           nova_api_db_sync:
129             start_order: 0
130             image: *nova_api_image
131             net: host
132             detach: false
133             user: root
134             volumes: &nova_api_bootstrap_volumes
135               list_concat:
136                 - {get_attr: [ContainersCommon, volumes]}
137                 -
138                   - /var/lib/config-data/nova/etc/my.cnf.d/tripleo.cnf:/etc/my.cnf.d/tripleo.cnf:ro
139                   - /var/lib/config-data/nova/etc/nova/:/etc/nova/:ro
140                   - /var/log/containers/nova:/var/log/nova
141                   - /var/log/containers/httpd/nova-api:/var/log/httpd
142             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage api_db sync'"
143           # FIXME: we probably want to wait on the 'cell_v2 update' in order for this
144           # to be capable of upgrading a baremetal setup. This is to ensure the name
145           # of the cell is 'default'
146           nova_api_map_cell0:
147             start_order: 1
148             image: *nova_api_image
149             net: host
150             detach: false
151             user: root
152             volumes: *nova_api_bootstrap_volumes
153             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 map_cell0'"
154           nova_api_create_default_cell:
155             start_order: 2
156             image: *nova_api_image
157             net: host
158             detach: false
159             volumes: *nova_api_bootstrap_volumes
160             # NOTE: allowing the exit code 2 is a dirty way of making
161             # this idempotent (if the resource already exists a conflict
162             # is raised)
163             exit_codes: [0,2]
164             user: root
165             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 create_cell --name=default'"
166           nova_db_sync:
167             start_order: 3
168             image: *nova_api_image
169             net: host
170             detach: false
171             volumes: *nova_api_bootstrap_volumes
172             user: root
173             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage db sync'"
174         step_4:
175           nova_api:
176             start_order: 2
177             image: *nova_api_image
178             net: host
179             user: root
180             privileged: true
181             restart: always
182             volumes:
183               list_concat:
184                 - {get_attr: [ContainersCommon, volumes]}
185                 -
186                   - /var/lib/kolla/config_files/nova_api.json:/var/lib/kolla/config_files/config.json:ro
187                   - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
188                   - /var/log/containers/nova:/var/log/nova
189                   - /var/log/containers/httpd/nova-api:/var/log/httpd
190                   -
191                     if:
192                       - internal_tls_enabled
193                       - /etc/pki/tls/certs/httpd:/etc/pki/tls/certs/httpd:ro
194                       - ''
195                   -
196                     if:
197                       - internal_tls_enabled
198                       - /etc/pki/tls/private/httpd:/etc/pki/tls/private/httpd:ro
199                       - ''
200             environment:
201               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
202           nova_api_cron:
203             image: *nova_api_image
204             net: host
205             user: root
206             privileged: false
207             restart: always
208             healthcheck:
209               test: /bin/true
210             volumes:
211               list_concat:
212                 - {get_attr: [ContainersCommon, volumes]}
213                 -
214                   - /var/lib/kolla/config_files/nova_api_cron.json:/var/lib/kolla/config_files/config.json:ro
215                   - /var/lib/config-data/puppet-generated/nova/:/var/lib/kolla/config_files/src:ro
216                   - /var/log/containers/nova:/var/log/nova
217                   - /var/log/containers/httpd/nova-api:/var/log/httpd
218             environment:
219               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
220         step_5:
221           nova_api_discover_hosts:
222             start_order: 1
223             image: *nova_api_image
224             net: host
225             detach: false
226             volumes: *nova_api_bootstrap_volumes
227             user: root
228             command: "/usr/bin/bootstrap_host_exec nova_api su nova -s /bin/bash -c '/usr/bin/nova-manage cell_v2 discover_hosts --verbose'"
229       metadata_settings:
230         get_attr: [NovaApiBase, role_data, metadata_settings]
231       host_prep_tasks:
232         - name: create persistent logs directory
233           file:
234             path: "{{ item }}"
235             state: directory
236           with_items:
237             - /var/log/containers/nova
238             - /var/log/containers/httpd/nova-api
239       upgrade_tasks:
240         - name: Stop and disable nova_api service
241           tags: step2
242           service: name=openstack-nova-api state=stopped enabled=no
243         - name: Remove openstack-nova-api package if operator requests it
244           yum: name=openstack-nova-api state=removed
245           tags: step2
246           ignore_errors: True
247           when: {get_param: UpgradeRemoveUnusedPackages}
248         - name: remove old nova cron jobs
249           file:
250             path: /var/spool/cron/nova
251             state: absent