blob: 558985da068bc4e54300cb942aa94db89fb2bfa5 [file] [log] [blame]
Yulia Portnova0e64ea22015-03-20 17:27:22 +02001import logging
koder aka kdanilove06762a2015-03-22 23:32:09 +02002
Yulia Portnova21289b22015-03-18 15:21:43 +02003from novaclient.client import Client
4
koder aka kdanilove06762a2015-03-22 23:32:09 +02005import node
6from disk_perf_test_tool.utils import parse_creds
7
Yulia Portnova21289b22015-03-18 15:21:43 +02008
Yulia Portnova0e64ea22015-03-20 17:27:22 +02009logger = logging.getLogger("io-perf-tool")
10
11
Yulia Portnova21289b22015-03-18 15:21:43 +020012def get_floating_ip(vm):
13 addrs = vm.addresses
14 for net_name, ifaces in addrs.items():
15 for iface in ifaces:
16 if iface.get('OS-EXT-IPS:type') == "floating":
17 return iface['addr']
Yulia Portnova21289b22015-03-18 15:21:43 +020018
19
Yulia Portnova0e64ea22015-03-20 17:27:22 +020020def discover_vms(client, search_opts):
koder aka kdanilove06762a2015-03-22 23:32:09 +020021 user, password, key = parse_creds(search_opts.pop('auth'))
22
Yulia Portnova0e64ea22015-03-20 17:27:22 +020023 servers = client.servers.list(search_opts=search_opts)
24 logger.debug("Found %s openstack vms" % len(servers))
25 return [node.Node(get_floating_ip(server), ["test_vm"], username=user,
26 password=password, key_path=key)
27 for server in servers if get_floating_ip(server)]
28
29
30def discover_services(client, opts):
koder aka kdanilove06762a2015-03-22 23:32:09 +020031 user, password, key = parse_creds(opts.pop('auth'))
32
Yulia Portnova0e64ea22015-03-20 17:27:22 +020033 services = []
34 if opts['service'] == "all":
35 services = client.services.list()
36 else:
37 if isinstance(opts['service'], basestring):
38 opts['service'] = [opts['service']]
39
40 for s in opts['service']:
41 services.extend(client.services.list(binary=s))
42
43 host_services_mapping = {}
44 for service in services:
45 if host_services_mapping.get(service.host):
46 host_services_mapping[service.host].append(service.binary)
47 else:
48 host_services_mapping[service.host] = [service.binary]
49 logger.debug("Found %s openstack service nodes" %
50 len(host_services_mapping))
51 return [node.Node(host, services, username=user,
52 password=password, key_path=key) for host, services in
53 host_services_mapping.items()]
54
55
56def discover_openstack_nodes(conn_details, conf):
Yulia Portnova21289b22015-03-18 15:21:43 +020057 """Discover vms running in openstack
58 :param conn_details - dict with openstack connection details -
59 auth_url, api_key (password), username
60 """
61 client = Client(version='1.1', **conn_details)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020062 nodes = []
63 if conf.get('discover'):
64 vms_to_discover = conf['discover'].get('vm')
65 if vms_to_discover:
66 nodes.extend(discover_vms(client, vms_to_discover))
67 services_to_discover = conf['discover'].get('nodes')
68 if services_to_discover:
69 nodes.extend(discover_services(client, services_to_discover))
Yulia Portnova0e64ea22015-03-20 17:27:22 +020070
71 return nodes
Yulia Portnova3556a062015-03-17 16:30:11 +020072
73
koder aka kdanilove06762a2015-03-22 23:32:09 +020074# from disk_perf_test_tool.starts_vms import create_vms_mt
75# def start_test_vms(client, opts):
Yulia Portnova0e64ea22015-03-20 17:27:22 +020076
koder aka kdanilove06762a2015-03-22 23:32:09 +020077# user = opts.pop("user", None)
78# key_file = opts.pop("key_file", None)
79# aff_group = opts.pop("aff_group", None)
80# raw_count = opts.pop('count')
Yulia Portnova0e64ea22015-03-20 17:27:22 +020081
koder aka kdanilove06762a2015-03-22 23:32:09 +020082# if raw_count.startswith("x"):
83# logger.debug("Getting amount of compute services")
84# count = len(client.services.list(binary="nova-compute"))
85# count *= int(raw_count[1:])
86# else:
87# count = int(raw_count)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020088
koder aka kdanilove06762a2015-03-22 23:32:09 +020089# if aff_group is not None:
90# scheduler_hints = {'group': aff_group}
91# else:
92# scheduler_hints = None
Yulia Portnova0e64ea22015-03-20 17:27:22 +020093
koder aka kdanilove06762a2015-03-22 23:32:09 +020094# opts['scheduler_hints'] = scheduler_hints
Yulia Portnova0e64ea22015-03-20 17:27:22 +020095
koder aka kdanilove06762a2015-03-22 23:32:09 +020096# logger.debug("Will start {0} vms".format(count))
Yulia Portnova0e64ea22015-03-20 17:27:22 +020097
koder aka kdanilove06762a2015-03-22 23:32:09 +020098# nodes = create_vms_mt(client, count, **opts)
99# return [node.Node(get_floating_ip(server), ["test_vm"], username=user,
100# key_path=key_file) for server in nodes]