blob: d24d79bd518c70dae41aef20225f12b2499aed65 [file] [log] [blame]
Jakub Josef79ecec32017-02-17 14:36:28 +01001package com.mirantis.mk
2/**
3 * Orchestration functions
4 *
5*/
6
7def validateFoundationInfra(master) {
8 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +02009
10 salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['salt-key'], null, true)
11 salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version', [], null, true)
12 salt.runSaltProcessStep(master, 'I@salt:master', 'cmd.run', ['reclass-salt --top'], null, true)
13 salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory', [], null, true)
14 salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top', [], null, true)
Jakub Josef79ecec32017-02-17 14:36:28 +010015}
16
Jakub Josef79ecec32017-02-17 14:36:28 +010017def installFoundationInfra(master) {
18 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020019
Vasyl Saienkoe36ab7c2017-07-17 14:35:48 +030020 salt.enforceState(master, 'I@salt:master', ['salt.master', 'reclass'], true, false, null, false, 60, 2)
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020021
22 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
23 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
24
25 salt.enforceState(master, 'I@salt:master', ['linux.system'], true)
Vasyl Saienkoe36ab7c2017-07-17 14:35:48 +030026 salt.enforceState(master, 'I@salt:master', ['salt.minion'], true, false, null, false, 60, 2)
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020027 salt.enforceState(master, 'I@salt:master', ['salt.minion'], true)
28
Jakub Josef200550f2017-05-16 17:39:55 +020029 salt.enforceState(master, '*', ['linux.system'], true)
Vasyl Saienkoe36ab7c2017-07-17 14:35:48 +030030 salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp'], true)
Tomáš Kukrál7e767f92017-08-18 14:53:17 +020031 salt.enforceState(master, '*', ['salt.minion'], true, false, null, false, 60, 2)
Jakub Josef79ecec32017-02-17 14:36:28 +010032}
33
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010034def installInfraKvm(master) {
35 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010036
Ales Komarekef2bab62017-04-26 11:48:28 +020037 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
38 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all', [], null, true)
39
Richard Felkl286f25f2017-07-26 14:23:55 +020040 salt.enforceState(master, 'I@salt:control', ['salt.minion'], true, false, null, false, 60, 2)
Vasyl Saienkoe36ab7c2017-07-17 14:35:48 +030041 salt.enforceState(master, 'I@salt:control', ['linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010042 salt.enforceState(master, 'I@salt:control', 'libvirt', true)
43 salt.enforceState(master, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010044
Ales Komarekef2bab62017-04-26 11:48:28 +020045 sleep(600)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010046
Marek Celoudc9b3cc82017-05-22 12:50:53 +000047 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
48 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010049}
Jakub Josef79ecec32017-02-17 14:36:28 +010050
vrovachev1c4770b2017-07-05 13:25:21 +040051def installInfra(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +010052 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020053
Jakub Josef79ecec32017-02-17 14:36:28 +010054 // Install glusterfs
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020055 if (salt.testTarget(master, 'I@glusterfs:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +040056 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010057
vrovachev1c4770b2017-07-05 13:25:21 +040058 withEnv(['ASK_ON_ERROR=false']){
59 retry(5) {
60 salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
61 }
Alexander Noskov93acac42017-06-20 17:55:55 +020062 }
vrovachev1c4770b2017-07-05 13:25:21 +040063
64 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
65 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Alexander Noskov93acac42017-06-20 17:55:55 +020066 }
Ales Komarekef2bab62017-04-26 11:48:28 +020067
Jakub Josef79ecec32017-02-17 14:36:28 +010068 // Install galera
Richard Felklc0f163e2017-07-27 15:11:12 +020069 if (salt.testTarget(master, 'I@galera:master') || salt.testTarget(master, 'I@galera:slave')) {
vrovachev1c4770b2017-07-05 13:25:21 +040070 withEnv(['ASK_ON_ERROR=false']){
71 retry(2) {
72 salt.enforceState(master, 'I@galera:master', 'galera', true)
73 }
Ales Komarekef2bab62017-04-26 11:48:28 +020074 }
vrovachev1c4770b2017-07-05 13:25:21 +040075 salt.enforceState(master, 'I@galera:slave', 'galera', true)
76
77 // Check galera status
78 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
79 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +030080 // If galera is not enabled check if we need to install mysql:server
81 } else if (salt.testTarget(master, 'I@mysql:server')){
82 salt.enforceState(master, 'I@mysql:server', 'mysql.server', true)
83 if (salt.testTarget(master, 'I@mysql:client')){
84 salt.enforceState(master, 'I@mysql:client', 'mysql.client', true)
85 }
Ales Komarekef2bab62017-04-26 11:48:28 +020086 }
Ales Komarekef2bab62017-04-26 11:48:28 +020087
vrovachev1c4770b2017-07-05 13:25:21 +040088 // Install docker
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020089 if (salt.testTarget(master, 'I@docker:host')) {
vrovachev1c4770b2017-07-05 13:25:21 +040090 salt.enforceState(master, 'I@docker:host', 'docker.host')
91 salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
92 }
Ales Komarekef2bab62017-04-26 11:48:28 +020093
vrovachev1c4770b2017-07-05 13:25:21 +040094 // Install keepalived
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020095 if (salt.testTarget(master, 'I@keepalived:cluster')) {
vrovachev1c4770b2017-07-05 13:25:21 +040096 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived', true)
97 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
98 }
99
100 // Install rabbitmq
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200101 if (salt.testTarget(master, 'I@rabbitmq:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400102 withEnv(['ASK_ON_ERROR=false']){
103 retry(2) {
104 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
105 }
106 }
107
108 // Check the rabbitmq status
109 salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
110 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200111
Jakub Josef79ecec32017-02-17 14:36:28 +0100112 // Install haproxy
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200113 if (salt.testTarget(master, 'I@haproxy:proxy')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400114 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
115 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
116 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
117 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200118
Jakub Josef79ecec32017-02-17 14:36:28 +0100119 // Install memcached
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200120 if (salt.testTarget(master, 'I@memcached:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400121 salt.enforceState(master, 'I@memcached:server', 'memcached', true)
122 }
123
124 // Install etcd
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200125 if (salt.testTarget(master, 'I@etcd:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400126 salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
127 salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['bash -c "source /var/lib/etcd/configenv && etcdctl cluster-health"'])
128 }
129}
130
131def installOpenstackInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200132 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400133
134 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200135 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100136}
137
138
Ales Komarekef2bab62017-04-26 11:48:28 +0200139def installOpenstackControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100140 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200141
142 // Install horizon dashboard
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300143 if (salt.testTarget(master, 'I@horizon:server')) {
144 salt.enforceState(master, 'I@horizon:server', 'horizon', true)
145 }
146 if (salt.testTarget(master, 'I@nginx:server')) {
147 salt.enforceState(master, 'I@nginx:server', 'nginx', true)
148 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200149
Jakub Josef79ecec32017-02-17 14:36:28 +0100150 // setup keystone service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300151 if (salt.testTarget(master, 'I@keystone:server')) {
152 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
153 salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server', true)
154 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
155 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100156
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300157 // keystone:client must be called locally
158 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
159 salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
160 sleep(30)
161 }
162 if (salt.testTarget(master, 'I@keystone:client')) {
Vasyl Saienkoff6f0f02017-07-19 15:54:16 +0300163 salt.enforceState(master, 'I@keystone:client and *01*', 'keystone.client', true)
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300164 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
165 }
166 if (salt.testTarget(master, 'I@keystone:server')) {
167 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonercv3; openstack service list'], null, true)
168 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100169
Jakub Josef79ecec32017-02-17 14:36:28 +0100170 // Install glance and ensure glusterfs clusters
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300171 if (salt.testTarget(master, 'I@glance:server')) {
172 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
173 salt.enforceState(master, 'I@glance:server and *01*', 'glance.server', true)
174 salt.enforceState(master, 'I@glance:server', 'glance.server', true)
175 }
176 if (salt.testTarget(master, 'I@glusterfs:client')) {
177 salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client', true)
178 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200179
Jakub Josef79ecec32017-02-17 14:36:28 +0100180 // Update fernet tokens before doing request on keystone server
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300181 if (salt.testTarget(master, 'I@keystone:server')) {
182 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200183
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300184 // Check glance service
185 if (salt.testTarget(master, 'I@glance:server')){
186 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
187 }
188 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200189
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400190 // Create glance resources
191 if (salt.testTarget(master, 'I@glance:client')) {
192 salt.enforceState(master, 'I@glance:client', 'glance.client', true)
193 }
194
Jakub Josef79ecec32017-02-17 14:36:28 +0100195 // Install and check nova service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300196 if (salt.testTarget(master, 'I@nova:controller')) {
197 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
198 salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller', true)
199 salt.enforceState(master, 'I@nova:controller', 'nova.controller', true)
200 if (salt.testTarget(master, 'I@keystone:server')) {
201 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
202 }
203 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200204
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400205 // Create nova resources
206 if (salt.testTarget(master, 'I@nova:client')) {
207 salt.enforceState(master, 'I@nova:client', 'nova.client', true)
208 }
209
Jakub Josef79ecec32017-02-17 14:36:28 +0100210 // Install and check cinder service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300211 if (salt.testTarget(master, 'I@cinder:controller')) {
212 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
213 salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder', true)
214 salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
215 if (salt.testTarget(master, 'I@keystone:server')) {
216 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
217 }
218 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200219
Jakub Josef79ecec32017-02-17 14:36:28 +0100220 // Install neutron service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300221 if (salt.testTarget(master, 'I@neutron:server')) {
222 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200223
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300224 salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server', true)
225 salt.enforceState(master, 'I@neutron:server', 'neutron.server', true)
226 if (salt.testTarget(master, 'I@keystone:server')) {
227 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
228 }
229 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200230
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400231 // Create neutron resources
232 if (salt.testTarget(master, 'I@neutron:client')) {
233 salt.enforceState(master, 'I@neutron:client', 'neutron.client', true)
234 }
235
Jakub Josef79ecec32017-02-17 14:36:28 +0100236 // Install heat service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300237 if (salt.testTarget(master, 'I@heat:server')) {
238 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
239 salt.enforceState(master, 'I@heat:server and *01*', 'heat', true)
240 salt.enforceState(master, 'I@heat:server', 'heat', true)
241 if (salt.testTarget(master, 'I@keystone:server')) {
242 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
243 }
244 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200245
246 // Restart nova api
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300247 if (salt.testTarget(master, 'I@nova:controller')) {
248 salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
249 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300250
251 // Install ironic service
252 if (salt.testTarget(master, 'I@ironic:api')) {
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300253 salt.enforceState(master, 'I@ironic:api and *01*', 'ironic.api', true)
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300254 salt.enforceState(master, 'I@ironic:api', 'ironic.api', true)
255 }
Andrey Shestakov82c0b892017-07-24 18:46:21 +0300256
257 // Install designate service
258 if (salt.testTarget(master, 'I@designate:server:enabled')) {
259 if (salt.testTarget(master, 'I@designate:server:backend:bind9')) {
260 salt.enforceState(master, 'I@bind:server', 'bind.server', true)
261 }
262 if (salt.testTarget(master, 'I@designate:server:backend:pdns4')) {
263 salt.enforceState(master, 'I@powerdns:server', 'powerdns.server', true)
264 }
265 salt.enforceState(master, 'I@designate:server and *01*', 'designate.server', true)
266 salt.enforceState(master, 'I@designate:server', 'designate.server', true)
267 }
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400268
269 // Install octavia api service
270 if (salt.testTarget(master, 'I@octavia:api')) {
271 salt.enforceState(master, 'I@octavia:api', 'octavia', true)
272 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100273}
274
275
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300276def installIronicConductor(master){
277 def salt = new com.mirantis.mk.Salt()
278
279 if (salt.testTarget(master, 'I@ironic:conductor')) {
280 salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor', true)
281 salt.enforceState(master, 'I@ironic:conductor', 'apache', true)
282 }
283 if (salt.testTarget(master, 'I@tftpd_hpa:server')) {
284 salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa', true)
285 }
286
287 if (salt.testTarget(master, 'I@nova:compute')) {
288 salt.runSaltProcessStep(master, 'I@nova:compute', 'service.restart', ['nova-compute'])
289 }
290
291 if (salt.testTarget(master, 'I@baremetal_simulator:enabled')) {
292 salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator', true)
293 }
294 if (salt.testTarget(master, 'I@ironic:client')) {
295 salt.enforceState(master, 'I@ironic:client', 'ironic.client', true)
296 }
297}
298
299
300
Ales Komarekef2bab62017-04-26 11:48:28 +0200301def installOpenstackNetwork(master, physical = "false") {
Jakub Josef79ecec32017-02-17 14:36:28 +0100302 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200303
304 salt.runSaltProcessStep(master, 'I@neutron:gateway', 'state.apply', [], null, true)
Elena Ezhova8d53bff2017-08-01 17:43:30 +0400305
306 // install octavia manager services
307 if (salt.testTarget(master, 'I@octavia:manager')) {
308 salt.runSaltProcessStep(master, 'I@salt:master', 'mine.update', ['*'], null, true)
309 salt.enforceState(master, 'I@octavia:manager', 'salt.minion.ca', true)
310 salt.enforceState(master, 'I@octavia:manager', 'salt.minion.cert', true)
311 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200312}
313
314
315def installOpenstackCompute(master) {
316 def salt = new com.mirantis.mk.Salt()
317
318 // Configure compute nodes
319 retry(2) {
Marek Celoude305ec72017-05-16 11:27:53 +0200320 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.highstate', ['exclude=opencontrail.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200321 }
322}
323
324
325def installContrailNetwork(master) {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200326 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200327 def salt = new com.mirantis.mk.Salt()
328
329
Jakub Josef79ecec32017-02-17 14:36:28 +0100330 // Install opencontrail database services
331 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200332 try {
333 salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
334 } catch (Exception e) {
335 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
336 }
337
338 try {
339 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
340 } catch (Exception e) {
341 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
342 }
343
Jakub Josef79ecec32017-02-17 14:36:28 +0100344 // Install opencontrail control services
345 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200346 salt.runSaltProcessStep(master, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
347 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
348 salt.runSaltProcessStep(master, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100349
Jakub Josef79ecec32017-02-17 14:36:28 +0100350 // Test opencontrail
Ales Komarekef2bab62017-04-26 11:48:28 +0200351 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100352}
353
354
Ales Komarekef2bab62017-04-26 11:48:28 +0200355def installContrailCompute(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200356 def salt = new com.mirantis.mk.Salt()
vrovachev32f7f542017-08-25 16:17:25 +0400357 def common = new com.mirantis.mk.Common()
Jakub Josef79ecec32017-02-17 14:36:28 +0100358 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200359 // Provision opencontrail control services
360 salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100361 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100362
vrovachev4ff77302017-08-09 20:39:57 +0400363 // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
364 try {
365 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail', true)
366 } catch (Exception e) {
367 common.warningMsg('Exception in state opencontrail on I@opencontrail:compute')
368 }
369
Ales Komarekef2bab62017-04-26 11:48:28 +0200370 salt.runSaltProcessStep(master, 'I@nova:compute', 'cmd.run', ['exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "'], null, true)
vrovachev4ff77302017-08-09 20:39:57 +0400371
372 if (salt.testTarget(master, 'I@opencontrail:compute')) {
373 sleep(300)
374 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client', true)
375 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail', true)
376 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100377}
378
379
Ales Komarekef2bab62017-04-26 11:48:28 +0200380def installKubernetesInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200381 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400382 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200383 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100384}
385
386
Tomáš Kukrálc1a1bbc2017-04-28 21:16:25 +0200387def installKubernetesControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100388 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200389
Jakub Josef79ecec32017-02-17 14:36:28 +0100390 // Install Kubernetes pool and Calico
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200391 salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
392 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100393
394 // Setup etcd server
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200395 salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100396
397 // Run k8s without master.setup
398 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
399
400 // Run k8s master setup
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200401 salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100402
403 // Restart kubelet
404 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
405}
406
407
Ales Komarekef2bab62017-04-26 11:48:28 +0200408def installKubernetesCompute(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200409 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200410
411 // Refresh minion's pillar data
412 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
413 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
414
415 // Bootstrap all nodes
416 salt.enforceState(master, 'I@kubernetes:pool', 'linux')
417 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
418 salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])
419
420 // Create and distribute SSL certificates for services using salt state
421 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')
422
423 // Install docker
424 salt.enforceState(master, 'I@docker:host', 'docker.host')
425
426 // Install Kubernetes and Calico
427 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
428
429}
430
431
Martin Polreich8663a342017-06-30 17:33:08 +0200432def installDockerSwarm(master) {
433 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100434
vrovachev1c4770b2017-07-05 13:25:21 +0400435 //Install and Configure Docker
Martin Polreich8663a342017-06-30 17:33:08 +0200436 salt.enforceState(master, 'I@docker:swarm', 'docker.host')
437 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
438 salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains', true)
439 salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update', [], null, true)
440 salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules', [], null, true)
441 sleep(5)
Martin Polreich377c37a2017-08-08 15:42:51 +0200442 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200443 salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm', true)
444 salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200445}
446
Martin Polreich8663a342017-06-30 17:33:08 +0200447def installStacklight(master) {
448 def common = new com.mirantis.mk.Common()
449 def salt = new com.mirantis.mk.Salt()
450
Martin Polreich792f2662017-07-11 13:36:32 +0200451 // Install haproxy
452 if (common.checkContains('STACK_INSTALL', 'k8s')) {
453 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
454 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
455 }
Martin Polreich8663a342017-06-30 17:33:08 +0200456 //Install Telegraf
Martin Polreichd894e3e2017-07-04 15:35:02 +0200457 salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200458
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400459 // Install Prometheus exporters
460 if (salt.testTarget(master, 'I@prometheus:exporters')) {
461 salt.enforceState(master, 'I@prometheus:exporters', 'prometheus', true)
462 }
463
Martin Polreich8663a342017-06-30 17:33:08 +0200464 //Install Elasticsearch and Kibana
Martin Polreichbf7f6162017-07-06 14:43:21 +0200465 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200466 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200467 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200468 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200469 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200470 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200471 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200472 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
473
Martin Polreich470925a2017-07-06 17:12:59 +0200474 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200475 if (common.checkContains('STACK_INSTALL', 'k8s')) {
476 withEnv(['ASK_ON_ERROR=false']){
477 retry(2) {
478 salt.enforceState(master, 'I@galera:master', 'galera', true)
479 }
Martin Polreich470925a2017-07-06 17:12:59 +0200480 }
Martin Polreich792f2662017-07-11 13:36:32 +0200481 salt.enforceState(master, 'I@galera:slave', 'galera', true)
Martin Polreich406f6462017-07-11 11:33:42 +0000482
Martin Polreich792f2662017-07-11 13:36:32 +0200483 // Check galera status
484 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
485 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
486 }
Martin Polreich470925a2017-07-06 17:12:59 +0200487
Martin Polreich8663a342017-06-30 17:33:08 +0200488 //Collect Grains
489 salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains', true)
490 salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules', [], null, true)
491 salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update', [], null, true)
492 sleep(5)
493
494 //Configure services in Docker Swarm
Martin Polreich8017f452017-08-21 16:01:42 +0200495 if (common.checkContains('STACK_INSTALL', 'k8s')) {
496 salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'prometheus', true, false)
497 }
498 else {
499 salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', ['prometheus', 'heka.remote_collector'], true, false)
500 }
Martin Polreich8663a342017-06-30 17:33:08 +0200501 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker', true)
Martin Polreich595baef2017-07-04 16:11:04 +0200502 salt.runSaltProcessStep(master, 'I@docker:swarm', 'dockerng.ps', [], null, true)
Martin Polreich8663a342017-06-30 17:33:08 +0200503
504 //Configure Grafana
Martin Polreich305e2222017-07-06 11:33:00 +0200505 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200506 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200507
Martin Polreich8663a342017-06-30 17:33:08 +0200508 def stacklight_vip
509 if(!pillar['return'].isEmpty()) {
510 stacklight_vip = pillar['return'][0].values()[0]
511 } else {
512 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
513 }
vrovachev1c4770b2017-07-05 13:25:21 +0400514
Martin Polreich305e2222017-07-06 11:33:00 +0200515 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200516 sleep(120)
Martin Polreich8663a342017-06-30 17:33:08 +0200517 salt.enforceState(master, 'I@grafana:client', 'grafana.client', true)
518
519 salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
520}
521
522def installStacklightv1Control(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200523 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200524
525 // infra install
526 // Install the StackLight backends
527 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
528 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
529
530 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
531 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
532
533 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
534 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
535
536 salt.enforceState(master, '*01* and I@grafana:server','grafana.server', true)
537 salt.enforceState(master, 'I@grafana:server','grafana.server', true)
538
Kalynovskyi3e370112017-06-26 12:48:23 +0300539 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
540 def alarming_service = alarming_service_pillar['return'][0].values()[0]
541
542 switch (alarming_service) {
543 case 'sensu':
544 // Update Sensu
545 salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq', true)
546 salt.enforceState(master, 'I@redis:cluster:role:master', 'redis', true)
547 salt.enforceState(master, 'I@redis:server', 'redis', true)
548 salt.enforceState(master, 'I@sensu:server', 'sensu', true)
549 default:
550 // Update Nagios
551 salt.enforceState(master, 'I@nagios:server', 'nagios.server', true)
552 // Stop the Nagios service because the package starts it by default and it will
553 // started later only on the node holding the VIP address
554 salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
555 }
556
Ales Komarekef2bab62017-04-26 11:48:28 +0200557 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
Marek Celoudebc623b2017-06-02 17:12:31 +0200558 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200559
560 sleep(10)
561}
562
Martin Polreich8663a342017-06-30 17:33:08 +0200563def installStacklightv1Client(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200564 def salt = new com.mirantis.mk.Salt()
565 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200566
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200567 salt.runSaltProcessStep(master, 'I@elasticsearch:client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200568 // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200569 salt.runSaltProcessStep(master, 'I@kibana:client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200570 // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
571
572 // Install collectd, heka and sensu services on the nodes, this will also
573 // generate the metadata that goes into the grains and eventually into Salt Mine
574 salt.enforceState(master, '*', 'collectd', true)
575 salt.enforceState(master, '*', 'salt.minion', true)
576 salt.enforceState(master, '*', 'heka', true)
577
578 // Gather the Grafana metadata as grains
579 salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
580
581 // Update Salt Mine
582 salt.enforceState(master, '*', 'salt.minion.grains', true)
583 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules', [], null, true)
584 salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
585
586 sleep(5)
587
588 // Update Heka
589 salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
590
591 // Update collectd
592 salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd', true)
593
Kalynovskyi3e370112017-06-26 12:48:23 +0300594 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
595 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +0200596
Kalynovskyi3e370112017-06-26 12:48:23 +0300597 switch (alarming_service) {
598 case 'sensu':
599 // Update Sensu
600 // TODO for stacklight team, should be fixed in model
601 salt.enforceState(master, 'I@sensu:client', 'sensu', true)
602 default:
603 break
604 // Default is nagios, and was enforced in installStacklightControl()
605 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200606
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200607 salt.runSaltProcessStep(master, 'I@grafana:client and *01*', 'cmd.run', ['salt-call state.sls grafana.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200608 // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
609
Marek Celoudd200cad2017-06-07 10:34:46 +0200610 // Finalize the configuration of Grafana (add the dashboards...)
Alexander Noskov8448fc52017-06-21 14:03:45 +0200611 salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
612 salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client', true)
613 salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client', true)
Marek Celoudd200cad2017-06-07 10:34:46 +0200614 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
615
Ales Komarekef2bab62017-04-26 11:48:28 +0200616 // Get the StackLight monitoring VIP addres
617 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
618 //vip=${vip:=172.16.10.253}
619 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +0200620 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +0200621 def stacklight_vip = pillar['return'][0].values()[0]
622
623 if (stacklight_vip) {
624 // (re)Start manually the services that are bound to the monitoring VIP
625 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
626 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
627 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
628 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
629 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
630 } else {
631 throw new Exception("Missing stacklight_vip")
632 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +0100633}
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +0200634
635
636//
637// Ceph
638//
639
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +0200640def installCephMon(master, target='I@ceph:mon', setup=true) {
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +0200641 def salt = new com.mirantis.mk.Salt()
642
Ondrej Smolafd5c2352017-08-11 14:25:39 +0200643 // install Ceph Mons
Tomáš Kukrál9b4fb512017-08-14 11:01:49 +0200644 salt.enforceState(master, target, 'ceph.mon', true)
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +0200645
646 // setup poools, keyrings and maybe crush
647 if (salt.testTarget(master, 'I@ceph:setup') && setup) {
648 salt.enforceState(master, 'I@ceph:setup', 'ceph.setup', true)
649 }
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +0200650}
651
652def installCephOsd(master, target='I@ceph:osd') {
653 def salt = new com.mirantis.mk.Salt()
654
Tomáš Kukrál3343a1f2017-08-16 12:03:36 +0200655 // Prapare filesystem on OSD drives
656 salt.enforceState(master, target, 'linux.storage', true)
657
Tomáš Kukrál64f8e1c2017-08-11 10:32:20 +0200658 // install Ceph OSDs
659 salt.enforceState(master, target, 'ceph.osd', true)
660}
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +0200661
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +0200662def installCephClient(master) {
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +0200663 def salt = new com.mirantis.mk.Salt()
664
665 // install Ceph Radosgw
Tomáš Kukrál5836e3d2017-08-25 18:20:55 +0200666 if (salt.testTarget(master, 'I@ceph:radosgw')) {
667 salt.enforceState(master, target, 'ceph.radosgw', true)
668 }
Tomáš Kukrál1e5b2192017-08-15 16:58:18 +0200669}