blob: b171855487a53e81b0251093c85cf29a4c3e5ac5 [file] [log] [blame]
Tomáš Kukrálf72096d2017-08-11 12:58:03 +02001/**
2 *
3 * Remove OSD from existing cluster
4 *
5 * Requred parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 * HOST Host (minion id) to be removed
10 * ADMIN_HOST Host (minion id) with admin keyring
11 * CLUSTER_FLAGS Comma separated list of tags to apply to cluster
12 * WAIT_FOR_HEALTHY Wait for cluster rebalance before stoping daemons
13 *
14 */
15
16common = new com.mirantis.mk.Common()
17salt = new com.mirantis.mk.Salt()
18
19// configure global variables
20def saltMaster
21def flags = CLUSTER_FLAGS.tokenize(',')
22
23def runCephCommand(master, cmd) {
24 return salt.cmdRun(master, ADMIN_HOST, cmd)
25}
26
27node("python") {
28
29 // create connection to salt master
30 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
31
32 if (flags.size() > 0) {
33 stage('Set cluster flags') {
34 for (flag in flags) {
35 runCephCommand(saltMaster, 'ceph osd set ' + flag)
36 }
37 }
38 }
39
40 // get list of disk at the osd
41 def pillar_disks = salt.getPillar(saltMaster, HOST, 'ceph:osd:disk')['return'][0].values()[0]
42 def hostname = salt.getPillar(saltMaster, HOST, 'linux:system:name')['return'][0].values()[0]
43 def hostname_id = hostname.replaceAll('osd', '')
44 def osd_ids = []
45
46 for (i in pillar_disks.keySet()) {
47 osd_ids.add('osd.' + (hostname_id + i).toInteger())
48 }
49
50 // `ceph osd out <id> <id>`
51 stage('Set OSDs out') {
52 runCephCommand(saltMaster, 'ceph osd out ' + osd_ids.join(' '))
53 }
54
55 // wait for healthy cluster
56 if (common.validInputParam('WAIT_FOR_HEALTHY') && WAIT_FOR_HEALTHY.toBoolean()) {
57 stage('Waiting for healthy cluster') {
58 while (true) {
59 def health = runCephCommand(saltMaster, 'ceph health')['return'][0].values()[0]
60 if (health.contains('HEALTH OK')) {
61 common.infoMsg('Cluster is healthy')
62 break;
63 }
64 sleep(60)
65 }
66 }
67 }
68
69 // stop osd daemons
70 stage('Stop OSD daemons') {
71 for (i in osd_ids) {
72 salt.runSaltProcessStep(saltMaster, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
73 }
74 }
75
76 // `ceph osd crush remove osd.2`
77 stage('Remove OSDs from CRUSH') {
78 for (i in osd_ids) {
79 runCephCommand(saltMaster, 'ceph osd crush remove ' + i)
80 }
81 }
82
83 // remove keyring `ceph auth del osd.3`
84 stage('Remove OSD keyrings from auth') {
85 for (i in osd_ids) {
86 runCephCommand(saltMaster, 'ceph auth del ' + i)
87 }
88 }
89
90 // remove osd `ceph osd rm osd.3`
91 stage('Remove OSDs') {
92 for (i in osd_ids) {
93 runCephCommand(saltMaster, 'ceph osd rm ' + i)
94 }
95 }
96
97 // remove cluster flags
98 if (flags.size() > 0) {
99 stage('Unset cluster flags') {
100 for (flag in flags) {
101 common.infoMsg('Removing flag ' + flag)
102 runCephCommand(saltMaster, 'ceph osd unset ' + flag)
103 }
104 }
105 }
106
107}