Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 1 | import logging |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 2 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 3 | from novaclient.client import Client |
| 4 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 5 | import node |
| 6 | from disk_perf_test_tool.utils import parse_creds |
| 7 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 8 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 9 | logger = logging.getLogger("io-perf-tool") |
| 10 | |
| 11 | |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 12 | def 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 Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 18 | |
| 19 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 20 | def discover_vms(client, search_opts): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 21 | user, password, key = parse_creds(search_opts.pop('auth')) |
| 22 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 23 | 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 | |
| 30 | def discover_services(client, opts): |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 31 | user, password, key = parse_creds(opts.pop('auth')) |
| 32 | |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 33 | 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 | |
| 56 | def discover_openstack_nodes(conn_details, conf): |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 57 | """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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 62 | 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 70 | |
| 71 | return nodes |
Yulia Portnova | 3556a06 | 2015-03-17 16:30:11 +0200 | [diff] [blame] | 72 | |
| 73 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 74 | # from disk_perf_test_tool.starts_vms import create_vms_mt |
| 75 | # def start_test_vms(client, opts): |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 76 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 77 | # 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 81 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 82 | # 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 Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 88 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 89 | # if aff_group is not None: |
| 90 | # scheduler_hints = {'group': aff_group} |
| 91 | # else: |
| 92 | # scheduler_hints = None |
Yulia Portnova | 0e64ea2 | 2015-03-20 17:27:22 +0200 | [diff] [blame] | 93 | |
koder aka kdanilov | e06762a | 2015-03-22 23:32:09 +0200 | [diff] [blame^] | 94 | # opts['scheduler_hints'] = scheduler_hints |
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 | # logger.debug("Will start {0} vms".format(count)) |
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 | # 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] |