From 04df5837a388c9b38172b24a2eeb6c2b8830d0aa Mon Sep 17 00:00:00 2001 From: spisarski Date: Thu, 3 Aug 2017 11:44:16 -0600 Subject: Refactor server retrieval API calls. Refactored nova_utils#get_servers_by_name() to get_server() and include a VmInstSettings object in addition to the server_name parameter as well as only returning one VmInst object. JIRA: SNAPS-168 Change-Id: I30c22a36b07ce143ee8c1c76a77fd75f0062e4aa Signed-off-by: spisarski --- snaps/openstack/utils/nova_utils.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'snaps/openstack/utils/nova_utils.py') diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index a0c028a..2e73201 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -106,19 +106,26 @@ def create_server(nova, neutron, glance, instance_settings, image_settings, image_settings.name) -def get_servers_by_name(nova, name): +def get_server(nova, vm_inst_settings=None, server_name=None): """ - Returns a list of servers with a given name + Returns a VmInst object for the first server instance found. :param nova: the Nova client - :param name: the server name - :return: the list of snaps.domain.VmInst objects - """ - out = list() - servers = nova.servers.list(search_opts={'name': name}) + :param vm_inst_settings: the VmInstanceSettings object from which to build + the query if not None + :param server_name: the server with this name to return if vm_inst_settings + is not None + :return: a snaps.domain.VmInst object or None if not found + """ + search_opts = dict() + if vm_inst_settings: + search_opts['name'] = vm_inst_settings.name + elif server_name: + search_opts['name'] = server_name + + servers = nova.servers.list(search_opts=search_opts) for server in servers: - out.append(VmInst(name=server.name, inst_id=server.id, - networks=server.networks)) - return out + return VmInst(name=server.name, inst_id=server.id, + networks=server.networks) def __get_latest_server_os_object(nova, server): -- cgit 1.2.3-korg