blob: 4e16b83d0a6b3b46a21bcfeb4315cc71ee54acf5 [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
17
18def installFoundationInfra(master) {
19 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020020
21 salt.enforceState(master, 'I@salt:master', ['salt.master', 'reclass'], true)
Tomáš Kukrálb4d75222017-06-06 10:36:02 +020022
23 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
24 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
25
26 salt.enforceState(master, 'I@salt:master', ['linux.system'], true)
27 salt.enforceState(master, 'I@salt:master', ['salt.minion'], true)
28
Jakub Josef200550f2017-05-16 17:39:55 +020029 salt.enforceState(master, '*', ['linux.system'], true)
30 salt.enforceState(master, '*', ['salt.minion'], true)
Ales Komarekef2bab62017-04-26 11:48:28 +020031 salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'salt.minion', 'ntp'], true)
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
40 salt.enforceState(master, 'I@salt:control', ['salt.minion', 'linux.system', 'linux.network', 'ntp'], true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010041 salt.enforceState(master, 'I@salt:control', 'libvirt', true)
42 salt.enforceState(master, 'I@salt:control', 'salt.control', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010043
Ales Komarekef2bab62017-04-26 11:48:28 +020044 sleep(600)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010045
Marek Celoudc9b3cc82017-05-22 12:50:53 +000046 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.refresh_pillar', [], null, true)
47 salt.runSaltProcessStep(master, '* and not kvm*', 'saltutil.sync_all', [], null, true)
Tomáš Kukrál8d2be5a2017-02-28 11:22:29 +010048}
Jakub Josef79ecec32017-02-17 14:36:28 +010049
Ales Komarekef2bab62017-04-26 11:48:28 +020050def installOpenstackInfra(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +010051 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +020052
Jakub Josef79ecec32017-02-17 14:36:28 +010053 // Install glusterfs
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010054 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service', true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010055
Ales Komarekef2bab62017-04-26 11:48:28 +020056 // Install keepaliveds
57 //runSaltProcessStep(master, 'I@keepalived:cluster', 'state.sls', ['keepalived'], 1)
58 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived', true)
59 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived', true)
60
61 // Check the keepalived VIPs
62 salt.runSaltProcessStep(master, 'I@keepalived:cluster', 'cmd.run', ['ip a | grep 172.16.10.2'])
63
64 salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true)
65
66 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'], null, true)
67 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'], null, true)
Tomáš Kukrálb8e97112017-03-01 16:03:16 +010068
Jakub Josef79ecec32017-02-17 14:36:28 +010069 // Install rabbitmq
Ales Komarekef2bab62017-04-26 11:48:28 +020070 withEnv(['ASK_ON_ERROR=false']){
71 retry(2) {
72 salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true)
73 }
74 }
75
Jakub Josef79ecec32017-02-17 14:36:28 +010076 // Check the rabbitmq status
77 salt.runSaltProcessStep(master, 'I@rabbitmq:server', 'cmd.run', ['rabbitmqctl cluster_status'])
Ales Komarekef2bab62017-04-26 11:48:28 +020078
Jakub Josef79ecec32017-02-17 14:36:28 +010079 // Install galera
Ales Komarekef2bab62017-04-26 11:48:28 +020080 withEnv(['ASK_ON_ERROR=false']){
81 retry(2) {
82 salt.enforceState(master, 'I@galera:master', 'galera', true)
83 }
84 }
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010085 salt.enforceState(master, 'I@galera:slave', 'galera', true)
Ales Komarekef2bab62017-04-26 11:48:28 +020086
Jakub Josef79ecec32017-02-17 14:36:28 +010087 // Check galera status
88 salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
89 salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
Ales Komarekef2bab62017-04-26 11:48:28 +020090
91 // // Setup mysql client
92 // salt.enforceState(master, 'I@mysql:client', 'mysql.client', true)
93
Jakub Josef79ecec32017-02-17 14:36:28 +010094 // Install haproxy
Tomáš Kukrál0abdde52017-03-01 21:57:23 +010095 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy', true)
Jakub Josef79ecec32017-02-17 14:36:28 +010096 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
97 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
Ales Komarekef2bab62017-04-26 11:48:28 +020098
Jakub Josef79ecec32017-02-17 14:36:28 +010099 // Install memcached
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100100 salt.enforceState(master, 'I@memcached:server', 'memcached', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100101}
102
103
Ales Komarekef2bab62017-04-26 11:48:28 +0200104def installOpenstackControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100105 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200106
107 // Install horizon dashboard
108 salt.enforceState(master, 'I@horizon:server', 'horizon', true)
109 salt.enforceState(master, 'I@nginx:server', 'nginx', true)
110
Jakub Josef79ecec32017-02-17 14:36:28 +0100111 // setup keystone service
112 //runSaltProcessStep(master, 'I@keystone:server', 'state.sls', ['keystone.server'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200113 salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server', true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100114 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100115 // populate keystone services/tenants/roles/users
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100116
117 // keystone:client must be called locally
Ales Komarekef2bab62017-04-26 11:48:28 +0200118 //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
119 salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
120 sleep(30)
121 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
122 salt.enforceState(master, 'I@keystone:client', 'keystone.client', true)
123 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonercv3; openstack service list'], null, true)
Tomáš Kukrál926e6332017-03-02 09:23:03 +0100124
Jakub Josef79ecec32017-02-17 14:36:28 +0100125 // Install glance and ensure glusterfs clusters
126 //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200127 salt.enforceState(master, 'I@glance:server and *01*', 'glance.server', true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100128 salt.enforceState(master, 'I@glance:server', 'glance.server', true)
129 salt.enforceState(master, 'I@glance:server', 'glusterfs.client', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200130
Jakub Josef79ecec32017-02-17 14:36:28 +0100131 // Update fernet tokens before doing request on keystone server
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100132 salt.enforceState(master, 'I@keystone:server', 'keystone.server', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200133
Jakub Josef79ecec32017-02-17 14:36:28 +0100134 // Check glance service
Ales Komarekef2bab62017-04-26 11:48:28 +0200135 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; glance image-list'], null, true)
136
Jakub Josef79ecec32017-02-17 14:36:28 +0100137 // Install and check nova service
138 //runSaltProcessStep(master, 'I@nova:controller', 'state.sls', ['nova'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200139 salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller', true)
140 salt.enforceState(master, 'I@nova:controller', 'nova.controller', true)
141 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; nova service-list'], null, true)
142
Jakub Josef79ecec32017-02-17 14:36:28 +0100143 // Install and check cinder service
144 //runSaltProcessStep(master, 'I@cinder:controller', 'state.sls', ['cinder'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200145 salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder', true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100146 salt.enforceState(master, 'I@cinder:controller', 'cinder', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200147 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; cinder list'], null, true)
148
Jakub Josef79ecec32017-02-17 14:36:28 +0100149 // Install neutron service
150 //runSaltProcessStep(master, 'I@neutron:server', 'state.sls', ['neutron'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200151
152 salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server', true)
153 salt.enforceState(master, 'I@neutron:server', 'neutron.server', true)
154 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; neutron agent-list'], null, true)
155
Jakub Josef79ecec32017-02-17 14:36:28 +0100156 // Install heat service
157 //runSaltProcessStep(master, 'I@heat:server', 'state.sls', ['heat'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200158 salt.enforceState(master, 'I@heat:server and *01*', 'heat', true)
Tomáš Kukrál0abdde52017-03-01 21:57:23 +0100159 salt.enforceState(master, 'I@heat:server', 'heat', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200160 salt.runSaltProcessStep(master, 'I@keystone:server', 'cmd.run', ['. /root/keystonerc; heat resource-type-list'], null, true)
161
162 // Restart nova api
163 salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
Jakub Josef79ecec32017-02-17 14:36:28 +0100164}
165
166
Ales Komarekef2bab62017-04-26 11:48:28 +0200167def installOpenstackNetwork(master, physical = "false") {
Jakub Josef79ecec32017-02-17 14:36:28 +0100168 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200169
170 salt.runSaltProcessStep(master, 'I@neutron:gateway', 'state.apply', [], null, true)
171}
172
173
174def installOpenstackCompute(master) {
175 def salt = new com.mirantis.mk.Salt()
176
177 // Configure compute nodes
178 retry(2) {
Marek Celoude305ec72017-05-16 11:27:53 +0200179 salt.runSaltProcessStep(master, 'I@nova:compute', 'state.highstate', ['exclude=opencontrail.client'], null, true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200180 }
181}
182
183
184def installContrailNetwork(master) {
185 def salt = new com.mirantis.mk.Salt()
186
187
Jakub Josef79ecec32017-02-17 14:36:28 +0100188 // Install opencontrail database services
189 //runSaltProcessStep(master, 'I@opencontrail:database', 'state.sls', ['opencontrail.database'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200190 try {
191 salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database', true)
192 } catch (Exception e) {
193 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database and *01*')
194 }
195
196 try {
197 salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database', true)
198 } catch (Exception e) {
199 common.warningMsg('Exception in state opencontrail.database on I@opencontrail:database')
200 }
201
Jakub Josef79ecec32017-02-17 14:36:28 +0100202 // Install opencontrail control services
203 //runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail'], 1)
Ales Komarekef2bab62017-04-26 11:48:28 +0200204 salt.runSaltProcessStep(master, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
205 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
206 salt.runSaltProcessStep(master, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client'])
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100207
Jakub Josef79ecec32017-02-17 14:36:28 +0100208 // Test opencontrail
Ales Komarekef2bab62017-04-26 11:48:28 +0200209 salt.runSaltProcessStep(master, 'I@opencontrail:control', 'cmd.run', ['contrail-status'], null, true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100210}
211
212
Ales Komarekef2bab62017-04-26 11:48:28 +0200213def installContrailCompute(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100214 def salt = new com.mirantis.mk.Salt()
215 // Configure compute nodes
Ales Komarekef2bab62017-04-26 11:48:28 +0200216 // Provision opencontrail control services
217 salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100218 // Provision opencontrail virtual routers
Tomáš Kukrálb8e97112017-03-01 16:03:16 +0100219
Ales Komarekef2bab62017-04-26 11:48:28 +0200220 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)
221 sleep(300)
Marek Celoude305ec72017-05-16 11:27:53 +0200222 salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client', true)
Jakub Josef79ecec32017-02-17 14:36:28 +0100223}
224
225
Ales Komarekef2bab62017-04-26 11:48:28 +0200226def installKubernetesInfra(master) {
Tomáš Kukrál0ea82db2017-05-02 11:16:05 +0200227 def common = new com.mirantis.mk.Common()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200228 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200229
Jakub Josef79ecec32017-02-17 14:36:28 +0100230 // Install glusterfs
Tomáš Kukrál0ea82db2017-05-02 11:16:05 +0200231 if (common.checkContains('INSTALL', 'glusterfs')) {
232 salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service')
233 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200234
Jakub Josef79ecec32017-02-17 14:36:28 +0100235 // Install keepalived
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200236 salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived')
237 salt.enforceState(master, 'I@keepalived:cluster', 'keepalived')
Ales Komarekef2bab62017-04-26 11:48:28 +0200238
Jakub Josef79ecec32017-02-17 14:36:28 +0100239 // Setup glusterfs
Tomáš Kukrál0ea82db2017-05-02 11:16:05 +0200240 if (common.checkContains('INSTALL', 'glusterfs')) {
241 salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup')
242 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster peer status'])
243 salt.runSaltProcessStep(master, 'I@glusterfs:server', 'cmd.run', ['gluster volume status'])
244 }
Ales Komarekef2bab62017-04-26 11:48:28 +0200245
Jakub Josef79ecec32017-02-17 14:36:28 +0100246 // Install haproxy
Tomáš Kukrál7c99e322017-05-02 11:31:31 +0200247 salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
Jakub Josef79ecec32017-02-17 14:36:28 +0100248 salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200249
Jakub Josef79ecec32017-02-17 14:36:28 +0100250 // Install docker
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200251 salt.enforceState(master, 'I@docker:host', 'docker.host')
Jakub Josef79ecec32017-02-17 14:36:28 +0100252 salt.runSaltProcessStep(master, 'I@docker:host', 'cmd.run', ['docker ps'])
Ales Komarekef2bab62017-04-26 11:48:28 +0200253
Jakub Josef79ecec32017-02-17 14:36:28 +0100254 // Install etcd
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200255 salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
Ales Komarekef2bab62017-04-26 11:48:28 +0200256 salt.runSaltProcessStep(master, 'I@etcd:server', 'cmd.run', ['./var/lib/etcd/configenv && etcdctl cluster-health'])
257
Jakub Josef79ecec32017-02-17 14:36:28 +0100258}
259
260
Tomáš Kukrálc1a1bbc2017-04-28 21:16:25 +0200261def installKubernetesControl(master) {
Jakub Josef79ecec32017-02-17 14:36:28 +0100262 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200263
Jakub Josef79ecec32017-02-17 14:36:28 +0100264 // Install Kubernetes pool and Calico
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200265 salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
266 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
Jakub Josef79ecec32017-02-17 14:36:28 +0100267
268 // Setup etcd server
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200269 salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100270
271 // Run k8s without master.setup
272 salt.runSaltProcessStep(master, 'I@kubernetes:master', 'state.sls', ['kubernetes', 'exclude=kubernetes.master.setup'])
273
274 // Run k8s master setup
Tomáš Kukrálb05cf002017-05-02 11:05:43 +0200275 salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')
Jakub Josef79ecec32017-02-17 14:36:28 +0100276
277 // Restart kubelet
278 salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
279}
280
281
Ales Komarekef2bab62017-04-26 11:48:28 +0200282def installKubernetesCompute(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200283 def salt = new com.mirantis.mk.Salt()
Tomáš Kukrále7e28962017-06-06 11:11:16 +0200284
285 // Refresh minion's pillar data
286 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_pillar', [], null, true)
287 salt.runSaltProcessStep(master, '*', 'saltutil.sync_all', [], null, true)
288
289 // Bootstrap all nodes
290 salt.enforceState(master, 'I@kubernetes:pool', 'linux')
291 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
292 salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])
293
294 // Create and distribute SSL certificates for services using salt state
295 salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')
296
297 // Install docker
298 salt.enforceState(master, 'I@docker:host', 'docker.host')
299
300 // Install Kubernetes and Calico
301 salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')
302
303}
304
305
306def installKubernetesContrailCompute(master) {
307 def salt = new com.mirantis.mk.Salt()
Jakub Josef79ecec32017-02-17 14:36:28 +0100308 // Install opencontrail
309 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'state.sls', ['opencontrail'])
310 // Reboot compute nodes
311 salt.runSaltProcessStep(master, 'I@opencontrail:compute', 'system.reboot')
312}
313
314
315def installStacklightControl(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200316 def salt = new com.mirantis.mk.Salt()
Ales Komarekef2bab62017-04-26 11:48:28 +0200317
318 // infra install
319 // Install the StackLight backends
320 salt.enforceState(master, '*01* and I@elasticsearch:server', 'elasticsearch.server', true)
321 salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server', true)
322
323 salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb', true)
324 salt.enforceState(master, 'I@influxdb:server', 'influxdb', true)
325
326 salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server', true)
327 salt.enforceState(master, 'I@kibana:server', 'kibana.server', true)
328
329 salt.enforceState(master, '*01* and I@grafana:server','grafana.server', true)
330 salt.enforceState(master, 'I@grafana:server','grafana.server', true)
331
332 salt.enforceState(master, 'I@nagios:server', 'nagios.server', true)
333 salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service', true)
Marek Celoudebc623b2017-06-02 17:12:31 +0200334 salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
Ales Komarekef2bab62017-04-26 11:48:28 +0200335
336 sleep(10)
337}
338
339def installStacklightClient(master) {
Tomáš Kukrála53b5352017-05-04 11:45:53 +0200340 def salt = new com.mirantis.mk.Salt()
341 def common = new com.mirantis.mk.Common()
Ales Komarekef2bab62017-04-26 11:48:28 +0200342
343 salt.runSaltProcessStep(master, 'I@elasticsearch.client', 'cmd.run', ['salt-call state.sls elasticsearch.client'], null, true)
344 // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
345 salt.runSaltProcessStep(master, 'I@kibana.client', 'cmd.run', ['salt-call state.sls kibana.client'], null, true)
346 // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)
347
348 // Install collectd, heka and sensu services on the nodes, this will also
349 // generate the metadata that goes into the grains and eventually into Salt Mine
350 salt.enforceState(master, '*', 'collectd', true)
351 salt.enforceState(master, '*', 'salt.minion', true)
352 salt.enforceState(master, '*', 'heka', true)
353
354 // Gather the Grafana metadata as grains
355 salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)
356
357 // Update Salt Mine
358 salt.enforceState(master, '*', 'salt.minion.grains', true)
359 salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules', [], null, true)
360 salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
361
362 sleep(5)
363
364 // Update Heka
365 salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka', true)
366
367 // Update collectd
368 salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd', true)
369
370 // Update Nagios
371 salt.enforceState(master, 'I@nagios:server', 'nagios', true)
372 // Stop the Nagios service because the package starts it by default and it will
373 // started later only on the node holding the VIP address
374 salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
375
376 // Update Sensu
377 // TODO for stacklight team, should be fixed in model
378 //salt.enforceState(master, 'I@sensu:server', 'sensu', true)
379
Ales Komarekef2bab62017-04-26 11:48:28 +0200380 salt.runSaltProcessStep(master, 'I@grafana.client and *01*', 'cmd.run', ['salt-call state.sls grafana.client'], null, true)
381 // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)
382
Marek Celoudd200cad2017-06-07 10:34:46 +0200383 // Finalize the configuration of Grafana (add the dashboards...)
384 salt.enforceState(master, 'I@grafana:client', 'grafana.client', true)
385 // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10
386
Ales Komarekef2bab62017-04-26 11:48:28 +0200387 // Get the StackLight monitoring VIP addres
388 //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
389 //vip=${vip:=172.16.10.253}
390 def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
Jakub Josefbceaa322017-06-13 18:28:27 +0200391 common.prettyPrint(pillar)
Ales Komarekef2bab62017-04-26 11:48:28 +0200392 def stacklight_vip = pillar['return'][0].values()[0]
393
394 if (stacklight_vip) {
395 // (re)Start manually the services that are bound to the monitoring VIP
396 common.infoMsg("restart services on node with IP: ${stacklight_vip}")
397 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'], null, true)
398 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'], null, true)
399 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'], null, true)
400 salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'], null, true)
401 } else {
402 throw new Exception("Missing stacklight_vip")
403 }
Tomáš Kukrálf06ca0f2017-02-27 15:18:50 +0100404}