blob: 4e063225384d2eb2886476123313e3861a5379f6 [file] [log] [blame]
Tomáš Kukrál13a70912017-08-18 17:14:09 +02001/**
2 *
3 * Enforce OSD weights from model
4 *
5 * Requred parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 * ADMIN_HOST Host (minion id) with admin keyring
10 *
11 */
12
13common = new com.mirantis.mk.Common()
14salt = new com.mirantis.mk.Salt()
15
16// configure global variables
17def saltMaster
18
19def runCephCommand(master, cmd) {
20 return salt.cmdRun(master, ADMIN_HOST, cmd)
21}
22
Tomáš Kukráld6dcabe2017-08-18 19:30:09 +020023def grains
24
Tomáš Kukrál13a70912017-08-18 17:14:09 +020025node("python") {
26
27 stage('Load cluster information') {
28 // create connection to salt master
29 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
30
31 // get list of disk from grains
Tomáš Kukráld6dcabe2017-08-18 19:30:09 +020032 grains = salt.getGrain(saltMaster, 'I@ceph:osd')['return'][0]
Tomáš Kukrál8c96e542017-08-18 19:36:00 +020033 common.prettyPrint(grains)
Tomáš Kukrál13a70912017-08-18 17:14:09 +020034
35 }
36
37 stage('Enforce weights on OSDs') {
38
39 for (host in grains) {
40 // parse grains
41 def hostGrains = host.value
42 common.prettyPrint(hostGrains)
43
44 def hostname = hostGrains.host
45 def salt_id = hostGrains.id
46 def ceph_host_id = hostGrains.ceph_osd_host_id
47
48 common.infoMsg("Setting weights on host ${hostname} (${salt_id}), ceph_id ${ceph_host_id}")
49 for (disk in hostGrains.ceph_osd_disk) {
50 def osd_id = ceph_host_id + disk.key
51 print(osd_id)
52 print(disk.value)
53 print(disk.key)
54 def cmd = "ceph osd crush set ${osd_id} ${disk.value.weight} host=${hostname}"
55 print(runCephCommand(saltMaster, cmd))
56 }
57 }
58
59 }
60}