blob: 7444e46aedbf1b2d167ff86d385578c037a41a6b [file] [log] [blame]
Yulia Portnova21289b22015-03-18 15:21:43 +02001import node
2
3from novaclient.client import Client
4
5
6def get_floating_ip(vm):
7 addrs = vm.addresses
8 for net_name, ifaces in addrs.items():
9 for iface in ifaces:
10 if iface.get('OS-EXT-IPS:type') == "floating":
11 return iface['addr']
12 raise Exception("No floating ip found for VM %s" % repr(vm))
13
14
15def discover_openstack_vms(conn_details):
16 """Discover vms running in openstack
17 :param conn_details - dict with openstack connection details -
18 auth_url, api_key (password), username
19 """
20 client = Client(version='1.1', **conn_details)
21 servers = client.servers.list(search_opts={"all_tenant": True})
22 return [node.Node(get_floating_ip(server), ["test_vm"])
23 for server in servers]
Yulia Portnova3556a062015-03-17 16:30:11 +020024
25
26def discover_openstack_nodes(conn_details):
27 """Discover openstack nodes
Yulia Portnova21289b22015-03-18 15:21:43 +020028 :param conn_details - dict with openstack connection details -
Yulia Portnova3556a062015-03-17 16:30:11 +020029 auth_url, api_key (password), username
30 """
Yulia Portnova21289b22015-03-18 15:21:43 +020031 client = Client(version='1.1', **conn_details)
32 services = client.services.list()
33 return [node.Node(server.ip, ["test_vm"]) for server in services]