Convert JSON generations from bash to python
[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       servers:  {get_param: servers}
72       config: {get_resource: ComputePuppetConfig}
73       input_values:
74         update_identifier: {get_param: NodeConfigIdentifiers}
75         tripleo::packages::enable_install: True
76
77   CopyEtcConfig:
78     type: OS::Heat::SoftwareConfig
79     properties:
80       group: script
81       outputs:
82       - name: result
83       config: {get_file: ./copy-etc.sh}
84
85   CopyEtcDeployment:
86     type: OS::Heat::SoftwareDeployments
87     depends_on: ComputePuppetDeployment
88     properties:
89       config: {get_resource: CopyEtcConfig}
90       servers:  {get_param: servers}
91
92   CopyJsonConfig:
93     type: OS::Heat::SoftwareConfig
94     properties:
95       group: script
96       inputs:
97       - name: libvirt_config
98       - name: nova_config
99       - name: neutron_openvswitch_agent_config
100       - name: neutron_agent_config
101       config: |
102         #!/bin/python
103         import json
104         import os
105
106         data = {}
107         file_perms = '600'
108         libvirt_perms = '644'
109
110         libvirt_config = os.getenv('libvirt_config').split(',')
111         nova_config = os.getenv('nova_config').split(',')
112         neutron_openvswitch_agent_config = os.getenv('neutron_openvswitch_agent_config').split(',')
113         neutron_agent_config = os.getenv('neutron_agent_config').split(',')
114
115         # Command, Config_files, Owner, Perms
116         services = {'nova-libvirt': ['/usr/sbin/libvirtd', libvirt_config, 'root', libvirt_perms],
117                     'nova-compute': ['/usr/bin/nova-compute', nova_config, 'nova', file_perms],
118                     'neutron-openvswitch-agent': ['/usr/bin/neutron-openvswitch-agent', neutron_openvswitch_agent_config, 'neutron', file_perms],
119                     'neutron-agent': ['/usr/bin/neutron-openvswitch-agent', neutron_agent_config, 'neutron', file_perms],
120                     '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'],
121                     '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']
122                    }
123
124
125         def build_config_files(config, owner, perms):
126             config_source = '/var/lib/kolla/config_files/'
127             config_files_dict = {}
128             source = os.path.basename(config)
129             dest = config
130             config_files_dict.update({'source': config_source + source,
131                                       'dest': dest,
132                                       'owner': owner,
133                                       'perm': perms})
134             return config_files_dict
135
136
137         for service in services:
138             if service != 'ovs-vswitchd' and service != 'ovsdb-server':
139                 command = services.get(service)[0]
140                 config_files = services.get(service)[1]
141                 owner = services.get(service)[2]
142                 perms = services.get(service)[3]
143                 config_files_list = []
144                 for config_file in config_files:
145                     if service == 'nova-libvirt':
146                         command = command + ' --config ' + config_file
147                     else:
148                         command = command + ' --config-file ' + config_file
149                     data['command'] = command
150                     config_files_dict = build_config_files(config_file, owner, perms)
151                     config_files_list.append(config_files_dict)
152                 data['config_files'] = config_files_list
153             else:
154                 data['command'] = services.get(service)[0]
155                 data['config_files'] = []
156
157             json_config_dir = '/var/lib/etc-data/json-config/'
158             with open(json_config_dir + service + '.json', 'w') as json_file:
159                 json.dump(data, json_file, sort_keys=True, indent=4, separators=(',', ': '))
160
161   CopyJsonDeployment:
162     type: OS::Heat::SoftwareDeployments
163     depends_on: CopyEtcDeployment
164     properties:
165       config: {get_resource: CopyJsonConfig}
166       servers:  {get_param: servers}
167       input_values:
168         libvirt_config: {get_param: LibvirtConfig}
169         nova_config: {get_param: NovaConfig}
170         neutron_openvswitch_agent_config: {get_param: NeutronOpenvswitchAgentConfig}
171         neutron_agent_config: {get_param: NeutronAgentConfig}
172
173   NovaComputeContainersDeploymentOVS:
174     type: OS::Heat::StructuredDeployments
175     depends_on: CopyJsonDeployment
176     properties:
177       config: {get_resource: NovaComputeContainersConfigOVS}
178       servers: {get_param: servers}
179
180   NovaComputeContainersConfigOVS:
181     type: OS::Heat::StructuredConfig
182     properties:
183       group: docker-compose
184       config:
185         ovsvswitchd:
186           image:
187             list_join:
188             - '/'
189             - [ {get_param: DockerNamespace}, {get_param: DockerOvsVswitchdImage} ]
190           container_name: ovs-vswitchd
191           net: host
192           privileged: true
193           restart: always
194           volumes:
195            - /run:/run
196            - /lib/modules:/lib/modules:ro
197            - /var/lib/etc-data/json-config/ovs-vswitchd.json:/var/lib/kolla/config_files/config.json
198           environment:
199            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
200
201         openvswitchdb:
202           image:
203             list_join:
204             - '/'
205             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchDBImage} ]
206           container_name: ovsdb-server
207           net: host
208           restart: always
209           volumes:
210            - /run:/run
211            - /var/lib/etc-data/json-config/ovsdb-server.json:/var/lib/kolla/config_files/config.json
212           environment:
213            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
214
215   NovaComputeContainersDeploymentNetconfig:
216     type: OS::Heat::SoftwareDeployments
217     depends_on: NovaComputeContainersDeploymentOVS
218     properties:
219       config: {get_resource: NovaComputeContainersConfigNetconfig}
220       servers: {get_param: servers}
221
222   # We run os-net-config here because we depend on the ovs containers to be up
223   # and running before we configure the network.  This allows explicit timing
224   # of the network configuration.
225   NovaComputeContainersConfigNetconfig:
226     type: OS::Heat::SoftwareConfig
227     properties:
228       group: script
229       outputs:
230       - name: result
231       config: |
232         #!/bin/bash
233         /usr/local/bin/run-os-net-config
234
235   LibvirtContainersDeployment:
236     type: OS::Heat::StructuredDeployments
237     depends_on: [CopyJsonDeployment, CopyEtcDeployment, ComputePuppetDeployment, NovaComputeContainersDeploymentNetconfig]
238     properties:
239       config: {get_resource: LibvirtContainersConfig}
240       servers: {get_param: servers}
241
242   LibvirtContainersConfig:
243     type: OS::Heat::StructuredConfig
244     properties:
245       group: docker-compose
246       config:
247         computedata:
248           image:
249             list_join:
250             - '/'
251             - [ {get_param: DockerNamespace}, {get_param: DockerComputeDataImage} ]
252           container_name: computedata
253           volumes:
254            - /var/lib/nova/instances
255            - /var/lib/libvirt
256
257         libvirt:
258           image:
259             list_join:
260             - '/'
261             - [ {get_param: DockerNamespace}, {get_param: DockerLibvirtImage} ]
262           container_name: libvirt
263           net: host
264           pid: host
265           privileged: true
266           restart: always
267           volumes:
268            - /run:/run
269            - /lib/modules:/lib/modules:ro
270            - /sys/fs/cgroup:/sys/fs/cgroup
271            - /var/lib/etc-data/json-config/nova-libvirt.json:/var/lib/kolla/config_files/config.json
272            - /var/lib/etc-data/libvirt/libvirtd.conf:/var/lib/kolla/config_files/libvirtd.conf
273           environment:
274            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
275           volumes_from:
276            - computedata
277
278   NovaComputeContainersDeployment:
279     type: OS::Heat::StructuredDeployments
280     depends_on: [CopyJsonDeployment, CopyEtcDeployment, ComputePuppetDeployment, NovaComputeContainersDeploymentNetconfig, LibvirtContainersDeployment]
281     properties:
282       config: {get_resource: NovaComputeContainersConfig}
283       servers: {get_param: servers}
284
285   NovaComputeContainersConfig:
286     type: OS::Heat::StructuredConfig
287     properties:
288       group: docker-compose
289       config:
290         openvswitch:
291           image:
292             list_join:
293             - '/'
294             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchImage} ]
295           container_name: openvswitch
296           net: host
297           privileged: true
298           restart: always
299           volumes:
300            - /run:/run
301            - /lib/modules:/lib/modules:ro
302            - /var/lib/etc-data/json-config/neutron-openvswitch-agent.json:/var/lib/kolla/config_files/config.json
303            - /var/lib/etc-data/neutron/neutron.conf:/etc/kolla/neutron-openvswitch-agent/:ro
304            - /var/lib/etc-data/neutron/plugins/ml2/ml2_conf.ini:/var/lib/kolla/config_files/ml2_conf.ini:ro
305            - /var/lib/etc-data/neutron/neutron.conf:/var/lib/kolla/config_files/neutron.conf:ro
306           environment:
307            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
308           volumes_from:
309            - computedata
310
311         neutronagent:
312           image:
313             list_join:
314             - '/'
315             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchImage} ]
316           container_name: neutronagent
317           net: host
318           pid: host
319           privileged: true
320           restart: always
321           volumes:
322             str_split:
323               - ","
324               - list_join:
325                  - ","
326                  - [ "/run:/run", "/lib/modules:/lib/modules:ro",
327                      "/var/lib/etc-data/json-config/neutron-agent.json:/var/lib/kolla/config_files/config.json",
328                      "/var/lib/etc-data/neutron/neutron.conf:/var/lib/kolla/config_files/neutron.conf:ro",
329                      {get_param: NeutronAgentPluginVolume},
330                      {get_param: NeutronAgentOvsVolume} ]
331           environment:
332            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
333           volumes_from:
334            - computedata
335
336         novacompute:
337           image:
338             list_join:
339             - '/'
340             - [ {get_param: DockerNamespace}, {get_param: DockerComputeImage} ]
341           container_name: novacompute
342           net: host
343           privileged: true
344           restart: always
345           volumes:
346            - /run:/run
347            - /lib/modules:/lib/modules:ro
348            - /var/lib/etc-data/json-config/nova-compute.json:/var/lib/kolla/config_files/config.json
349            - /var/lib/etc-data/nova/nova.conf:/var/lib/kolla/config_files/nova.conf:ro
350           environment:
351            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
352           volumes_from:
353            - computedata
354
355   ExtraConfig:
356     depends_on: NovaComputeContainersDeployment
357     type: OS::TripleO::NodeExtraConfigPost
358     properties:
359         servers: {get_param: servers}