Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 1 | import logging |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 2 | import ceph |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 3 | import openstack |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 4 | |
gstepanov | f1ff52d | 2015-04-07 15:54:33 +0300 | [diff] [blame] | 5 | from utils import parse_creds |
| 6 | from scripts import connector |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame^] | 7 | import urlparse |
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 | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 12 | def discover(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 | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 39 | elif cluster == "fuel" or cluster == "fuel+openstack": |
| 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'] |
| 45 | # if user:password format us used |
| 46 | if not ssh_creds.startswith("ssh://"): |
| 47 | ip_port = urlparse.urlparse(url).netloc |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 48 | if ':' in ip_port: |
| 49 | ip = ip_port.split(":")[0] |
| 50 | else: |
| 51 | ip = ip_port |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 52 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 53 | ssh_creds = "ssh://{0}@{1}".format(ssh_creds, ip) |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 54 | |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 55 | env = cluster_info['openstack_env'] |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame^] | 56 | 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 kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 75 | |
| 76 | elif cluster == "ceph": |
| 77 | cluster_info = clusters_info["ceph"] |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 78 | nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 79 | else: |
| 80 | msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}" |
| 81 | raise ValueError(msg_templ.format(cluster)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 82 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 83 | return nodes_to_run |