blob: a59f365a52e01bd6bff887643777e993ddb83983 [file] [log] [blame]
Yulia Portnova0e64ea22015-03-20 17:27:22 +02001import logging
Yulia Portnova0e64ea22015-03-20 17:27:22 +02002import ceph
koder aka kdanilove06762a2015-03-22 23:32:09 +02003import openstack
Yulia Portnova0e64ea22015-03-20 17:27:22 +02004
gstepanovf1ff52d2015-04-07 15:54:33 +03005from utils import parse_creds
6from scripts import connector
gstepanov59d80f72015-04-10 17:24:27 +03007import urlparse
Yulia Portnova0e64ea22015-03-20 17:27:22 +02008
9logger = logging.getLogger("io-perf-tool")
10
11
koder aka kdanilovda45e882015-04-06 02:24:42 +030012def discover(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 kdanilovda45e882015-04-06 02:24:42 +030039 elif cluster == "fuel" or cluster == "fuel+openstack":
40 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']
45 # if user:password format us used
46 if not ssh_creds.startswith("ssh://"):
47 ip_port = urlparse.urlparse(url).netloc
koder aka kdanilovda45e882015-04-06 02:24:42 +030048 if ':' in ip_port:
49 ip = ip_port.split(":")[0]
50 else:
51 ip = ip_port
koder aka kdanilove06762a2015-03-22 23:32:09 +020052
koder aka kdanilovda45e882015-04-06 02:24:42 +030053 ssh_creds = "ssh://{0}@{1}".format(ssh_creds, ip)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020054
koder aka kdanilovda45e882015-04-06 02:24:42 +030055 env = cluster_info['openstack_env']
gstepanov59d80f72015-04-10 17:24:27 +030056 nodes, _, openrc_dict = connector.discover_fuel_nodes(url, creds, cluster_name)
57
58 if 'openstack' not in clusters_info:
59 clusters_info['openstack'] = {}
60
61 for key in openrc_dict:
62 if key == 'OS_AUTH_URL':
63 url = urlparse.urlparse(openrc_dict[key])
64 clusters_info['openstack'][key] = \
65 url.scheme + '://' + \
66 cluster_info['ext_ip'] \
67 + ':' +\
68 str(url.port) +\
69 url.path
70 else:
71 clusters_info['openstack'][key] = \
72 openrc_dict[key]
73
74 nodes_to_run.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +030075
76 elif cluster == "ceph":
77 cluster_info = clusters_info["ceph"]
koder aka kdanilov2c473092015-03-29 17:12:13 +030078 nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info))
koder aka kdanilovda45e882015-04-06 02:24:42 +030079 else:
80 msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}"
81 raise ValueError(msg_templ.format(cluster))
koder aka kdanilov2c473092015-03-29 17:12:13 +030082
Yulia Portnova0e64ea22015-03-20 17:27:22 +020083 return nodes_to_run