Containerize virtlogd
[apex-tripleo-heat-templates.git] / docker / services / nova-libvirt.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack Libvirt Service
5
6 parameters:
7   DockerNovaLibvirtImage:
8     description: image
9     type: string
10   # we configure libvirt via the nova-compute container due to coupling
11   # in the puppet modules
12   DockerNovaLibvirtConfigImage:
13     description: The container image to use for the nova_libvirt config_volume
14     type: string
15   ServiceData:
16     default: {}
17     description: Dictionary packing service data
18     type: json
19   ServiceNetMap:
20     default: {}
21     description: Mapping of service_name -> network name. Typically set
22                  via parameter_defaults in the resource registry.  This
23                  mapping overrides those in ServiceNetMapDefaults.
24     type: json
25   DefaultPasswords:
26     default: {}
27     type: json
28   RoleName:
29     default: ''
30     description: Role name on which the service is applied
31     type: string
32   RoleParameters:
33     default: {}
34     description: Parameters specific to the role
35     type: json
36   EndpointMap:
37     default: {}
38     description: Mapping of service endpoint -> protocol. Typically set
39                  via parameter_defaults in the resource registry.
40     type: json
41   EnableInternalTLS:
42     type: boolean
43     default: false
44   UseTLSTransportForLiveMigration:
45     type: boolean
46     default: true
47     description: If set to true and if EnableInternalTLS is enabled, it will
48                  set the libvirt URI's transport to tls and configure the
49                  relevant keys for libvirt.
50   DockerNovaMigrationSshdPort:
51     default: 2022
52     description: Port that dockerized nova migration target sshd service
53                  binds to.
54     type: number
55   NovaEnableRbdBackend:
56     default: false
57     description: Whether to enable or not the Rbd backend for Nova
58     type: boolean
59   CinderEnableRbdBackend:
60     default: false
61     description: Whether to enable or not the Rbd backend for Cinder
62     type: boolean
63   CephClientKey:
64     description: The Ceph client key. Can be created with ceph-authtool --gen-print-key. Currently only used for external Ceph deployments to create the openstack user keyring.
65     type: string
66     hidden: true
67   CephClusterFSID:
68     type: string
69     description: The Ceph cluster FSID. Must be a UUID.
70
71 conditions:
72
73   use_tls_for_live_migration:
74     and:
75     - equals:
76       - {get_param: EnableInternalTLS}
77       - true
78     - equals:
79       - {get_param: UseTLSTransportForLiveMigration}
80       - true
81
82   need_libvirt_secret:
83     or:
84     - equals:
85       - {get_param: NovaEnableRbdBackend}
86       - true
87     - equals:
88       - {get_param: CinderEnableRbdBackend}
89       - true
90
91 resources:
92
93   ContainersCommon:
94     type: ./containers-common.yaml
95
96   MySQLClient:
97     type: ../../puppet/services/database/mysql-client.yaml
98
99   NovaLibvirtBase:
100     type: ../../puppet/services/nova-libvirt.yaml
101     properties:
102       EndpointMap: {get_param: EndpointMap}
103       ServiceData: {get_param: ServiceData}
104       ServiceNetMap: {get_param: ServiceNetMap}
105       DefaultPasswords: {get_param: DefaultPasswords}
106       RoleName: {get_param: RoleName}
107       RoleParameters: {get_param: RoleParameters}
108       MigrationSshPort: {get_param: DockerNovaMigrationSshdPort}
109
110 outputs:
111   role_data:
112     description: Role data for the Libvirt service.
113     value:
114       service_name: {get_attr: [NovaLibvirtBase, role_data, service_name]}
115       config_settings:
116         get_attr: [NovaLibvirtBase, role_data, config_settings]
117       step_config: &step_config
118         list_join:
119           - "\n"
120           - - {get_attr: [NovaLibvirtBase, role_data, step_config]}
121             - {get_attr: [MySQLClient, role_data, step_config]}
122       puppet_config:
123         config_volume: nova_libvirt
124         puppet_tags: libvirtd_config,nova_config,file
125         step_config: *step_config
126         config_image: {get_param: DockerNovaLibvirtConfigImage}
127       kolla_config:
128         /var/lib/kolla/config_files/nova_libvirt.json:
129           command:
130             if:
131               - use_tls_for_live_migration
132               - /usr/sbin/libvirtd --listen --config /etc/libvirt/libvirtd.conf
133               - /usr/sbin/libvirtd --config /etc/libvirt/libvirtd.conf
134           config_files:
135             - source: "/var/lib/kolla/config_files/src/*"
136               dest: "/"
137               merge: true
138               preserve_properties: true
139             - source: "/var/lib/kolla/config_files/src-ceph/"
140               dest: "/etc/ceph/"
141               merge: true
142               preserve_properties: true
143         /var/lib/kolla/config_files/nova_virtlogd.json:
144           command: /usr/sbin/virtlogd --config /etc/libvirt/virtlogd.conf
145           config_files:
146             - source: "/var/lib/kolla/config_files/src/*"
147               dest: "/"
148               merge: true
149               preserve_properties: true
150           permissions:
151             - path: /var/log/nova
152               owner: nova:nova
153               recurse: true
154       docker_config:
155         step_3:
156           nova_virtlogd:
157             start_order: 0
158             image: {get_param: DockerNovaLibvirtImage}
159             net: host
160             pid: host
161             privileged: true
162             restart: always
163             volumes:
164               list_concat:
165                 - {get_attr: [ContainersCommon, volumes]}
166                 -
167                   - /var/lib/kolla/config_files/nova_virtlogd.json:/var/lib/kolla/config_files/config.json:ro
168                   - /var/lib/config-data/puppet-generated/nova_libvirt/:/var/lib/kolla/config_files/src:ro
169                   - /lib/modules:/lib/modules:ro
170                   - /dev:/dev
171                   - /run:/run
172                   - /sys/fs/cgroup:/sys/fs/cgroup
173                   - /var/lib/nova:/var/lib/nova
174                   - /var/run/libvirt:/var/run/libvirt
175                   - /var/lib/libvirt:/var/lib/libvirt
176                   - /etc/libvirt/qemu:/etc/libvirt/qemu:ro
177                   - /var/log/libvirt/qemu:/var/log/libvirt/qemu
178             environment:
179               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
180           nova_libvirt:
181             start_order: 1
182             image: {get_param: DockerNovaLibvirtImage}
183             net: host
184             pid: host
185             privileged: true
186             restart: always
187             volumes:
188               list_concat:
189                 - {get_attr: [ContainersCommon, volumes]}
190                 -
191                   - /var/lib/kolla/config_files/nova_libvirt.json:/var/lib/kolla/config_files/config.json:ro
192                   - /var/lib/config-data/puppet-generated/nova_libvirt/:/var/lib/kolla/config_files/src:ro
193                   - /etc/ceph:/var/lib/kolla/config_files/src-ceph:ro
194                   - /lib/modules:/lib/modules:ro
195                   - /dev:/dev
196                   - /run:/run
197                   - /sys/fs/cgroup:/sys/fs/cgroup
198                   - /var/lib/nova:/var/lib/nova
199                   - /etc/libvirt:/etc/libvirt
200                   - /var/run/libvirt:/var/run/libvirt
201                   - /var/lib/libvirt:/var/lib/libvirt
202                   - /var/log/libvirt/qemu:/var/log/libvirt/qemu:ro
203                   - /var/log/containers/nova:/var/log/nova
204             environment:
205               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
206         step_4:
207           if:
208             - need_libvirt_secret
209             - nova_libvirt_init_secret:
210                 detach: false
211                 image: {get_param: DockerNovaLibvirtImage}
212                 privileged: false
213                 user: root
214                 volumes:
215                   list_concat:
216                     - {get_attr: [ContainersCommon, volumes]}
217                     -
218                       - /var/lib/config-data/puppet-generated/nova_libvirt/etc/nova:/etc/nova:ro
219                       - /etc/libvirt:/etc/libvirt
220                       - /var/run/libvirt:/var/run/libvirt
221                       - /var/lib/libvirt:/var/lib/libvirt
222                 command:
223                   - /bin/bash
224                   - -c
225                   - str_replace:
226                       template: /usr/bin/virsh secret-define --file /etc/nova/secret.xml && /usr/bin/virsh secret-set-value --secret 'SECRET_UUID' --base64 'SECRET_KEY'
227                       params:
228                         SECRET_UUID: {get_param: CephClusterFSID}
229                         SECRET_KEY: {get_param: CephClientKey}
230             - {}
231       host_prep_tasks:
232         - name: create libvirt persistent data directories
233           file:
234             path: "{{ item }}"
235             state: directory
236           with_items:
237             - /etc/libvirt
238             - /etc/libvirt/secrets
239             - /etc/libvirt/qemu
240             - /var/lib/libvirt
241             - /var/log/containers/nova
242         - name: ensure ceph configurations exist
243           file:
244             path: /etc/ceph
245             state: directory
246       upgrade_tasks:
247         - name: Stop and disable libvirtd service
248           tags: step2
249           service: name=libvirtd state=stopped enabled=no