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 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 3 | from . import ceph |
| 4 | from . import fuel |
| 5 | from . import openstack |
| 6 | from wally.utils import parse_creds |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 7 | |
| 8 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 9 | logger = logging.getLogger("wally.discover") |
| 10 | |
| 11 | |
| 12 | def discover(ctx, discover, clusters_info, var_dir): |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 13 | nodes_to_run = [] |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 14 | clean_data = None |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 15 | for cluster in discover: |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 16 | if cluster == "openstack": |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 17 | cluster_info = clusters_info["openstack"] |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 18 | conn = cluster_info['connection'] |
| 19 | user, passwd, tenant = parse_creds(conn['creds']) |
| 20 | |
| 21 | auth_data = dict( |
| 22 | auth_url=conn['auth_url'], |
| 23 | username=user, |
| 24 | api_key=passwd, |
| 25 | project_id=tenant) |
| 26 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 27 | if not conn: |
| 28 | logger.error("No connection provided for %s. Skipping" |
| 29 | % cluster) |
| 30 | continue |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 31 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 32 | logger.debug("Discovering openstack nodes " |
| 33 | "with connection details: %r" % |
| 34 | conn) |
| 35 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 36 | os_nodes = openstack.discover_openstack_nodes(auth_data, |
| 37 | cluster_info) |
| 38 | nodes_to_run.extend(os_nodes) |
| 39 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 40 | elif cluster == "fuel": |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 41 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 42 | res = fuel.discover_fuel_nodes(clusters_info['fuel'], var_dir) |
| 43 | nodes, clean_data, openrc_dict = res |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame] | 44 | |
koder aka kdanilov | cee4334 | 2015-04-14 22:52:53 +0300 | [diff] [blame] | 45 | ctx.fuel_openstack_creds = {'name': openrc_dict['username'], |
| 46 | 'passwd': openrc_dict['password'], |
| 47 | 'tenant': openrc_dict['tenant_name'], |
| 48 | 'auth_url': openrc_dict['os_auth_url']} |
gstepanov | 59d80f7 | 2015-04-10 17:24:27 +0300 | [diff] [blame] | 49 | |
| 50 | nodes_to_run.extend(nodes) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 51 | |
| 52 | elif cluster == "ceph": |
| 53 | cluster_info = clusters_info["ceph"] |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 54 | nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info)) |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 55 | else: |
| 56 | msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}" |
| 57 | raise ValueError(msg_templ.format(cluster)) |
koder aka kdanilov | 2c47309 | 2015-03-29 17:12:13 +0300 | [diff] [blame] | 58 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 59 | return nodes_to_run, clean_data |
| 60 | |
| 61 | |
| 62 | def undiscover(clean_data): |
| 63 | if clean_data is not None: |
| 64 | fuel.clean_fuel_port_forwarding(clean_data) |