blob: 3cd5cfff80a7d501d3304b3195735f58344cd3cc [file] [log] [blame]
koder aka kdanilov168f6092015-04-19 02:33:38 +03001import os.path
Yulia Portnova0e64ea22015-03-20 17:27:22 +02002import logging
koder aka kdanilovcee43342015-04-14 22:52:53 +03003
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03004from . import ceph
5from . import fuel
6from . import openstack
7from wally.utils import parse_creds
Yulia Portnova0e64ea22015-03-20 17:27:22 +02008
9
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030010logger = logging.getLogger("wally.discover")
11
12
koder aka kdanilov168f6092015-04-19 02:33:38 +030013openrc_templ = """#!/bin/sh
14export LC_ALL=C
15export OS_NO_CACHE='true'
16export OS_TENANT_NAME='{tenant}'
17export OS_USERNAME='{name}'
18export OS_PASSWORD='{passwd}'
19export OS_AUTH_URL='{auth_url}'
20export OS_AUTH_STRATEGY='keystone'
21export OS_REGION_NAME='RegionOne'
22export CINDER_ENDPOINT_TYPE='publicURL'
23export GLANCE_ENDPOINT_TYPE='publicURL'
24export KEYSTONE_ENDPOINT_TYPE='publicURL'
25export NOVA_ENDPOINT_TYPE='publicURL'
26export NEUTRON_ENDPOINT_TYPE='publicURL'
27"""
28
29
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030030def discover(ctx, discover, clusters_info, var_dir):
Yulia Portnova0e64ea22015-03-20 17:27:22 +020031 nodes_to_run = []
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030032 clean_data = None
koder aka kdanilovda45e882015-04-06 02:24:42 +030033 for cluster in discover:
Yulia Portnova0e64ea22015-03-20 17:27:22 +020034 if cluster == "openstack":
koder aka kdanilovda45e882015-04-06 02:24:42 +030035 cluster_info = clusters_info["openstack"]
koder aka kdanilove06762a2015-03-22 23:32:09 +020036 conn = cluster_info['connection']
37 user, passwd, tenant = parse_creds(conn['creds'])
38
39 auth_data = dict(
40 auth_url=conn['auth_url'],
41 username=user,
42 api_key=passwd,
43 project_id=tenant)
44
Yulia Portnova0e64ea22015-03-20 17:27:22 +020045 if not conn:
46 logger.error("No connection provided for %s. Skipping"
47 % cluster)
48 continue
koder aka kdanilove06762a2015-03-22 23:32:09 +020049
Yulia Portnova0e64ea22015-03-20 17:27:22 +020050 logger.debug("Discovering openstack nodes "
51 "with connection details: %r" %
52 conn)
53
koder aka kdanilove06762a2015-03-22 23:32:09 +020054 os_nodes = openstack.discover_openstack_nodes(auth_data,
55 cluster_info)
56 nodes_to_run.extend(os_nodes)
57
koder aka kdanilovcee43342015-04-14 22:52:53 +030058 elif cluster == "fuel":
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030059 res = fuel.discover_fuel_nodes(clusters_info['fuel'], var_dir)
60 nodes, clean_data, openrc_dict = res
gstepanov59d80f72015-04-10 17:24:27 +030061
koder aka kdanilovcee43342015-04-14 22:52:53 +030062 ctx.fuel_openstack_creds = {'name': openrc_dict['username'],
63 'passwd': openrc_dict['password'],
64 'tenant': openrc_dict['tenant_name'],
65 'auth_url': openrc_dict['os_auth_url']}
gstepanov59d80f72015-04-10 17:24:27 +030066
koder aka kdanilov168f6092015-04-19 02:33:38 +030067 env_name = clusters_info['fuel']['openstack_env']
68 env_f_name = env_name
69 for char in "-+ {}()[]":
70 env_f_name = env_f_name.replace(char, '_')
71
72 fuel_openrc_fname = os.path.join(var_dir,
73 env_f_name + "_openrc")
74 with open(fuel_openrc_fname, "w") as fd:
75 fd.write(openrc_templ.format(**ctx.fuel_openstack_creds))
76 msg = "Openrc for cluster {0} saves into {1}"
77 logger.debug(msg.format(env_name, fuel_openrc_fname))
gstepanov59d80f72015-04-10 17:24:27 +030078 nodes_to_run.extend(nodes)
koder aka kdanilovda45e882015-04-06 02:24:42 +030079
80 elif cluster == "ceph":
81 cluster_info = clusters_info["ceph"]
koder aka kdanilov2c473092015-03-29 17:12:13 +030082 nodes_to_run.extend(ceph.discover_ceph_nodes(cluster_info))
koder aka kdanilovda45e882015-04-06 02:24:42 +030083 else:
84 msg_templ = "Unknown cluster type in 'discover' parameter: {0!r}"
85 raise ValueError(msg_templ.format(cluster))
koder aka kdanilov2c473092015-03-29 17:12:13 +030086
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +030087 return nodes_to_run, clean_data
88
89
90def undiscover(clean_data):
91 if clean_data is not None:
92 fuel.clean_fuel_port_forwarding(clean_data)