Merge "Composable Mistral services"
[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   DeployIdentifier:
9      type: string
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   DockerOpenvswitchImage:
21     type: string
22   DockerOvsVswitchdImage:
23     type: string
24   DockerOpenvswitchDBImage:
25     type: string
26   LibvirtConfig:
27     type: string
28     default: "/etc/libvirt/libvirtd.conf"
29   NovaConfig:
30     type: string
31     default: "/etc/nova/nova.conf,/etc/nova/rootwrap.conf"
32   NeutronOpenvswitchAgentConfig:
33     type: string
34     default: "/etc/neutron/neutron.conf,/etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini"
35   NeutronOpenvswitchAgentPluginVolume:
36     type: string
37     default: "/var/lib/etc-data/neutron/plugins/ml2/openvswitch_agent.ini:/var/lib/kolla/config_files/ovs_neutron_plugin.ini:ro"
38   NeutronOpenvswitchAgentOvsVolume:
39     type: string
40     default: " "
41   StepConfig:
42     type: string
43     description: Config manifests that will be used to step through the deployment.
44     default: ''
45   RoleData:
46     type: json
47     default: {}
48
49
50 resources:
51
52   ComputePuppetConfig:
53     type: OS::Heat::SoftwareConfig
54     properties:
55       group: puppet
56       options:
57         enable_hiera: True
58         enable_facter: False
59         tags: package,file,concat,file_line,nova_config,neutron_config,neutron_agent_ovs,neutron_plugin_ml2
60       inputs:
61       - name: tripleo::packages::enable_install
62         type: Boolean
63         default: True
64       outputs:
65       - name: result
66       config:
67         list_join:
68         - ''
69         - - get_file: ../puppet/manifests/overcloud_compute.pp
70           - {get_param: StepConfig}
71
72
73   ComputePuppetDeployment:
74     type: OS::Heat::SoftwareDeployments
75     properties:
76       name: ComputePuppetDeployment
77       servers:  {get_param: servers}
78       config: {get_resource: ComputePuppetConfig}
79       input_values:
80         update_identifier: {get_param: DeployIdentifier}
81         tripleo::packages::enable_install: True
82
83   CopyEtcConfig:
84     type: OS::Heat::SoftwareConfig
85     properties:
86       group: script
87       outputs:
88       - name: result
89       config: {get_file: ./copy-etc.sh}
90
91   CopyEtcDeployment:
92     type: OS::Heat::SoftwareDeployments
93     depends_on: ComputePuppetDeployment
94     properties:
95       name: CopyEtcDeployment
96       config: {get_resource: CopyEtcConfig}
97       servers:  {get_param: servers}
98
99   CopyJsonConfig:
100     type: OS::Heat::SoftwareConfig
101     properties:
102       group: script
103       inputs:
104       - name: libvirt_config
105       - name: nova_config
106       - name: neutron_openvswitch_agent_config
107       config: |
108         #!/bin/python
109         import json
110         import os
111
112         data = {}
113         file_perms = '600'
114         libvirt_perms = '644'
115
116         libvirt_config = os.getenv('libvirt_config').split(',')
117         nova_config = os.getenv('nova_config').split(',')
118         neutron_openvswitch_agent_config = os.getenv('neutron_openvswitch_agent_config').split(',')
119
120         # Command, Config_files, Owner, Perms
121         services = {'nova-libvirt': ['/usr/sbin/libvirtd', libvirt_config, 'root', libvirt_perms],
122                     'nova-compute': ['/usr/bin/nova-compute', nova_config, 'nova', file_perms],
123                     'neutron-openvswitch-agent': ['/usr/bin/neutron-openvswitch-agent', neutron_openvswitch_agent_config, 'neutron', file_perms],
124                     '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'],
125                     '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']
126                    }
127
128
129         def build_config_files(config, owner, perms):
130             config_source = '/var/lib/kolla/config_files/'
131             config_files_dict = {}
132             source = os.path.basename(config)
133             dest = config
134             config_files_dict.update({'source': config_source + source,
135                                       'dest': dest,
136                                       'owner': owner,
137                                       'perm': perms})
138             return config_files_dict
139
140
141         for service in services:
142             if service != 'ovs-vswitchd' and service != 'ovsdb-server':
143                 command = services.get(service)[0]
144                 config_files = services.get(service)[1]
145                 owner = services.get(service)[2]
146                 perms = services.get(service)[3]
147                 config_files_list = []
148                 for config_file in config_files:
149                     if service == 'nova-libvirt':
150                         command = command + ' --config ' + config_file
151                     else:
152                         command = command + ' --config-file ' + config_file
153                     data['command'] = command
154                     config_files_dict = build_config_files(config_file, owner, perms)
155                     config_files_list.append(config_files_dict)
156                 data['config_files'] = config_files_list
157             else:
158                 data['command'] = services.get(service)[0]
159                 data['config_files'] = []
160
161             json_config_dir = '/var/lib/etc-data/json-config/'
162             with open(json_config_dir + service + '.json', 'w') as json_file:
163                 json.dump(data, json_file, sort_keys=True, indent=4, separators=(',', ': '))
164
165   CopyJsonDeployment:
166     type: OS::Heat::SoftwareDeployments
167     depends_on: CopyEtcDeployment
168     properties:
169       name: CopyJsonDeployment
170       config: {get_resource: CopyJsonConfig}
171       servers:  {get_param: servers}
172       input_values:
173         libvirt_config: {get_param: LibvirtConfig}
174         nova_config: {get_param: NovaConfig}
175         neutron_openvswitch_agent_config: {get_param: NeutronOpenvswitchAgentConfig}
176
177   NovaComputeContainersDeploymentOVS:
178     type: OS::Heat::StructuredDeployments
179     depends_on: CopyJsonDeployment
180     properties:
181       name: NovaComputeContainersDeploymentOVS
182       config: {get_resource: NovaComputeContainersConfigOVS}
183       servers: {get_param: servers}
184
185   NovaComputeContainersConfigOVS:
186     type: OS::Heat::StructuredConfig
187     properties:
188       group: docker-cmd
189       config:
190         ovsvswitchd:
191           image:
192             list_join:
193             - '/'
194             - [ {get_param: DockerNamespace}, {get_param: DockerOvsVswitchdImage} ]
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           net: host
211           restart: always
212           volumes:
213            - /run:/run
214            - /var/lib/etc-data/json-config/ovsdb-server.json:/var/lib/kolla/config_files/config.json
215            - /etc/openvswitchd:/etc/openvswitchd
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-cmd
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           net: host
269           pid: host
270           privileged: true
271           restart: always
272           volumes:
273            - /run:/run
274            - /lib/modules:/lib/modules:ro
275            - /dev:/dev
276            - /lib/udev:/lib/udev
277            - /sys/fs/cgroup:/sys/fs/cgroup
278            - /var/lib/etc-data/json-config/nova-libvirt.json:/var/lib/kolla/config_files/config.json
279            - /var/lib/etc-data/libvirt/libvirtd.conf:/var/lib/kolla/config_files/libvirtd.conf
280           environment:
281            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
282           volumes_from:
283            - computedata
284
285   NovaComputeContainersDeployment:
286     type: OS::Heat::StructuredDeployments
287     depends_on: [CopyJsonDeployment, CopyEtcDeployment, ComputePuppetDeployment, NovaComputeContainersDeploymentNetconfig, LibvirtContainersDeployment]
288     properties:
289       name: NovaComputeContainersDeployment
290       config: {get_resource: NovaComputeContainersConfig}
291       servers: {get_param: servers}
292
293   NovaComputeContainersConfig:
294     type: OS::Heat::StructuredConfig
295     properties:
296       group: docker-cmd
297       config:
298         neutronovsagent:
299           image:
300             list_join:
301             - '/'
302             - [ {get_param: DockerNamespace}, {get_param: DockerOpenvswitchImage} ]
303           net: host
304           pid: host
305           privileged: true
306           restart: always
307           volumes:
308             str_split:
309               - ","
310               - list_join:
311                  - ","
312                  - [ "/run:/run", "/lib/modules:/lib/modules:ro",
313                      "/var/lib/etc-data/json-config/neutron-openvswitch-agent.json:/var/lib/kolla/config_files/config.json",
314                      "/var/lib/etc-data/neutron/neutron.conf:/var/lib/kolla/config_files/neutron.conf:ro",
315                      "/var/lib/etc-data/neutron/plugins/ml2/ml2_conf.ini:/var/lib/kolla/config_files/ml2_conf.ini:ro",
316                      {get_param: NeutronOpenvswitchAgentPluginVolume},
317                      {get_param: NeutronOpenvswitchAgentOvsVolume} ]
318           environment:
319            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
320           volumes_from:
321            - computedata
322
323         novacompute:
324           image:
325             list_join:
326             - '/'
327             - [ {get_param: DockerNamespace}, {get_param: DockerComputeImage} ]
328           net: host
329           privileged: true
330           restart: always
331           volumes:
332            - /run:/run
333            - /lib/modules:/lib/modules:ro
334            - /dev:/dev
335            - /lib/udev:/lib/udev
336            - /etc/iscsi:/etc/iscsi
337            - /var/lib/etc-data/json-config/nova-compute.json:/var/lib/kolla/config_files/config.json
338            - /var/lib/etc-data/nova/nova.conf:/var/lib/kolla/config_files/nova.conf:ro
339            - /var/lib/etc-data/nova/rootwrap.conf:/var/lib/kolla/config_files/rootwrap.conf:ro
340           environment:
341            - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
342           volumes_from:
343            - computedata
344
345   ExtraConfig:
346     depends_on: NovaComputeContainersDeployment
347     type: OS::TripleO::NodeExtraConfigPost
348     properties:
349         servers: {get_param: servers}