blob: 216f30d4426c8ac5dadb23cf21a83990c4a87947 [file] [log] [blame]
Ved-vampira915a012015-03-18 14:38:52 +03001""" Collect data about ceph nodes"""
2import json
3
Ved-vampir29931712015-03-18 16:31:02 +03004from node import Node
koder aka kdanilove06762a2015-03-22 23:32:09 +02005from disk_perf_test_tool.ext_libs import sh
Ved-vampira915a012015-03-18 14:38:52 +03006
7
8def discover_ceph_node():
9 """ Return list of ceph's nodes ips """
Ved-vampira915a012015-03-18 14:38:52 +030010 ips = {}
koder aka kdanilove06762a2015-03-22 23:32:09 +020011
12 osd_ips = get_osds_ips(get_osds_list())
Ved-vampira915a012015-03-18 14:38:52 +030013 mon_ips = get_mons_or_mds_ips("mon")
14 mds_ips = get_mons_or_mds_ips("mds")
koder aka kdanilove06762a2015-03-22 23:32:09 +020015
Ved-vampira915a012015-03-18 14:38:52 +030016 for ip in osd_ips:
17 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020018 ips.setdefault(url, []).append("ceph-osd")
19
Ved-vampira915a012015-03-18 14:38:52 +030020 for ip in mon_ips:
21 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020022 ips.setdefault(url, []).append("ceph-mon")
23
Ved-vampira915a012015-03-18 14:38:52 +030024 for ip in mds_ips:
25 url = "ssh://%s" % ip
koder aka kdanilove06762a2015-03-22 23:32:09 +020026 ips.setdefault(url, []).append("ceph-mds")
Ved-vampira915a012015-03-18 14:38:52 +030027
koder aka kdanilove06762a2015-03-22 23:32:09 +020028 return [Node(ip=url, roles=list(roles)) for url, roles in ips.items()]
Ved-vampira915a012015-03-18 14:38:52 +030029
30
31def get_osds_list():
32 """ Get list of osds id"""
koder aka kdanilove06762a2015-03-22 23:32:09 +020033 return filter(None, sh.ceph.osd.ls().split("\n"))
Ved-vampira915a012015-03-18 14:38:52 +030034
35
36def get_mons_or_mds_ips(who):
37 """ Return mon ip list
38 :param who - "mon" or "mds" """
koder aka kdanilove06762a2015-03-22 23:32:09 +020039 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-vampira915a012015-03-18 14:38:52 +030046
koder aka kdanilove06762a2015-03-22 23:32:09 +020047 line_res = res.split("\n")
48 ips = set()
Ved-vampira915a012015-03-18 14:38:52 +030049
koder aka kdanilove06762a2015-03-22 23:32:09 +020050 for line in line_res:
51 fields = line.split()
Ved-vampira915a012015-03-18 14:38:52 +030052
koder aka kdanilove06762a2015-03-22 23:32:09 +020053 # 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-vampira915a012015-03-18 14:38:52 +030061
62
63def get_osds_ips(osd_list):
koder aka kdanilove06762a2015-03-22 23:32:09 +020064 """ Get osd's ips
Ved-vampira915a012015-03-18 14:38:52 +030065 :param osd_list - list of osd names from osd ls command"""
koder aka kdanilove06762a2015-03-22 23:32:09 +020066 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