blob: ac102eb4dafee5c141cd490b301a0e5cb69c3d40 [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(',')
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020022def osds = OSD.tokenize(',')
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020023
24def runCephCommand(master, cmd) {
25 return salt.cmdRun(master, ADMIN_HOST, cmd)
26}
27
28node("python") {
29
30 // create connection to salt master
31 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
32
33 if (flags.size() > 0) {
34 stage('Set cluster flags') {
35 for (flag in flags) {
36 runCephCommand(saltMaster, 'ceph osd set ' + flag)
37 }
38 }
39 }
40
41 // get list of disk at the osd
42 def pillar_disks = salt.getPillar(saltMaster, HOST, 'ceph:osd:disk')['return'][0].values()[0]
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020043 def hostname_id = salt.getPillar(saltMaster, HOST, 'ceph:osd:host_id')['return'][0].values()[0]
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020044 def osd_ids = []
45
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020046 print("host_id is ${hostname_id}")
47 print("osds:")
48 print(osds)
49
50 for (i in pillar_disks) {
51 def osd_id = (hostname_id + i.key).toInteger().toString()
52 print("Evaluating ${osd_id}")
Tomáš Kukrál00e06912017-08-16 13:33:12 +020053 if (osd_id in osds || OSD == '*') {
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020054 osd_ids.add('osd.' + osd_id)
Tomáš Kukrálacadfb52017-08-18 19:07:42 +020055 print("Will delete " + osd_id)
56 } else {
57 print("Skipping " + osd_id)
Tomáš Kukrál9d6228b2017-08-15 16:54:55 +020058 }
Tomáš Kukrálf72096d2017-08-11 12:58:03 +020059 }
60
61 // `ceph osd out <id> <id>`
62 stage('Set OSDs out') {
63 runCephCommand(saltMaster, 'ceph osd out ' + osd_ids.join(' '))
64 }
65
66 // wait for healthy cluster
67 if (common.validInputParam('WAIT_FOR_HEALTHY') && WAIT_FOR_HEALTHY.toBoolean()) {
68 stage('Waiting for healthy cluster') {
69 while (true) {
70 def health = runCephCommand(saltMaster, 'ceph health')['return'][0].values()[0]
71 if (health.contains('HEALTH OK')) {
72 common.infoMsg('Cluster is healthy')
73 break;
74 }
75 sleep(60)
76 }
77 }
78 }
79
80 // stop osd daemons
81 stage('Stop OSD daemons') {
82 for (i in osd_ids) {
83 salt.runSaltProcessStep(saltMaster, HOST, 'service.stop', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
84 }
85 }
86
87 // `ceph osd crush remove osd.2`
88 stage('Remove OSDs from CRUSH') {
89 for (i in osd_ids) {
90 runCephCommand(saltMaster, 'ceph osd crush remove ' + i)
91 }
92 }
93
94 // remove keyring `ceph auth del osd.3`
95 stage('Remove OSD keyrings from auth') {
96 for (i in osd_ids) {
97 runCephCommand(saltMaster, 'ceph auth del ' + i)
98 }
99 }
100
101 // remove osd `ceph osd rm osd.3`
102 stage('Remove OSDs') {
103 for (i in osd_ids) {
104 runCephCommand(saltMaster, 'ceph osd rm ' + i)
105 }
106 }
107
108 // remove cluster flags
109 if (flags.size() > 0) {
110 stage('Unset cluster flags') {
111 for (flag in flags) {
112 common.infoMsg('Removing flag ' + flag)
113 runCephCommand(saltMaster, 'ceph osd unset ' + flag)
114 }
115 }
116 }
117
118}