Tomáš Kukrál | 13a7091 | 2017-08-18 17:14:09 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 13 | common = new com.mirantis.mk.Common() |
| 14 | salt = new com.mirantis.mk.Salt() |
| 15 | |
| 16 | // configure global variables |
| 17 | def saltMaster |
| 18 | |
| 19 | def runCephCommand(master, cmd) { |
| 20 | return salt.cmdRun(master, ADMIN_HOST, cmd) |
| 21 | } |
| 22 | |
Tomáš Kukrál | d6dcabe | 2017-08-18 19:30:09 +0200 | [diff] [blame] | 23 | def grains |
| 24 | |
Tomáš Kukrál | 13a7091 | 2017-08-18 17:14:09 +0200 | [diff] [blame] | 25 | node("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ál | d6dcabe | 2017-08-18 19:30:09 +0200 | [diff] [blame] | 32 | grains = salt.getGrain(saltMaster, 'I@ceph:osd')['return'][0] |
Tomáš Kukrál | 8c96e54 | 2017-08-18 19:36:00 +0200 | [diff] [blame] | 33 | common.prettyPrint(grains) |
Tomáš Kukrál | 13a7091 | 2017-08-18 17:14:09 +0200 | [diff] [blame] | 34 | |
| 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 | } |