Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 1 | """ Collect data about ceph nodes""" |
| 2 | import json |
| 3 | |
Ved-vampir | 2993171 | 2015-03-18 16:31:02 +0300 | [diff] [blame] | 4 | from node import Node |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 5 | from disk_perf_test_tool.ext_libs import sh |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 6 | |
| 7 | |
| 8 | def discover_ceph_node(): |
| 9 | """ Return list of ceph's nodes ips """ |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 10 | ips = {} |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 11 | |
| 12 | osd_ips = get_osds_ips(get_osds_list()) |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 13 | mon_ips = get_mons_or_mds_ips("mon") |
| 14 | mds_ips = get_mons_or_mds_ips("mds") |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 15 | |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 16 | for ip in osd_ips: |
| 17 | url = "ssh://%s" % ip |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 18 | ips.setdefault(url, []).append("ceph-osd") |
| 19 | |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 20 | for ip in mon_ips: |
| 21 | url = "ssh://%s" % ip |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 22 | ips.setdefault(url, []).append("ceph-mon") |
| 23 | |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 24 | for ip in mds_ips: |
| 25 | url = "ssh://%s" % ip |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 26 | ips.setdefault(url, []).append("ceph-mds") |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 27 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 28 | return [Node(ip=url, roles=list(roles)) for url, roles in ips.items()] |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def get_osds_list(): |
| 32 | """ Get list of osds id""" |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 33 | return filter(None, sh.ceph.osd.ls().split("\n")) |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 34 | |
| 35 | |
| 36 | def get_mons_or_mds_ips(who): |
| 37 | """ Return mon ip list |
| 38 | :param who - "mon" or "mds" """ |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 39 | if who == "mon": |
| 40 | res = sh.ceph.mon.dump() |
| 41 | elif who == "mds": |
| 42 | res = sh.ceph.mds.dump() |
| 43 | else: |
| 44 | raise ValueError(("'%s' in get_mons_or_mds_ips instead" + |
| 45 | "of mon/mds") % who) |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 46 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 47 | line_res = res.split("\n") |
| 48 | ips = set() |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 49 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 50 | for line in line_res: |
| 51 | fields = line.split() |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 52 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 53 | # what does fields[1], fields[2] means? |
| 54 | # make this code looks like: |
| 55 | # SOME_MENINGFULL_VAR1, SOME_MENINGFULL_VAR2 = line.split()[1:3] |
| 56 | |
| 57 | if len(fields) > 2 and who in fields[2]: |
| 58 | ips.add(fields[1].split(":")[0]) |
| 59 | |
| 60 | return ips |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 61 | |
| 62 | |
| 63 | def get_osds_ips(osd_list): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 64 | """ Get osd's ips |
Ved-vampir | a915a01 | 2015-03-18 14:38:52 +0300 | [diff] [blame] | 65 | :param osd_list - list of osd names from osd ls command""" |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 66 | ips = set() |
| 67 | for osd_id in osd_list: |
| 68 | res = sh.ceph.osd.find(osd_id) |
| 69 | ip = json.loads(str(res))["ip"] |
| 70 | ips.add(ip.split(":")[0]) |
| 71 | return ips |