blob: fa5e8d39b3848ded5f521d4f76116000c92dcf4c [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
20 salt.enforceState(master, 'I@salt:master', ['salt.master', 'reclass'], true)
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)
26 salt.enforceState(master, 'I@salt:master', ['salt.minion'], true)
27
Jakub Josef200550f2017-05-16 17:39:55 +020028 salt.enforceState(master, '*', ['linux.system'], true)
29 salt.enforceState(master, '*', ['salt.minion'], true)
Ales Komarekef2bab62017-04-26 11:48:28 +020030 salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
Jakub Josef79ecec32017-02-17 14:36:28 +010031}
32
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010033def installInfraKvm(master) {
34 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010035
Ales Komarekef2bab62017-04-26 11:48:28 +020036 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.refresh_pillar', [], null, true)
37 salt.runSaltProcessStep(master, 'I@linux:system', 'saltutil.sync_all', [], null, true)
38
39 salt.enforceState(master, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010040 salt.enforceState(master, 'I@salt:control', 'libvirt', true)
41 salt.enforceState(master, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010042
Ales Komarekef2bab62017-04-26 11:48:28 +020043 sleep(600)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010044
Marek Celoudc9b3cc82017-05-22 12:50:53 +000045 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
46 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010047}
Jakub Josef79ecec32017-02-17 14:36:28 +010048
vrovachev1c4770b2017-07-05 13:25:21 +040049def installInfra(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +010050 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020051
Jakub Josef79ecec32017-02-17 14:36:28 +010052 // Install glusterfs
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020053 if (salt.testTarget(master, 'I@glusterfs:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +040054 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010055
vrovachev1c4770b2017-07-05 13:25:21 +040056 withEnv(['ASK_ON_ERROR=false']){
57 retry(5) {
58 salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
59 }
Alexander Noskov93acac42017-06-20 17:55:55 +020060 }
vrovachev1c4770b2017-07-05 13:25:21 +040061
62 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
63 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Alexander Noskov93acac42017-06-20 17:55:55 +020064 }
Ales Komarekef2bab62017-04-26 11:48:28 +020065
Jakub Josef79ecec32017-02-17 14:36:28 +010066 // Install galera
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020067 if (salt.testTarget(master, 'I@galera:server') || salt.testTarget(master, 'I@galera:slave')) {
vrovachev1c4770b2017-07-05 13:25:21 +040068 withEnv(['ASK_ON_ERROR=false']){
69 retry(2) {
70 salt.enforceState(master, 'I@galera:master', 'galera', true)
71 }
Ales Komarekef2bab62017-04-26 11:48:28 +020072 }
vrovachev1c4770b2017-07-05 13:25:21 +040073 salt.enforceState(master, 'I@galera:slave', 'galera', true)
74
75 // Check galera status
76 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
77 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
Vasyl Saienkoc1fb9892017-07-13 14:54:13 +030078 // If galera is not enabled check if we need to install mysql:server
79 } else if (salt.testTarget(master, 'I@mysql:server')){
80 salt.enforceState(master, 'I@mysql:server', 'mysql.server', true)
81 if (salt.testTarget(master, 'I@mysql:client')){
82 salt.enforceState(master, 'I@mysql:client', 'mysql.client', true)
83 }
Ales Komarekef2bab62017-04-26 11:48:28 +020084 }
Ales Komarekef2bab62017-04-26 11:48:28 +020085
vrovachev1c4770b2017-07-05 13:25:21 +040086 // Install docker
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020087 if (salt.testTarget(master, 'I@docker:host')) {
vrovachev1c4770b2017-07-05 13:25:21 +040088 salt.enforceState(master, 'I@docker:host', 'docker.host')
89 salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
90 }
Ales Komarekef2bab62017-04-26 11:48:28 +020091
vrovachev1c4770b2017-07-05 13:25:21 +040092 // Install keepalived
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020093 if (salt.testTarget(master, 'I@keepalived:cluster')) {
vrovachev1c4770b2017-07-05 13:25:21 +040094 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived', true)
95 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
96 }
97
98 // Install rabbitmq
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020099 if (salt.testTarget(master, 'I@rabbitmq:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400100 withEnv(['ASK_ON_ERROR=false']){
101 retry(2) {
102 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
103 }
104 }
105
106 // Check the rabbitmq status
107 salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
108 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200109
Jakub Josef79ecec32017-02-17 14:36:28 +0100110 // Install haproxy
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200111 if (salt.testTarget(master, 'I@haproxy:proxy')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400112 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
113 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
114 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
115 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200116
Jakub Josef79ecec32017-02-17 14:36:28 +0100117 // Install memcached
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200118 if (salt.testTarget(master, 'I@memcached:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400119 salt.enforceState(master, 'I@memcached:server', 'memcached', true)
120 }
121
122 // Install etcd
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200123 if (salt.testTarget(master, 'I@etcd:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400124 salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
125 salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['bash -c "source /var/lib/etcd/configenv && etcdctl cluster-health"'])
126 }
127}
128
129def installOpenstackInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200130 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400131
132 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200133 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100134}
135
136
Ales Komarekef2bab62017-04-26 11:48:28 +0200137def installOpenstackControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100138 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200139
140 // Install horizon dashboard
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300141 if (salt.testTarget(master, 'I@horizon:server')) {
142 salt.enforceState(master, 'I@horizon:server', 'horizon', true)
143 }
144 if (salt.testTarget(master, 'I@nginx:server')) {
145 salt.enforceState(master, 'I@nginx:server', 'nginx', true)
146 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200147
Jakub Josef79ecec32017-02-17 14:36:28 +0100148 // setup keystone service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300149 if (salt.testTarget(master, 'I@keystone:server')) {
150 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
151 salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server', true)
152 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
153 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100154
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300155 // keystone:client must be called locally
156 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
157 salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
158 sleep(30)
159 }
160 if (salt.testTarget(master, 'I@keystone:client')) {
161 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
162 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
163 }
164 if (salt.testTarget(master, 'I@keystone:server')) {
165 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonercv3; openstack service list'], null, true)
166 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100167
Jakub Josef79ecec32017-02-17 14:36:28 +0100168 // Install glance and ensure glusterfs clusters
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300169 if (salt.testTarget(master, 'I@glance:server')) {
170 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
171 salt.enforceState(master, 'I@glance:server and *01*', 'glance.server', true)
172 salt.enforceState(master, 'I@glance:server', 'glance.server', true)
173 }
174 if (salt.testTarget(master, 'I@glusterfs:client')) {
175 salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client', true)
176 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200177
Jakub Josef79ecec32017-02-17 14:36:28 +0100178 // Update fernet tokens before doing request on keystone server
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300179 if (salt.testTarget(master, 'I@keystone:server')) {
180 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200181
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300182 // Check glance service
183 if (salt.testTarget(master, 'I@glance:server')){
184 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
185 }
186 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200187
Jakub Josef79ecec32017-02-17 14:36:28 +0100188 // Install and check nova service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300189 if (salt.testTarget(master, 'I@nova:controller')) {
190 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
191 salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller', true)
192 salt.enforceState(master, 'I@nova:controller', 'nova.controller', true)
193 if (salt.testTarget(master, 'I@keystone:server')) {
194 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
195 }
196 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200197
Jakub Josef79ecec32017-02-17 14:36:28 +0100198 // Install and check cinder service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300199 if (salt.testTarget(master, 'I@cinder:controller')) {
200 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
201 salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder', true)
202 salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
203 if (salt.testTarget(master, 'I@keystone:server')) {
204 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
205 }
206 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200207
Jakub Josef79ecec32017-02-17 14:36:28 +0100208 // Install neutron service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300209 if (salt.testTarget(master, 'I@neutron:server')) {
210 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200211
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300212 salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server', true)
213 salt.enforceState(master, 'I@neutron:server', 'neutron.server', true)
214 if (salt.testTarget(master, 'I@keystone:server')) {
215 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
216 }
217 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200218
Jakub Josef79ecec32017-02-17 14:36:28 +0100219 // Install heat service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300220 if (salt.testTarget(master, 'I@heat:server')) {
221 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
222 salt.enforceState(master, 'I@heat:server and *01*', 'heat', true)
223 salt.enforceState(master, 'I@heat:server', 'heat', true)
224 if (salt.testTarget(master, 'I@keystone:server')) {
225 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
226 }
227 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200228
229 // Restart nova api
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300230 if (salt.testTarget(master, 'I@nova:controller')) {
231 salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
232 }
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300233
234 // Install ironic service
235 if (salt.testTarget(master, 'I@ironic:api')) {
236 salt.enforceState(master, 'I@ironic:api and ctl01*', 'ironic.api', true)
237 salt.enforceState(master, 'I@ironic:api', 'ironic.api', true)
238 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100239}
240
241
Vasyl Saienkoa7c10c02017-07-13 10:43:43 +0300242def installIronicConductor(master){
243 def salt = new com.mirantis.mk.Salt()
244
245 if (salt.testTarget(master, 'I@ironic:conductor')) {
246 salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor', true)
247 salt.enforceState(master, 'I@ironic:conductor', 'apache', true)
248 }
249 if (salt.testTarget(master, 'I@tftpd_hpa:server')) {
250 salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa', true)
251 }
252
253 if (salt.testTarget(master, 'I@nova:compute')) {
254 salt.runSaltProcessStep(master, 'I@nova:compute', 'service.restart', ['nova-compute'])
255 }
256
257 if (salt.testTarget(master, 'I@baremetal_simulator:enabled')) {
258 salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator', true)
259 }
260 if (salt.testTarget(master, 'I@ironic:client')) {
261 salt.enforceState(master, 'I@ironic:client', 'ironic.client', true)
262 }
263}
264
265
266
Ales Komarekef2bab62017-04-26 11:48:28 +0200267def installOpenstackNetwork(master, physical = "false") {
Jakub Josef79ecec32017-02-17 14:36:28 +0100268 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200269
270 salt.runSaltProcessStep(master, 'I@neutron:gateway', 'state.apply', [], null, true)
271}
272
273
274def installOpenstackCompute(master) {
275 def salt = new com.mirantis.mk.Salt()
276
277 // Configure compute nodes
278 retry(2) {
Marek Celoude305ec72017-05-16 11:27:53 +0200279 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.highstate', ['exclude=opencontrail.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200280 }
281}
282
283
284def installContrailNetwork(master) {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200285 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200286 def salt = new com.mirantis.mk.Salt()
287
288
Jakub Josef79ecec32017-02-17 14:36:28 +0100289 // Install opencontrail database services
290 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200291 try {
292 salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
293 } catch (Exception e) {
294 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
295 }
296
297 try {
298 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
299 } catch (Exception e) {
300 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
301 }
302
Jakub Josef79ecec32017-02-17 14:36:28 +0100303 // Install opencontrail control services
304 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200305 salt.runSaltProcessStep(master, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
306 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
307 salt.runSaltProcessStep(master, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100308
Jakub Josef79ecec32017-02-17 14:36:28 +0100309 // Test opencontrail
Ales Komarekef2bab62017-04-26 11:48:28 +0200310 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100311}
312
313
Ales Komarekef2bab62017-04-26 11:48:28 +0200314def installContrailCompute(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200315 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100316 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200317 // Provision opencontrail control services
318 salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100319 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100320
Ales Komarekef2bab62017-04-26 11:48:28 +0200321 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)
322 sleep(300)
Marek Celoude305ec72017-05-16 11:27:53 +0200323 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100324}
325
326
Ales Komarekef2bab62017-04-26 11:48:28 +0200327def installKubernetesInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200328 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400329 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200330 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100331}
332
333
Tomáš Kukrálc1a1bbc2017-04-28 21:16:25 +0200334def installKubernetesControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100335 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200336
Jakub Josef79ecec32017-02-17 14:36:28 +0100337 // Install Kubernetes pool and Calico
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200338 salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
339 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100340
341 // Setup etcd server
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200342 salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100343
344 // Run k8s without master.setup
345 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
346
347 // Run k8s master setup
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200348 salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100349
350 // Restart kubelet
351 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
352}
353
354
Ales Komarekef2bab62017-04-26 11:48:28 +0200355def installKubernetesCompute(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200356 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200357
358 // Refresh minion's pillar data
359 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
360 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
361
362 // Bootstrap all nodes
363 salt.enforceState(master, 'I@kubernetes:pool', 'linux')
364 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
365 salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])
366
367 // Create and distribute SSL certificates for services using salt state
368 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')
369
370 // Install docker
371 salt.enforceState(master, 'I@docker:host', 'docker.host')
372
373 // Install Kubernetes and Calico
374 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
375
376}
377
378
379def installKubernetesContrailCompute(master) {
380 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100381 // Install opencontrail
382 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail'])
383 // Reboot compute nodes
vrovachev02cd1bc2017-06-28 10:47:13 +0400384 try {
385 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'system.reboot')
386 } catch (Exception e) {
387 common.warningMsg('Exception in state system.reboot on I@opencontrail:compute')
388 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100389}
390
Martin Polreich8663a342017-06-30 17:33:08 +0200391def installDockerSwarm(master) {
392 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100393
vrovachev1c4770b2017-07-05 13:25:21 +0400394 //Install and Configure Docker
Martin Polreich8663a342017-06-30 17:33:08 +0200395 salt.enforceState(master, 'I@docker:swarm', 'docker.host')
396 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
397 salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains', true)
398 salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update', [], null, true)
399 salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules', [], null, true)
400 sleep(5)
401 salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm', true)
402 salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200403}
404
405
406def installStacklight(master) {
407 def common = new com.mirantis.mk.Common()
408 def salt = new com.mirantis.mk.Salt()
409
Martin Polreich792f2662017-07-11 13:36:32 +0200410 // Install haproxy
411 if (common.checkContains('STACK_INSTALL', 'k8s')) {
412 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
413 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
414 }
Martin Polreich8663a342017-06-30 17:33:08 +0200415 //Install Telegraf
Martin Polreichd894e3e2017-07-04 15:35:02 +0200416 salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200417
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400418 // Install Prometheus exporters
419 if (salt.testTarget(master, 'I@prometheus:exporters')) {
420 salt.enforceState(master, 'I@prometheus:exporters', 'prometheus', true)
421 }
422
Martin Polreich8663a342017-06-30 17:33:08 +0200423 //Install Elasticsearch and Kibana
Martin Polreichbf7f6162017-07-06 14:43:21 +0200424 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200425 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200426 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200427 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200428 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200429 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200430 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200431 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
432
Martin Polreich470925a2017-07-06 17:12:59 +0200433 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200434 if (common.checkContains('STACK_INSTALL', 'k8s')) {
435 withEnv(['ASK_ON_ERROR=false']){
436 retry(2) {
437 salt.enforceState(master, 'I@galera:master', 'galera', true)
438 }
Martin Polreich470925a2017-07-06 17:12:59 +0200439 }
Martin Polreich792f2662017-07-11 13:36:32 +0200440 salt.enforceState(master, 'I@galera:slave', 'galera', true)
Martin Polreich406f6462017-07-11 11:33:42 +0000441
Martin Polreich792f2662017-07-11 13:36:32 +0200442 // Check galera status
443 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
444 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
445 }
Martin Polreich470925a2017-07-06 17:12:59 +0200446
Martin Polreich8663a342017-06-30 17:33:08 +0200447 //Collect Grains
448 salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains', true)
449 salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules', [], null, true)
450 salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update', [], null, true)
451 sleep(5)
452
453 //Configure services in Docker Swarm
Martin Polreich595baef2017-07-04 16:11:04 +0200454 salt.enforceState(master, 'I@docker:swarm', ['prometheus', 'heka.remote_collector'], true, false)
Martin Polreich8663a342017-06-30 17:33:08 +0200455 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker', true)
Martin Polreich595baef2017-07-04 16:11:04 +0200456 salt.runSaltProcessStep(master, 'I@docker:swarm', 'dockerng.ps', [], null, true)
Martin Polreich8663a342017-06-30 17:33:08 +0200457
458 //Configure Grafana
Martin Polreich305e2222017-07-06 11:33:00 +0200459 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200460 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200461
Martin Polreich8663a342017-06-30 17:33:08 +0200462 def stacklight_vip
463 if(!pillar['return'].isEmpty()) {
464 stacklight_vip = pillar['return'][0].values()[0]
465 } else {
466 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
467 }
vrovachev1c4770b2017-07-05 13:25:21 +0400468
Martin Polreich305e2222017-07-06 11:33:00 +0200469 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200470 sleep(120)
Martin Polreich8663a342017-06-30 17:33:08 +0200471 salt.enforceState(master, 'I@grafana:client', 'grafana.client', true)
472
473 salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
474}
475
476def installStacklightv1Control(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200477 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200478
479 // infra install
480 // Install the StackLight backends
481 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
482 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
483
484 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
485 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
486
487 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
488 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
489
490 salt.enforceState(master, '*01* and I@grafana:server','grafana.server', true)
491 salt.enforceState(master, 'I@grafana:server','grafana.server', true)
492
Kalynovskyi3e370112017-06-26 12:48:23 +0300493 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
494 def alarming_service = alarming_service_pillar['return'][0].values()[0]
495
496 switch (alarming_service) {
497 case 'sensu':
498 // Update Sensu
499 salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq', true)
500 salt.enforceState(master, 'I@redis:cluster:role:master', 'redis', true)
501 salt.enforceState(master, 'I@redis:server', 'redis', true)
502 salt.enforceState(master, 'I@sensu:server', 'sensu', true)
503 default:
504 // Update Nagios
505 salt.enforceState(master, 'I@nagios:server', 'nagios.server', true)
506 // Stop the Nagios service because the package starts it by default and it will
507 // started later only on the node holding the VIP address
508 salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
509 }
510
Ales Komarekef2bab62017-04-26 11:48:28 +0200511 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
Marek Celoudebc623b2017-06-02 17:12:31 +0200512 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200513
514 sleep(10)
515}
516
Martin Polreich8663a342017-06-30 17:33:08 +0200517def installStacklightv1Client(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200518 def salt = new com.mirantis.mk.Salt()
519 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200520
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200521 salt.runSaltProcessStep(master, 'I@elasticsearch:client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200522 // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200523 salt.runSaltProcessStep(master, 'I@kibana:client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200524 // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
525
526 // Install collectd, heka and sensu services on the nodes, this will also
527 // generate the metadata that goes into the grains and eventually into Salt Mine
528 salt.enforceState(master, '*', 'collectd', true)
529 salt.enforceState(master, '*', 'salt.minion', true)
530 salt.enforceState(master, '*', 'heka', true)
531
532 // Gather the Grafana metadata as grains
533 salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
534
535 // Update Salt Mine
536 salt.enforceState(master, '*', 'salt.minion.grains', true)
537 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules', [], null, true)
538 salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
539
540 sleep(5)
541
542 // Update Heka
543 salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
544
545 // Update collectd
546 salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd', true)
547
Kalynovskyi3e370112017-06-26 12:48:23 +0300548 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
549 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +0200550
Kalynovskyi3e370112017-06-26 12:48:23 +0300551 switch (alarming_service) {
552 case 'sensu':
553 // Update Sensu
554 // TODO for stacklight team, should be fixed in model
555 salt.enforceState(master, 'I@sensu:client', 'sensu', true)
556 default:
557 break
558 // Default is nagios, and was enforced in installStacklightControl()
559 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200560
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200561 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 +0200562 // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
563
Marek Celoudd200cad2017-06-07 10:34:46 +0200564 // Finalize the configuration of Grafana (add the dashboards...)
Alexander Noskov8448fc52017-06-21 14:03:45 +0200565 salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
566 salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client', true)
567 salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client', true)
Marek Celoudd200cad2017-06-07 10:34:46 +0200568 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
569
Ales Komarekef2bab62017-04-26 11:48:28 +0200570 // Get the StackLight monitoring VIP addres
571 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
572 //vip=${vip:=172.16.10.253}
573 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +0200574 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +0200575 def stacklight_vip = pillar['return'][0].values()[0]
576
577 if (stacklight_vip) {
578 // (re)Start manually the services that are bound to the monitoring VIP
579 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
580 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
581 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
582 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
583 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
584 } else {
585 throw new Exception("Missing stacklight_vip")
586 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +0100587}