blob: d212283cc70bdbedb0430b36e7dde2aec142e252 [file] [log] [blame]
koder aka kdanilov3a6633e2015-03-26 18:20:00 +02001import socket
Yulia Portnova0e64ea22015-03-20 17:27:22 +02002import logging
koder aka kdanilove06762a2015-03-22 23:32:09 +02003
koder aka kdanilov3a6633e2015-03-26 18:20:00 +02004
Yulia Portnova21289b22015-03-18 15:21:43 +02005from novaclient.client import Client
6
koder aka kdanilove06762a2015-03-22 23:32:09 +02007import node
8from disk_perf_test_tool.utils import parse_creds
9
Yulia Portnova21289b22015-03-18 15:21:43 +020010
Yulia Portnova0e64ea22015-03-20 17:27:22 +020011logger = logging.getLogger("io-perf-tool")
12
13
Yulia Portnova21289b22015-03-18 15:21:43 +020014def get_floating_ip(vm):
15 addrs = vm.addresses
16 for net_name, ifaces in addrs.items():
17 for iface in ifaces:
18 if iface.get('OS-EXT-IPS:type') == "floating":
19 return iface['addr']
Yulia Portnova21289b22015-03-18 15:21:43 +020020
21
Yulia Portnova0e64ea22015-03-20 17:27:22 +020022def discover_vms(client, search_opts):
koder aka kdanilove06762a2015-03-22 23:32:09 +020023 user, password, key = parse_creds(search_opts.pop('auth'))
24
Yulia Portnova0e64ea22015-03-20 17:27:22 +020025 servers = client.servers.list(search_opts=search_opts)
26 logger.debug("Found %s openstack vms" % len(servers))
27 return [node.Node(get_floating_ip(server), ["test_vm"], username=user,
28 password=password, key_path=key)
29 for server in servers if get_floating_ip(server)]
30
31
32def discover_services(client, opts):
koder aka kdanilove06762a2015-03-22 23:32:09 +020033 user, password, key = parse_creds(opts.pop('auth'))
34
Yulia Portnova0e64ea22015-03-20 17:27:22 +020035 services = []
36 if opts['service'] == "all":
37 services = client.services.list()
38 else:
39 if isinstance(opts['service'], basestring):
40 opts['service'] = [opts['service']]
41
42 for s in opts['service']:
43 services.extend(client.services.list(binary=s))
44
45 host_services_mapping = {}
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020046
Yulia Portnova0e64ea22015-03-20 17:27:22 +020047 for service in services:
koder aka kdanilov3a6633e2015-03-26 18:20:00 +020048 ip = socket.gethostbyname(service.host)
49 host_services_mapping[ip].append(service.binary)
50
Yulia Portnova0e64ea22015-03-20 17:27:22 +020051 logger.debug("Found %s openstack service nodes" %
52 len(host_services_mapping))
53 return [node.Node(host, services, username=user,
54 password=password, key_path=key) for host, services in
55 host_services_mapping.items()]
56
57
58def discover_openstack_nodes(conn_details, conf):
Yulia Portnova21289b22015-03-18 15:21:43 +020059 """Discover vms running in openstack
60 :param conn_details - dict with openstack connection details -
61 auth_url, api_key (password), username
62 """
63 client = Client(version='1.1', **conn_details)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020064 nodes = []
65 if conf.get('discover'):
koder aka kdanilovda45e882015-04-06 02:24:42 +030066 # vms_to_discover = conf['discover'].get('vm')
67 # if vms_to_discover:
68 # nodes.extend(discover_vms(client, vms_to_discover))
Yulia Portnova0e64ea22015-03-20 17:27:22 +020069 services_to_discover = conf['discover'].get('nodes')
70 if services_to_discover:
71 nodes.extend(discover_services(client, services_to_discover))
Yulia Portnova0e64ea22015-03-20 17:27:22 +020072
73 return nodes
Yulia Portnova3556a062015-03-17 16:30:11 +020074
75
koder aka kdanilove06762a2015-03-22 23:32:09 +020076# from disk_perf_test_tool.starts_vms import create_vms_mt
77# def start_test_vms(client, opts):
Yulia Portnova0e64ea22015-03-20 17:27:22 +020078
koder aka kdanilove06762a2015-03-22 23:32:09 +020079# user = opts.pop("user", None)
80# key_file = opts.pop("key_file", None)
81# aff_group = opts.pop("aff_group", None)
82# raw_count = opts.pop('count')
Yulia Portnova0e64ea22015-03-20 17:27:22 +020083
koder aka kdanilove06762a2015-03-22 23:32:09 +020084# if raw_count.startswith("x"):
85# logger.debug("Getting amount of compute services")
86# count = len(client.services.list(binary="nova-compute"))
87# count *= int(raw_count[1:])
88# else:
89# count = int(raw_count)
Yulia Portnova0e64ea22015-03-20 17:27:22 +020090
koder aka kdanilove06762a2015-03-22 23:32:09 +020091# if aff_group is not None:
92# scheduler_hints = {'group': aff_group}
93# else:
94# scheduler_hints = None
Yulia Portnova0e64ea22015-03-20 17:27:22 +020095
koder aka kdanilove06762a2015-03-22 23:32:09 +020096# opts['scheduler_hints'] = scheduler_hints
Yulia Portnova0e64ea22015-03-20 17:27:22 +020097
koder aka kdanilove06762a2015-03-22 23:32:09 +020098# logger.debug("Will start {0} vms".format(count))
Yulia Portnova0e64ea22015-03-20 17:27:22 +020099
koder aka kdanilove06762a2015-03-22 23:32:09 +0200100# nodes = create_vms_mt(client, count, **opts)
101# return [node.Node(get_floating_ip(server), ["test_vm"], username=user,
102# key_path=key_file) for server in nodes]