Node class
diff --git a/nodes/fuel.py b/nodes/fuel.py
index 20390aa..76dedcd 100644
--- a/nodes/fuel.py
+++ b/nodes/fuel.py
@@ -1,3 +1,4 @@
+import node
import fuel_rest_api
@@ -6,4 +7,4 @@
connection = fuel_rest_api.KeystoneAuth(root_url, credentials)
fi = fuel_rest_api.FuelInfo(connection)
- return fi.nodes
\ No newline at end of file
+ return [node.Node(n.ip, n.get_roles()) for n in fi.nodes]
\ No newline at end of file
diff --git a/nodes/node.py b/nodes/node.py
new file mode 100644
index 0000000..4ee2109
--- /dev/null
+++ b/nodes/node.py
@@ -0,0 +1,33 @@
+class Node(object):
+
+ def __init__(self, ip, roles, username=None,
+ password=None, key_path=None, port=None):
+ self.roles = roles
+ self.ip = ip
+ self.username = username
+ self.password = password
+ self.port = port
+ self.key_path = key_path
+
+ def set_conn_attr(self, name, value):
+ setattr(self, name, value)
+
+ @property
+ def connection(self):
+ connection = []
+
+ if self.username:
+ connection.append(self.username)
+ if self.password:
+ connection.extend([":", self.password, "@"])
+ connection.append("@")
+
+ connection.append(self.ip)
+ if self.port:
+ connection.extend([":", self.port])
+ if self.key_path:
+ connection.extend([":", self.key_path])
+ else:
+ if self.key_path:
+ connection.extend([":", ":", self.key_path])
+ return "".join(connection)
diff --git a/nodes/openstack.py b/nodes/openstack.py
index 8b425cb..7444e46 100644
--- a/nodes/openstack.py
+++ b/nodes/openstack.py
@@ -1,11 +1,33 @@
-from novaclient.v1_1 import client as novacl
+import node
+
+from novaclient.client import Client
+
+
+def get_floating_ip(vm):
+ addrs = vm.addresses
+ for net_name, ifaces in addrs.items():
+ for iface in ifaces:
+ if iface.get('OS-EXT-IPS:type') == "floating":
+ return iface['addr']
+ raise Exception("No floating ip found for VM %s" % repr(vm))
+
+
+def discover_openstack_vms(conn_details):
+ """Discover vms running in openstack
+ :param conn_details - dict with openstack connection details -
+ auth_url, api_key (password), username
+ """
+ client = Client(version='1.1', **conn_details)
+ servers = client.servers.list(search_opts={"all_tenant": True})
+ return [node.Node(get_floating_ip(server), ["test_vm"])
+ for server in servers]
def discover_openstack_nodes(conn_details):
"""Discover openstack nodes
- :param connection_details - dict with openstack connection details -
+ :param conn_details - dict with openstack connection details -
auth_url, api_key (password), username
"""
- client = novacl.Client(**conn_details)
- servers = client.servers.list(search_opts={"all_tenant": True})
- return servers
+ client = Client(version='1.1', **conn_details)
+ services = client.services.list()
+ return [node.Node(server.ip, ["test_vm"]) for server in services]