From 5cced7a31482d014fe31f815f38fd00e079cc491 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Wed, 3 Apr 2013 16:22:12 +1100 Subject: Allow listing fixed_ips for a given compute host. nova.db.fixed_ip_get_all_by_instance_host was removed in commit bb867ce3948ddc23cf928ca3dda100a1a977896a, but was still used in nova-manage. This patch works around the removal of the foreign key that led to this method being removed. Resolves bug 1163660. Change-Id: Ieccd37c752e245558827615c098604d11ad3d945 --- nova/db/api.py | 5 +++++ nova/db/sqlalchemy/api.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index c1d28e33a..4a11d8b31 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -496,6 +496,11 @@ def fixed_ip_get_by_instance(context, instance_uuid): return IMPL.fixed_ip_get_by_instance(context, instance_uuid) +def fixed_ip_get_by_host(context, host): + """Get fixed ips by compute host.""" + return IMPL.fixed_ip_get_by_host(context, host) + + def fixed_ip_get_by_network_host(context, network_uuid, host): """Get fixed ip for a host in a network.""" return IMPL.fixed_ip_get_by_network_host(context, network_uuid, host) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 4224d9c06..e386919b3 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1225,6 +1225,20 @@ def fixed_ip_get_by_instance(context, instance_uuid): return result +@require_admin_context +def fixed_ip_get_by_host(context, host): + session = get_session() + with session.begin(): + instance_uuids = _instance_get_all_uuids_by_host(context, host, + session=session) + if not instance_uuids: + return [] + + return model_query(context, models.FixedIp, session=session).\ + filter(models.FixedIp.instance_uuid.in_(instance_uuids)).\ + all() + + @require_context def fixed_ip_get_by_network_host(context, network_id, host): result = model_query(context, models.FixedIp, read_deleted="no").\ @@ -1848,6 +1862,22 @@ def instance_get_all_by_host(context, host, columns_to_join=None): manual_joins=columns_to_join) +@require_admin_context +def _instance_get_all_uuids_by_host(context, host, session=None): + """Return a list of the instance uuids on a given host. + + Returns a list of UUIDs, not Instance model objects. This internal version + allows you to specify a session object as a kwarg. + """ + uuids = [] + for tuple in model_query(context, models.Instance.uuid, read_deleted="no", + base_model=models.Instance, session=session).\ + filter_by(host=host).\ + all(): + uuids.append(tuple[0]) + return uuids + + @require_admin_context def instance_get_all_by_host_and_node(context, host, node): return _instances_fill_metadata(context, @@ -4912,6 +4942,9 @@ def _get_default_deleted_value(table): # from the column, but I don't see a way to do that in the low-level APIs # of SQLAlchemy 0.7. 0.8 has better introspection APIs, which we should # use when Nova is ready to require 0.8. + + # NOTE(mikal): this is a little confusing. This method returns the value + # that a _not_deleted_ row would have. deleted_column_type = table.c.deleted.type if isinstance(deleted_column_type, Integer): return 0 -- cgit