Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 1 | import node |
| 2 | |
| 3 | from novaclient.client import Client |
| 4 | |
| 5 | |
| 6 | def 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 | |
| 15 | def 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 Portnova | 3556a06 | 2015-03-17 16:30:11 +0200 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def discover_openstack_nodes(conn_details): |
| 27 | """Discover openstack nodes |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 28 | :param conn_details - dict with openstack connection details - |
Yulia Portnova | 3556a06 | 2015-03-17 16:30:11 +0200 | [diff] [blame] | 29 | auth_url, api_key (password), username |
| 30 | """ |
Yulia Portnova | 21289b2 | 2015-03-18 15:21:43 +0200 | [diff] [blame] | 31 | client = Client(version='1.1', **conn_details) |
| 32 | services = client.services.list() |
| 33 | return [node.Node(server.ip, ["test_vm"]) for server in services] |