blob: 8c783873945661f48af71cd8d7992d0753164a07 [file] [log] [blame]
Yulia Portnova0e64ea22015-03-20 17:27:22 +02001import logging
koder aka kdanilovcee43342015-04-14 22:52:53 +03002
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03003from . import ceph
4from . import fuel
5from . import openstack
6from wally.utils import parse_creds
Yulia Portnova0e64ea22015-03-20 17:27:22 +02007
8
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03009logger = logging.getLogger("wally.discover")
10
11
12def discover(ctx, discover, clusters_info, var_dir):
Yulia Portnova0e64ea22015-03-20 17:27:22 +020013 nodes_to_run = []
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030014 clean_data = None
koder aka kdanilovda45e882015-04-06 02:24:42 +030015 for cluster in discover:
Yulia Portnova0e64ea22015-03-20 17:27:22 +020016 if cluster == "openstack":
koder aka kdanilovda45e882015-04-06 02:24:42 +030017 cluster_info = clusters_info["openstack"]
koder aka kdanilove06762a2015-03-22 23:32:09 +020018 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 Portnova0e64ea22015-03-20 17:27:22 +020027 if not conn:
28 logger.error("No connection provided for %s. Skipping"
29 % cluster)
30 continue
koder aka kdanilove06762a2015-03-22 23:32:09 +020031
Yulia Portnova0e64ea22015-03-20 17:27:22 +020032 logger.debug("Discovering openstack nodes "
33 "with connection details: %r" %
34 conn)
35
koder aka kdanilove06762a2015-03-22 23:32:09 +020036 os_nodes = openstack.discover_openstack_nodes(auth_data,
37 cluster_info)
38 nodes_to_run.extend(os_nodes)
39
koder aka kdanilovcee43342015-04-14 22:52:53 +030040 elif cluster == "fuel":
koder aka kdanilovcee43342015-04-14 22:52:53 +030041
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030042 res = fuel.discover_fuel_nodes(clusters_info['fuel'], var_dir)
43 nodes, clean_data, openrc_dict = res
gstepanov59d80f72015-04-10 17:24:27 +030044
koder aka kdanilovcee43342015-04-14 22:52:53 +030045 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']}
gstepanov59d80f72015-04-10 17:24:27 +030049
50 nodes_to_run.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +030051
52 elif cluster == "ceph":
53 cluster_info = clusters_info["ceph"]
koder aka kdanilov2c473092015-03-29 17:12:13 +030054 nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info))
koder aka kdanilovda45e882015-04-06 02:24:42 +030055 else:
56 msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}"
57 raise ValueError(msg_templ.format(cluster))
koder aka kdanilov2c473092015-03-29 17:12:13 +030058
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030059 return nodes_to_run, clean_data
60
61
62def undiscover(clean_data):
63 if clean_data is not None:
64 fuel.clean_fuel_port_forwarding(clean_data)