blob: 38ce17763b7bc9890ca3ff9195863e8e525eb7aa [file] [log] [blame]
Ved-vampira915a012015-03-18 14:38:52 +03001""" Collect data about ceph nodes"""
2import json
koder aka kdanilov3a6633e2015-03-26 18:20:00 +02003import logging
4
Ved-vampira915a012015-03-18 14:38:52 +03005
Ved-vampir29931712015-03-18 16:31:02 +03006from node import Node
koder aka kdanilov3a6633e2015-03-26 18:20:00 +02007from disk_perf_test_tool.ssh_utils import connect
Ved-vampira915a012015-03-18 14:38:52 +03008
9
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020010logger = logging.getLogger("io-perf-tool")
11
12
13def discover_ceph_node(ip):
Ved-vampira915a012015-03-18 14:38:52 +030014 """ Return list of ceph's nodes ips """
Ved-vampira915a012015-03-18 14:38:52 +030015 ips = {}
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020016 ssh = connect(ip)
koder aka kdanilove06762a2015-03-22 23:32:09 +020017
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020018 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 kdanilove06762a2015-03-22 23:32:09 +020021
Ved-vampira915a012015-03-18 14:38:52 +030022 for ip in osd_ips:
23 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020024 ips.setdefault(url, []).append("ceph-osd")
25
Ved-vampira915a012015-03-18 14:38:52 +030026 for ip in mon_ips:
27 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020028 ips.setdefault(url, []).append("ceph-mon")
29
Ved-vampira915a012015-03-18 14:38:52 +030030 for ip in mds_ips:
31 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020032 ips.setdefault(url, []).append("ceph-mds")
Ved-vampira915a012015-03-18 14:38:52 +030033
koder aka kdanilove06762a2015-03-22 23:32:09 +020034 return [Node(ip=url, roles=list(roles)) for url, roles in ips.items()]
Ved-vampira915a012015-03-18 14:38:52 +030035
36
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020037def get_osds_list(ssh):
Ved-vampira915a012015-03-18 14:38:52 +030038 """ Get list of osds id"""
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020039 _, chan, _ = ssh.exec_command("ceph osd ls")
40 return filter(None, chan.read().split("\n"))
Ved-vampira915a012015-03-18 14:38:52 +030041
42
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020043def get_mons_or_mds_ips(ssh, who):
Ved-vampira915a012015-03-18 14:38:52 +030044 """ Return mon ip list
45 :param who - "mon" or "mds" """
koder aka kdanilove06762a2015-03-22 23:32:09 +020046 if who == "mon":
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020047 _, chan, _ = ssh.exec_command("ceph mon dump")
koder aka kdanilove06762a2015-03-22 23:32:09 +020048 elif who == "mds":
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020049 _, chan, _ = ssh.exec_command("ceph mds dump")
koder aka kdanilove06762a2015-03-22 23:32:09 +020050 else:
51 raise ValueError(("'%s' in get_mons_or_mds_ips instead" +
52 "of mon/mds") % who)
Ved-vampira915a012015-03-18 14:38:52 +030053
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020054 line_res = chan.read().split("\n")
koder aka kdanilove06762a2015-03-22 23:32:09 +020055 ips = set()
Ved-vampira915a012015-03-18 14:38:52 +030056
koder aka kdanilove06762a2015-03-22 23:32:09 +020057 for line in line_res:
58 fields = line.split()
Ved-vampira915a012015-03-18 14:38:52 +030059
koder aka kdanilove06762a2015-03-22 23:32:09 +020060 # 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-vampira915a012015-03-18 14:38:52 +030068
69
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020070def get_osds_ips(ssh, osd_list):
koder aka kdanilove06762a2015-03-22 23:32:09 +020071 """ Get osd's ips
Ved-vampira915a012015-03-18 14:38:52 +030072 :param osd_list - list of osd names from osd ls command"""
koder aka kdanilove06762a2015-03-22 23:32:09 +020073 ips = set()
74 for osd_id in osd_list:
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020075 _, chan, _ = ssh.exec_command("ceph osd find {0}".format(osd_id))
76 ip = json.loads(chan.read())["ip"]
koder aka kdanilove06762a2015-03-22 23:32:09 +020077 ips.add(ip.split(":")[0])
78 return ips