koder aka kdanilov | 3a6633e | 2015-03-26 18:20:00 +0200 | [diff] [blame] | 1 | import socket |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 2 | import logging |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 3 | |
koder aka kdanilov | 3a6633e | 2015-03-26 18:20:00 +0200 | [diff] [blame] | 4 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 5 | from novaclient.client import Client |
| 6 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 7 | import node |
| 8 | from disk_perf_test_tool.utils import parse_creds |
| 9 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 10 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 11 | logger = logging.getLogger("io-perf-tool") |
| 12 | |
| 13 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 14 | def 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 Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 20 | |
| 21 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 22 | def discover_vms(client, search_opts): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 23 | user, password, key = parse_creds(search_opts.pop('auth')) |
| 24 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 25 | 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 | |
| 32 | def discover_services(client, opts): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 33 | user, password, key = parse_creds(opts.pop('auth')) |
| 34 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 35 | 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 kdanilov | 3a6633e | 2015-03-26 18:20:00 +0200 | [diff] [blame] | 46 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 47 | for service in services: |
koder aka kdanilov | 3a6633e | 2015-03-26 18:20:00 +0200 | [diff] [blame] | 48 | ip = socket.gethostbyname(service.host) |
| 49 | host_services_mapping[ip].append(service.binary) |
| 50 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 51 | 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 | |
| 58 | def discover_openstack_nodes(conn_details, conf): |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 59 | """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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 64 | nodes = [] |
| 65 | if conf.get('discover'): |
koder aka kdanilov | da45e88 | 2015-04-06 02:24:42 +0300 | [diff] [blame] | 66 | # vms_to_discover = conf['discover'].get('vm') |
| 67 | # if vms_to_discover: |
| 68 | # nodes.extend(discover_vms(client, vms_to_discover)) |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 69 | services_to_discover = conf['discover'].get('nodes') |
| 70 | if services_to_discover: |
| 71 | nodes.extend(discover_services(client, services_to_discover)) |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 72 | |
| 73 | return nodes |
Yulia Portnova | 3556a06 | 2015-03-17 16:30:11 +0200 | [diff] [blame] | 74 | |
| 75 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 76 | # from disk_perf_test_tool.starts_vms import create_vms_mt |
| 77 | # def start_test_vms(client, opts): |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 78 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 79 | # 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 83 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 84 | # 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 90 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 91 | # if aff_group is not None: |
| 92 | # scheduler_hints = {'group': aff_group} |
| 93 | # else: |
| 94 | # scheduler_hints = None |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 95 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 96 | # opts['scheduler_hints'] = scheduler_hints |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 97 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 98 | # logger.debug("Will start {0} vms".format(count)) |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 99 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame] | 100 | # 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] |