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