blob: 77f6472b78ea0874fd92efe68c82dc58b60922c2 [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')
Ales Komarekef2bab62017-04-26 11:48:28 +020078 }
Ales Komarekef2bab62017-04-26 11:48:28 +020079
vrovachev1c4770b2017-07-05 13:25:21 +040080 // Install docker
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020081 if (salt.testTarget(master, 'I@docker:host')) {
vrovachev1c4770b2017-07-05 13:25:21 +040082 salt.enforceState(master, 'I@docker:host', 'docker.host')
83 salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
84 }
Ales Komarekef2bab62017-04-26 11:48:28 +020085
vrovachev1c4770b2017-07-05 13:25:21 +040086 // Install keepalived
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020087 if (salt.testTarget(master, 'I@keepalived:cluster')) {
vrovachev1c4770b2017-07-05 13:25:21 +040088 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived', true)
89 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
90 }
91
92 // Install rabbitmq
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +020093 if (salt.testTarget(master, 'I@rabbitmq:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +040094 withEnv(['ASK_ON_ERROR=false']){
95 retry(2) {
96 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
97 }
98 }
99
100 // Check the rabbitmq status
101 salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
102 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200103
Jakub Josef79ecec32017-02-17 14:36:28 +0100104 // Install haproxy
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200105 if (salt.testTarget(master, 'I@haproxy:proxy')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400106 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
107 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
108 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
109 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200110
Jakub Josef79ecec32017-02-17 14:36:28 +0100111 // Install memcached
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200112 if (salt.testTarget(master, 'I@memcached:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400113 salt.enforceState(master, 'I@memcached:server', 'memcached', true)
114 }
115
116 // Install etcd
Tomáš Kukráld0cf7ec2017-07-13 11:29:20 +0200117 if (salt.testTarget(master, 'I@etcd:server')) {
vrovachev1c4770b2017-07-05 13:25:21 +0400118 salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
119 salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['bash -c "source /var/lib/etcd/configenv && etcdctl cluster-health"'])
120 }
121}
122
123def installOpenstackInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200124 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400125
126 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200127 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100128}
129
130
Ales Komarekef2bab62017-04-26 11:48:28 +0200131def installOpenstackControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100132 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200133
134 // Install horizon dashboard
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300135 if (salt.testTarget(master, 'I@horizon:server')) {
136 salt.enforceState(master, 'I@horizon:server', 'horizon', true)
137 }
138 if (salt.testTarget(master, 'I@nginx:server')) {
139 salt.enforceState(master, 'I@nginx:server', 'nginx', true)
140 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200141
Jakub Josef79ecec32017-02-17 14:36:28 +0100142 // setup keystone service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300143 if (salt.testTarget(master, 'I@keystone:server')) {
144 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
145 salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server', true)
146 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
147 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100148
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300149 // keystone:client must be called locally
150 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
151 salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
152 sleep(30)
153 }
154 if (salt.testTarget(master, 'I@keystone:client')) {
155 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
156 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
157 }
158 if (salt.testTarget(master, 'I@keystone:server')) {
159 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonercv3; openstack service list'], null, true)
160 }
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100161
Jakub Josef79ecec32017-02-17 14:36:28 +0100162 // Install glance and ensure glusterfs clusters
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300163 if (salt.testTarget(master, 'I@glance:server')) {
164 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
165 salt.enforceState(master, 'I@glance:server and *01*', 'glance.server', true)
166 salt.enforceState(master, 'I@glance:server', 'glance.server', true)
167 }
168 if (salt.testTarget(master, 'I@glusterfs:client')) {
169 salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client', true)
170 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200171
Jakub Josef79ecec32017-02-17 14:36:28 +0100172 // Update fernet tokens before doing request on keystone server
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300173 if (salt.testTarget(master, 'I@keystone:server')) {
174 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200175
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300176 // Check glance service
177 if (salt.testTarget(master, 'I@glance:server')){
178 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
179 }
180 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200181
Jakub Josef79ecec32017-02-17 14:36:28 +0100182 // Install and check nova service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300183 if (salt.testTarget(master, 'I@nova:controller')) {
184 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
185 salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller', true)
186 salt.enforceState(master, 'I@nova:controller', 'nova.controller', true)
187 if (salt.testTarget(master, 'I@keystone:server')) {
188 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
189 }
190 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200191
Jakub Josef79ecec32017-02-17 14:36:28 +0100192 // Install and check cinder service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300193 if (salt.testTarget(master, 'I@cinder:controller')) {
194 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
195 salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder', true)
196 salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
197 if (salt.testTarget(master, 'I@keystone:server')) {
198 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
199 }
200 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200201
Jakub Josef79ecec32017-02-17 14:36:28 +0100202 // Install neutron service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300203 if (salt.testTarget(master, 'I@neutron:server')) {
204 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200205
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300206 salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server', true)
207 salt.enforceState(master, 'I@neutron:server', 'neutron.server', true)
208 if (salt.testTarget(master, 'I@keystone:server')) {
209 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
210 }
211 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200212
Jakub Josef79ecec32017-02-17 14:36:28 +0100213 // Install heat service
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300214 if (salt.testTarget(master, 'I@heat:server')) {
215 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
216 salt.enforceState(master, 'I@heat:server and *01*', 'heat', true)
217 salt.enforceState(master, 'I@heat:server', 'heat', true)
218 if (salt.testTarget(master, 'I@keystone:server')) {
219 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
220 }
221 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200222
223 // Restart nova api
Vasyl Saienko962e0b52017-07-11 10:49:19 +0300224 if (salt.testTarget(master, 'I@nova:controller')) {
225 salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
226 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100227}
228
229
Ales Komarekef2bab62017-04-26 11:48:28 +0200230def installOpenstackNetwork(master, physical = "false") {
Jakub Josef79ecec32017-02-17 14:36:28 +0100231 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200232
233 salt.runSaltProcessStep(master, 'I@neutron:gateway', 'state.apply', [], null, true)
234}
235
236
237def installOpenstackCompute(master) {
238 def salt = new com.mirantis.mk.Salt()
239
240 // Configure compute nodes
241 retry(2) {
Marek Celoude305ec72017-05-16 11:27:53 +0200242 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.highstate', ['exclude=opencontrail.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200243 }
244}
245
246
247def installContrailNetwork(master) {
Martin Polreichfc9854c2017-06-30 11:17:36 +0200248 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200249 def salt = new com.mirantis.mk.Salt()
250
251
Jakub Josef79ecec32017-02-17 14:36:28 +0100252 // Install opencontrail database services
253 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200254 try {
255 salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
256 } catch (Exception e) {
257 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
258 }
259
260 try {
261 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
262 } catch (Exception e) {
263 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
264 }
265
Jakub Josef79ecec32017-02-17 14:36:28 +0100266 // Install opencontrail control services
267 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200268 salt.runSaltProcessStep(master, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
269 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
270 salt.runSaltProcessStep(master, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100271
Jakub Josef79ecec32017-02-17 14:36:28 +0100272 // Test opencontrail
Ales Komarekef2bab62017-04-26 11:48:28 +0200273 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100274}
275
276
Ales Komarekef2bab62017-04-26 11:48:28 +0200277def installContrailCompute(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200278 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100279 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200280 // Provision opencontrail control services
281 salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100282 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100283
Ales Komarekef2bab62017-04-26 11:48:28 +0200284 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)
285 sleep(300)
Marek Celoude305ec72017-05-16 11:27:53 +0200286 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100287}
288
289
Ales Komarekef2bab62017-04-26 11:48:28 +0200290def installKubernetesInfra(master) {
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200291 def orchestrate = new com.mirantis.mk.Orchestrate()
vrovachev1c4770b2017-07-05 13:25:21 +0400292 // THIS FUNCTION IS LEGACY, PLEASE USE installInfra directly
Tomáš Kukrál104a07a2017-07-13 12:19:11 +0200293 orchestrate.installInfra(master)
Jakub Josef79ecec32017-02-17 14:36:28 +0100294}
295
296
Tomáš Kukrálc1a1bbc2017-04-28 21:16:25 +0200297def installKubernetesControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100298 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200299
Jakub Josef79ecec32017-02-17 14:36:28 +0100300 // Install Kubernetes pool and Calico
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200301 salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
302 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100303
304 // Setup etcd server
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200305 salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100306
307 // Run k8s without master.setup
308 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
309
310 // Run k8s master setup
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200311 salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100312
313 // Restart kubelet
314 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
315}
316
317
Ales Komarekef2bab62017-04-26 11:48:28 +0200318def installKubernetesCompute(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200319 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200320
321 // Refresh minion's pillar data
322 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
323 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
324
325 // Bootstrap all nodes
326 salt.enforceState(master, 'I@kubernetes:pool', 'linux')
327 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
328 salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])
329
330 // Create and distribute SSL certificates for services using salt state
331 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')
332
333 // Install docker
334 salt.enforceState(master, 'I@docker:host', 'docker.host')
335
336 // Install Kubernetes and Calico
337 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
338
339}
340
341
342def installKubernetesContrailCompute(master) {
343 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100344 // Install opencontrail
345 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail'])
346 // Reboot compute nodes
vrovachev02cd1bc2017-06-28 10:47:13 +0400347 try {
348 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'system.reboot')
349 } catch (Exception e) {
350 common.warningMsg('Exception in state system.reboot on I@opencontrail:compute')
351 }
Jakub Josef79ecec32017-02-17 14:36:28 +0100352}
353
Martin Polreich8663a342017-06-30 17:33:08 +0200354def installDockerSwarm(master) {
355 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100356
vrovachev1c4770b2017-07-05 13:25:21 +0400357 //Install and Configure Docker
Martin Polreich8663a342017-06-30 17:33:08 +0200358 salt.enforceState(master, 'I@docker:swarm', 'docker.host')
359 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm', true)
360 salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains', true)
361 salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update', [], null, true)
362 salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules', [], null, true)
363 sleep(5)
364 salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm', true)
365 salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200366}
367
368
369def installStacklight(master) {
370 def common = new com.mirantis.mk.Common()
371 def salt = new com.mirantis.mk.Salt()
372
Martin Polreich792f2662017-07-11 13:36:32 +0200373 // Install haproxy
374 if (common.checkContains('STACK_INSTALL', 'k8s')) {
375 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
376 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
377 }
Martin Polreich8663a342017-06-30 17:33:08 +0200378 //Install Telegraf
Martin Polreichd894e3e2017-07-04 15:35:02 +0200379 salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200380
Dmitry Kalashnikebc1e1e2017-07-13 14:20:08 +0400381 // Install Prometheus exporters
382 if (salt.testTarget(master, 'I@prometheus:exporters')) {
383 salt.enforceState(master, 'I@prometheus:exporters', 'prometheus', true)
384 }
385
Martin Polreich8663a342017-06-30 17:33:08 +0200386 //Install Elasticsearch and Kibana
Martin Polreichbf7f6162017-07-06 14:43:21 +0200387 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200388 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200389 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200390 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
Martin Polreicha540ac12017-06-30 22:48:39 +0200391 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200392 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Martin Polreichbf7f6162017-07-06 14:43:21 +0200393 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
Martin Polreich8663a342017-06-30 17:33:08 +0200394 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
395
Martin Polreich470925a2017-07-06 17:12:59 +0200396 // Install galera
Martin Polreich792f2662017-07-11 13:36:32 +0200397 if (common.checkContains('STACK_INSTALL', 'k8s')) {
398 withEnv(['ASK_ON_ERROR=false']){
399 retry(2) {
400 salt.enforceState(master, 'I@galera:master', 'galera', true)
401 }
Martin Polreich470925a2017-07-06 17:12:59 +0200402 }
Martin Polreich792f2662017-07-11 13:36:32 +0200403 salt.enforceState(master, 'I@galera:slave', 'galera', true)
Martin Polreich406f6462017-07-11 11:33:42 +0000404
Martin Polreich792f2662017-07-11 13:36:32 +0200405 // Check galera status
406 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
407 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
408 }
Martin Polreich470925a2017-07-06 17:12:59 +0200409
Martin Polreich8663a342017-06-30 17:33:08 +0200410 //Collect Grains
411 salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains', true)
412 salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules', [], null, true)
413 salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update', [], null, true)
414 sleep(5)
415
416 //Configure services in Docker Swarm
Martin Polreich595baef2017-07-04 16:11:04 +0200417 salt.enforceState(master, 'I@docker:swarm', ['prometheus', 'heka.remote_collector'], true, false)
Martin Polreich8663a342017-06-30 17:33:08 +0200418 salt.enforceState(master, 'I@docker:swarm:role:master', 'docker', true)
Martin Polreich595baef2017-07-04 16:11:04 +0200419 salt.runSaltProcessStep(master, 'I@docker:swarm', 'dockerng.ps', [], null, true)
Martin Polreich8663a342017-06-30 17:33:08 +0200420
421 //Configure Grafana
Martin Polreich305e2222017-07-06 11:33:00 +0200422 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Martin Polreich8663a342017-06-30 17:33:08 +0200423 common.prettyPrint(pillar)
Martin Polreich595baef2017-07-04 16:11:04 +0200424
Martin Polreich8663a342017-06-30 17:33:08 +0200425 def stacklight_vip
426 if(!pillar['return'].isEmpty()) {
427 stacklight_vip = pillar['return'][0].values()[0]
428 } else {
429 common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
430 }
vrovachev1c4770b2017-07-05 13:25:21 +0400431
Martin Polreich305e2222017-07-06 11:33:00 +0200432 common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
Martin Polreichbd7ad222017-07-06 12:53:51 +0200433 sleep(120)
Martin Polreich8663a342017-06-30 17:33:08 +0200434 salt.enforceState(master, 'I@grafana:client', 'grafana.client', true)
435
436 salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
437}
438
439def installStacklightv1Control(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200440 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200441
442 // infra install
443 // Install the StackLight backends
444 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
445 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
446
447 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
448 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
449
450 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
451 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
452
453 salt.enforceState(master, '*01* and I@grafana:server','grafana.server', true)
454 salt.enforceState(master, 'I@grafana:server','grafana.server', true)
455
Kalynovskyi3e370112017-06-26 12:48:23 +0300456 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
457 def alarming_service = alarming_service_pillar['return'][0].values()[0]
458
459 switch (alarming_service) {
460 case 'sensu':
461 // Update Sensu
462 salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq', true)
463 salt.enforceState(master, 'I@redis:cluster:role:master', 'redis', true)
464 salt.enforceState(master, 'I@redis:server', 'redis', true)
465 salt.enforceState(master, 'I@sensu:server', 'sensu', true)
466 default:
467 // Update Nagios
468 salt.enforceState(master, 'I@nagios:server', 'nagios.server', true)
469 // Stop the Nagios service because the package starts it by default and it will
470 // started later only on the node holding the VIP address
471 salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
472 }
473
Ales Komarekef2bab62017-04-26 11:48:28 +0200474 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
Marek Celoudebc623b2017-06-02 17:12:31 +0200475 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200476
477 sleep(10)
478}
479
Martin Polreich8663a342017-06-30 17:33:08 +0200480def installStacklightv1Client(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200481 def salt = new com.mirantis.mk.Salt()
482 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200483
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200484 salt.runSaltProcessStep(master, 'I@elasticsearch:client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200485 // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200486 salt.runSaltProcessStep(master, 'I@kibana:client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200487 // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
488
489 // Install collectd, heka and sensu services on the nodes, this will also
490 // generate the metadata that goes into the grains and eventually into Salt Mine
491 salt.enforceState(master, '*', 'collectd', true)
492 salt.enforceState(master, '*', 'salt.minion', true)
493 salt.enforceState(master, '*', 'heka', true)
494
495 // Gather the Grafana metadata as grains
496 salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
497
498 // Update Salt Mine
499 salt.enforceState(master, '*', 'salt.minion.grains', true)
500 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules', [], null, true)
501 salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
502
503 sleep(5)
504
505 // Update Heka
506 salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
507
508 // Update collectd
509 salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd', true)
510
Kalynovskyi3e370112017-06-26 12:48:23 +0300511 def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
512 def alarming_service = alarming_service_pillar['return'][0].values()[0]
Ales Komarekef2bab62017-04-26 11:48:28 +0200513
Kalynovskyi3e370112017-06-26 12:48:23 +0300514 switch (alarming_service) {
515 case 'sensu':
516 // Update Sensu
517 // TODO for stacklight team, should be fixed in model
518 salt.enforceState(master, 'I@sensu:client', 'sensu', true)
519 default:
520 break
521 // Default is nagios, and was enforced in installStacklightControl()
522 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200523
Alexander Noskov3c6a60a2017-06-21 14:05:07 +0200524 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 +0200525 // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
526
Marek Celoudd200cad2017-06-07 10:34:46 +0200527 // Finalize the configuration of Grafana (add the dashboards...)
Alexander Noskov8448fc52017-06-21 14:03:45 +0200528 salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
529 salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client', true)
530 salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client', true)
Marek Celoudd200cad2017-06-07 10:34:46 +0200531 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
532
Ales Komarekef2bab62017-04-26 11:48:28 +0200533 // Get the StackLight monitoring VIP addres
534 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
535 //vip=${vip:=172.16.10.253}
536 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +0200537 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +0200538 def stacklight_vip = pillar['return'][0].values()[0]
539
540 if (stacklight_vip) {
541 // (re)Start manually the services that are bound to the monitoring VIP
542 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
543 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
544 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
545 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
546 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
547 } else {
548 throw new Exception("Missing stacklight_vip")
549 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +0100550}