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 | |
| 23 | node("python") { |
| 24 | |
| 25 | stage('Load cluster information') { |
| 26 | // create connection to salt master |
| 27 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 28 | |
| 29 | // get list of disk from grains |
| 30 | def grains = salt.getGrain(saltMaster, 'I@ceph:osd')['return'][0] |
| 31 | |
| 32 | |
| 33 | } |
| 34 | |
| 35 | stage('Enforce weights on OSDs') { |
| 36 | |
| 37 | for (host in grains) { |
| 38 | // parse grains |
| 39 | def hostGrains = host.value |
| 40 | common.prettyPrint(hostGrains) |
| 41 | |
| 42 | def hostname = hostGrains.host |
| 43 | def salt_id = hostGrains.id |
| 44 | def ceph_host_id = hostGrains.ceph_osd_host_id |
| 45 | |
| 46 | common.infoMsg("Setting weights on host ${hostname} (${salt_id}), ceph_id ${ceph_host_id}") |
| 47 | for (disk in hostGrains.ceph_osd_disk) { |
| 48 | def osd_id = ceph_host_id + disk.key |
| 49 | print(osd_id) |
| 50 | print(disk.value) |
| 51 | print(disk.key) |
| 52 | def cmd = "ceph osd crush set ${osd_id} ${disk.value.weight} host=${hostname}" |
| 53 | print(runCephCommand(saltMaster, cmd)) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | } |