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