blob: 6c02fe6f03b0d45361bd98c8ea78054ff09dc521 [file] [log] [blame]
Yulia Portnova0e64ea22015-03-20 17:27:22 +02001import logging
koder aka kdanilovcee43342015-04-14 22:52:53 +03002import urlparse
3
Yulia Portnova0e64ea22015-03-20 17:27:22 +02004import ceph
koder aka kdanilove06762a2015-03-22 23:32:09 +02005import openstack
gstepanovf1ff52d2015-04-07 15:54:33 +03006from utils import parse_creds
7from scripts import connector
Yulia Portnova0e64ea22015-03-20 17:27:22 +02008
9logger = logging.getLogger("io-perf-tool")
10
11
koder aka kdanilovcee43342015-04-14 22:52:53 +030012def discover(ctx, discover, clusters_info):
Yulia Portnova0e64ea22015-03-20 17:27:22 +020013 nodes_to_run = []
koder aka kdanilovda45e882015-04-06 02:24:42 +030014 for cluster in discover:
Yulia Portnova0e64ea22015-03-20 17:27:22 +020015 if cluster == "openstack":
koder aka kdanilovda45e882015-04-06 02:24:42 +030016 cluster_info = clusters_info["openstack"]
koder aka kdanilove06762a2015-03-22 23:32:09 +020017 conn = cluster_info['connection']
18 user, passwd, tenant = parse_creds(conn['creds'])
19
20 auth_data = dict(
21 auth_url=conn['auth_url'],
22 username=user,
23 api_key=passwd,
24 project_id=tenant)
25
Yulia Portnova0e64ea22015-03-20 17:27:22 +020026 if not conn:
27 logger.error("No connection provided for %s. Skipping"
28 % cluster)
29 continue
koder aka kdanilove06762a2015-03-22 23:32:09 +020030
Yulia Portnova0e64ea22015-03-20 17:27:22 +020031 logger.debug("Discovering openstack nodes "
32 "with connection details: %r" %
33 conn)
34
koder aka kdanilove06762a2015-03-22 23:32:09 +020035 os_nodes = openstack.discover_openstack_nodes(auth_data,
36 cluster_info)
37 nodes_to_run.extend(os_nodes)
38
koder aka kdanilovcee43342015-04-14 22:52:53 +030039 elif cluster == "fuel":
koder aka kdanilovda45e882015-04-06 02:24:42 +030040 cluster_info = clusters_info['fuel']
gstepanov59d80f72015-04-10 17:24:27 +030041 cluster_name = cluster_info['openstack_env']
koder aka kdanilovda45e882015-04-06 02:24:42 +030042 url = cluster_info['url']
43 creds = cluster_info['creds']
44 ssh_creds = cluster_info['ssh_creds']
koder aka kdanilovcee43342015-04-14 22:52:53 +030045
koder aka kdanilovda45e882015-04-06 02:24:42 +030046 # if user:password format us used
47 if not ssh_creds.startswith("ssh://"):
48 ip_port = urlparse.urlparse(url).netloc
koder aka kdanilovcee43342015-04-14 22:52:53 +030049
koder aka kdanilovda45e882015-04-06 02:24:42 +030050 if ':' in ip_port:
51 ip = ip_port.split(":")[0]
52 else:
53 ip = ip_port
koder aka kdanilove06762a2015-03-22 23:32:09 +020054
koder aka kdanilovda45e882015-04-06 02:24:42 +030055 ssh_creds = "ssh://{0}@{1}".format(ssh_creds, ip)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020056
koder aka kdanilovcee43342015-04-14 22:52:53 +030057 dfunc = connector.discover_fuel_nodes
58 nodes, clean_data, openrc_dict = dfunc(url, creds, cluster_name)
gstepanov59d80f72015-04-10 17:24:27 +030059
koder aka kdanilovcee43342015-04-14 22:52:53 +030060 ctx.fuel_openstack_creds = {'name': openrc_dict['username'],
61 'passwd': openrc_dict['password'],
62 'tenant': openrc_dict['tenant_name'],
63 'auth_url': openrc_dict['os_auth_url']}
gstepanov59d80f72015-04-10 17:24:27 +030064
65 nodes_to_run.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +030066
67 elif cluster == "ceph":
68 cluster_info = clusters_info["ceph"]
koder aka kdanilov2c473092015-03-29 17:12:13 +030069 nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info))
koder aka kdanilovda45e882015-04-06 02:24:42 +030070 else:
71 msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}"
72 raise ValueError(msg_templ.format(cluster))
koder aka kdanilov2c473092015-03-29 17:12:13 +030073
Yulia Portnova0e64ea22015-03-20 17:27:22 +020074 return nodes_to_run