Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 1 | import logging |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 2 | import urlparse |
| 3 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 4 | import ceph |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 5 | import openstack |
gstepanov | f1ff52d | 2015-04-07 15:54:33 +0300 | [diff] [blame] | 6 | from utils import parse_creds |
| 7 | from scripts import connector |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 8 | |
| 9 | logger = logging.getLogger("io-perf-tool") |
| 10 | |
| 11 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 12 | def discover(ctx, discover, clusters_info): |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 13 | nodes_to_run = [] |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 14 | for cluster in discover: |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 15 | if cluster == "openstack": |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 16 | cluster_info = clusters_info["openstack"] |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 17 | 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 26 | if not conn: |
| 27 | logger.error("No connection provided for %s. Skipping" |
| 28 | % cluster) |
| 29 | continue |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 30 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 31 | logger.debug("Discovering openstack nodes " |
| 32 | "with connection details: %r" % |
| 33 | conn) |
| 34 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 35 | os_nodes = openstack.discover_openstack_nodes(auth_data, |
| 36 | cluster_info) |
| 37 | nodes_to_run.extend(os_nodes) |
| 38 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 39 | elif cluster == "fuel": |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 40 | cluster_info = clusters_info['fuel'] |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame] | 41 | cluster_name = cluster_info['openstack_env'] |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 42 | url = cluster_info['url'] |
| 43 | creds = cluster_info['creds'] |
| 44 | ssh_creds = cluster_info['ssh_creds'] |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 45 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 46 | # if user:password format us used |
| 47 | if not ssh_creds.startswith("ssh://"): |
| 48 | ip_port = urlparse.urlparse(url).netloc |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 49 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 50 | if ':' in ip_port: |
| 51 | ip = ip_port.split(":")[0] |
| 52 | else: |
| 53 | ip = ip_port |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 54 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 55 | ssh_creds = "ssh://{0}@{1}".format(ssh_creds, ip) |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 56 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 57 | dfunc = connector.discover_fuel_nodes |
| 58 | nodes, clean_data, openrc_dict = dfunc(url, creds, cluster_name) |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame] | 59 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame^] | 60 | 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']} |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame] | 64 | |
| 65 | nodes_to_run.extend(nodes) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 66 | |
| 67 | elif cluster == "ceph": |
| 68 | cluster_info = clusters_info["ceph"] |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 69 | nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 70 | else: |
| 71 | msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}" |
| 72 | raise ValueError(msg_templ.format(cluster)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 73 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 74 | return nodes_to_run |