Merge "Fix neutron-nova notifications"
[apex-tripleo-heat-templates.git] / docker / compute-post.yaml
1 heat_template_version: 2015-10-15
2 description: >
3   OpenStack compute node post deployment for Docker.
4
5 parameters:
6   servers:
7     type: json
8   NodeConfigIdentifiers:
9      type: json
10      description: Value which changes if the node configuration may need to be re-applied
11   DockerNamespace:
12     type: string
13     default: tripleoupstream
14   DockerComputeImage:
15     type: string
16   DockerComputeDataImage:
17     type: string
18   DockerLibvirtImage:
19     type: string
20   DockerNeutronAgentImage:
21     type: string
22   DockerOpenvswitchImage:
23     type: string
24   DockerOvsVswitchdImage:
25     type: string
26   DockerOpenvswitchDBImage:
27     type: string
28   LibvirtConfig:
29     type: string
30     default: "/etc/libvirt/libvirtd.conf"
31   NovaConfig:
32     type: string
33     default: "/etc/nova/nova.conf"
34   NeutronOpenvswitchAgentConfig:
35     type: string
36     default: "/etc/neutron/neutron.conf,/etc/neutron/plugins/ml2/ml2_conf.ini"
37   NeutronAgentConfig:
38     type: string
39     default: "/etc/neutron/neutron.conf,/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini"
40   NeutronAgentPluginVolume:
41     type: string
42     description: The neutron agent plugin to mount into the neutron-agents container
43     default: "/var/lib/etc-data/neutron/plugins/ml2/openvswitch_agent.ini:/var/lib/kolla/config_files/ovs_neutron_plugin.ini:ro"
44   NeutronAgentOvsVolume:
45     type: string
46     description: The neutron agent ovs agents to mount into the neutron-agents container
47     default: " "
48
49 resources:
50
51   ComputePuppetConfig:
52     type: OS::Heat::SoftwareConfig
53     properties:
54       group: puppet
55       options:
56         enable_hiera: True
57         enable_facter: False
58         tags: package,file,concat,file_line,nova_config,neutron_config,neutron_agent_ovs,neutron_plugin_ml2
59       inputs:
60       - name: tripleo::packages::enable_install
61         type: Boolean
62         default: True
63       outputs:
64       - name: result
65       config:
66         get_file: ../puppet/manifests/overcloud_compute.pp
67
68   ComputePuppetDeployment:
69     type: OS::Heat::SoftwareDeployments
70     properties:
71       name: ComputePuppetDeployment
72       servers:  {get_param: servers}
73       config: {get_resource: ComputePuppetConfig}
74       input_values:
75         update_identifier: {get_param: NodeConfigIdentifiers}
76         tripleo::packages::enable_install: True
77
78   CopyEtcConfig:
79     type: OS::Heat::SoftwareConfig
80     properties:
81       group: script
82       outputs:
83       - name: result
84       config: {get_file: ./copy-etc.sh}
85
86   CopyEtcDeployment:
87     type: OS::Heat::SoftwareDeployments
88     depends_on: ComputePuppetDeployment
89     properties:
90       name: CopyEtcDeployment
91       config: {get_resource: CopyEtcConfig}
92       servers:  {get_param: servers}
93
94   CopyJsonConfig:
95     type: OS::Heat::SoftwareConfig
96     properties:
97       group: script
98       inputs:
99       - name: libvirt_config
100       - name: nova_config
101       - name: neutron_openvswitch_agent_config
102       - name: neutron_agent_config
103       config: |
104         #!/bin/python
105         import json
106         import os
107
108         data = {}
109         file_perms = '600'
110         libvirt_perms = '644'
111
112         libvirt_config = os.getenv('libvirt_config').split(',')
113         nova_config = os.getenv('nova_config').split(',')
114         neutron_openvswitch_agent_config = os.getenv('neutron_openvswitch_agent_config').split(',')
115         neutron_agent_config = os.getenv('neutron_agent_config').split(',')
116
117         # Command, Config_files, Owner, Perms
118         services = {'nova-libvirt': ['/usr/sbin/libvirtd', libvirt_config, 'root', libvirt_perms],
119                     'nova-compute': ['/usr/bin/nova-compute', nova_config, 'nova', file_perms],
120                     'neutron-openvswitch-agent': ['/usr/bin/neutron-openvswitch-agent', neutron_openvswitch_agent_config, 'neutron', file_perms],
121                     'neutron-agent': ['/usr/bin/neutron-openvswitch-agent', neutron_agent_config, 'neutron', file_perms],
122                     'ovs-vswitchd': ['/usr/sbin/ovs-vswitchd unix:/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --log-file=/var/log/openvswitch/ovs-vswitchd.log'],
123                     'ovsdb-server': ['/usr/sbin/ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/run/openvswitch/db.sock --log-file=/var/log/openvswitch/ovsdb-server.log']
124                    }
125
126
127         def build_config_files(config, owner, perms):
128             config_source = '/var/lib/kolla/config_files/'
129             config_files_dict = {}
130             source = os.path.basename(config)
131             dest = config
132             config_files_dict.update({'source': config_source + source,
133                                       'dest': dest,
134                                       'owner': owner,
135                                       'perm': perms})
136             return config_files_dict
137
138
139         for service in services:
140             if service != 'ovs-vswitchd' and service != 'ovsdb-server':
141                 command = services.get(service)[0]
142                 config_files = services.get(service)[1]
143                 owner = services.get(service)[2]
144                 perms = services.get(service)[3]
145                 config_files_list = []
146                 for config_file in config_files:
147                     if service == 'nova-libvirt':
148                         command = command + ' --config ' + config_file
149                     else:
150                         command = command + ' --config-file ' + config_file
151                     data['command'] = command
152                     config_files_dict = build_config_files(config_file, owner, perms)
153                     config_files_list.append(config_files_dict)
154                 data['config_files'] = config_files_list
155             else:
156                 data['command'] = services.get(service)[0]
157                 data['config_files'] = []
158
159             json_config_dir = '/var/lib/etc-data/json-config/'
160             with open(json_config_dir + service + '.json', 'w') as json_file:
161                 json.dump(data, json_file, sort_keys=True, indent=4, separators=(',', ': '))
162
163   CopyJsonDeployment:
164     type: OS::Heat::SoftwareDeployments
165     depends_on: CopyEtcDeployment
166     properties:
167       name: CopyJsonDeployment
168       config: {get_resource: CopyJsonConfig}
169       servers:  {get_param: servers}
170       input_values:
171         libvirt_config: {get_param: LibvirtConfig}
172         nova_config: {get_param: NovaConfig}
173         neutron_openvswitch_agent_config: {get_param: NeutronOpenvswitchAgentConfig}
174         neutron_agent_config: {get_param: NeutronAgentConfig}
175
176   NovaComputeContainersDeploymentOVS:
177     type: OS::Heat::StructuredDeployments
178     depends_on: CopyJsonDeployment
179     properties:
180       name: NovaComputeContainersDeploymentOVS
181       config: {get_resource: NovaComputeContainersConfigOVS}
182       servers: {get_param: servers}
183
184   NovaComputeContainersConfigOVS:
185     type: OS::Heat::StructuredConfig
186     properties:
187       group: docker-compose
188       config:
189         ovsvswitchd:
190           image:
191             list_join:
192             - '/'
193             - [ {get_param: DockerNamespace}, {get_param: DockerOvsVswitchdImage} ]
194           container_name: ovs-vswitchd
195           net: host
196           privileged: true
197           restart: always
198           volumes:
199            - /run:/run
200            - /lib/modules:/lib/modules:ro
201            - /var/lib/etc-data/json-config/ovs-vswitchd.json:/var/lib/kolla/config_files/config.json
202           environment:
203            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
204
205         openvswitchdb:
206           image:
207             list_join:
208             - '/'
209             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchDBImage} ]
210           container_name: ovsdb-server
211           net: host
212           restart: always
213           volumes:
214            - /run:/run
215            - /var/lib/etc-data/json-config/ovsdb-server.json:/var/lib/kolla/config_files/config.json
216           environment:
217            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
218
219   NovaComputeContainersDeploymentNetconfig:
220     type: OS::Heat::SoftwareDeployments
221     depends_on: NovaComputeContainersDeploymentOVS
222     properties:
223       name: NovaComputeContainersDeploymentNetconfig
224       config: {get_resource: NovaComputeContainersConfigNetconfig}
225       servers: {get_param: servers}
226
227   # We run os-net-config here because we depend on the ovs containers to be up
228   # and running before we configure the network.  This allows explicit timing
229   # of the network configuration.
230   NovaComputeContainersConfigNetconfig:
231     type: OS::Heat::SoftwareConfig
232     properties:
233       group: script
234       outputs:
235       - name: result
236       config: |
237         #!/bin/bash
238         /usr/local/bin/run-os-net-config
239
240   LibvirtContainersDeployment:
241     type: OS::Heat::StructuredDeployments
242     depends_on: [CopyJsonDeployment, CopyEtcDeployment, ComputePuppetDeployment, NovaComputeContainersDeploymentNetconfig]
243     properties:
244       name: LibvirtContainersDeployment
245       config: {get_resource: LibvirtContainersConfig}
246       servers: {get_param: servers}
247
248   LibvirtContainersConfig:
249     type: OS::Heat::StructuredConfig
250     properties:
251       group: docker-compose
252       config:
253         computedata:
254           image:
255             list_join:
256             - '/'
257             - [ {get_param: DockerNamespace}, {get_param: DockerComputeDataImage} ]
258           container_name: computedata
259           volumes:
260            - /var/lib/nova/instances
261            - /var/lib/libvirt
262
263         libvirt:
264           image:
265             list_join:
266             - '/'
267             - [ {get_param: DockerNamespace}, {get_param: DockerLibvirtImage} ]
268           container_name: libvirt
269           net: host
270           pid: host
271           privileged: true
272           restart: always
273           volumes:
274            - /run:/run
275            - /lib/modules:/lib/modules:ro
276            - /sys/fs/cgroup:/sys/fs/cgroup
277            - /var/lib/etc-data/json-config/nova-libvirt.json:/var/lib/kolla/config_files/config.json
278            - /var/lib/etc-data/libvirt/libvirtd.conf:/var/lib/kolla/config_files/libvirtd.conf
279           environment:
280            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
281           volumes_from:
282            - computedata
283
284   NovaComputeContainersDeployment:
285     type: OS::Heat::StructuredDeployments
286     depends_on: [CopyJsonDeployment, CopyEtcDeployment, ComputePuppetDeployment, NovaComputeContainersDeploymentNetconfig, LibvirtContainersDeployment]
287     properties:
288       name: NovaComputeContainersDeployment
289       config: {get_resource: NovaComputeContainersConfig}
290       servers: {get_param: servers}
291
292   NovaComputeContainersConfig:
293     type: OS::Heat::StructuredConfig
294     properties:
295       group: docker-compose
296       config:
297         openvswitch:
298           image:
299             list_join:
300             - '/'
301             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchImage} ]
302           container_name: openvswitch
303           net: host
304           privileged: true
305           restart: always
306           volumes:
307            - /run:/run
308            - /lib/modules:/lib/modules:ro
309            - /var/lib/etc-data/json-config/neutron-openvswitch-agent.json:/var/lib/kolla/config_files/config.json
310            - /var/lib/etc-data/neutron/neutron.conf:/etc/kolla/neutron-openvswitch-agent/:ro
311            - /var/lib/etc-data/neutron/plugins/ml2/ml2_conf.ini:/var/lib/kolla/config_files/ml2_conf.ini:ro
312            - /var/lib/etc-data/neutron/neutron.conf:/var/lib/kolla/config_files/neutron.conf:ro
313           environment:
314            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
315           volumes_from:
316            - computedata
317
318         neutronagent:
319           image:
320             list_join:
321             - '/'
322             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchImage} ]
323           container_name: neutronagent
324           net: host
325           pid: host
326           privileged: true
327           restart: always
328           volumes:
329             str_split:
330               - ","
331               - list_join:
332                  - ","
333                  - [ "/run:/run", "/lib/modules:/lib/modules:ro",
334                      "/var/lib/etc-data/json-config/neutron-agent.json:/var/lib/kolla/config_files/config.json",
335                      "/var/lib/etc-data/neutron/neutron.conf:/var/lib/kolla/config_files/neutron.conf:ro",
336                      {get_param: NeutronAgentPluginVolume},
337                      {get_param: NeutronAgentOvsVolume} ]
338           environment:
339            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
340           volumes_from:
341            - computedata
342
343         novacompute:
344           image:
345             list_join:
346             - '/'
347             - [ {get_param: DockerNamespace}, {get_param: DockerComputeImage} ]
348           container_name: novacompute
349           net: host
350           privileged: true
351           restart: always
352           volumes:
353            - /run:/run
354            - /lib/modules:/lib/modules:ro
355            - /var/lib/etc-data/json-config/nova-compute.json:/var/lib/kolla/config_files/config.json
356            - /var/lib/etc-data/nova/nova.conf:/var/lib/kolla/config_files/nova.conf:ro
357           environment:
358            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
359           volumes_from:
360            - computedata
361
362   ExtraConfig:
363     depends_on: NovaComputeContainersDeployment
364     type: OS::TripleO::NodeExtraConfigPost
365     properties:
366         servers: {get_param: servers}