summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2013-04-03 16:22:12 +1100
committerMichael Still <mikal@stillhq.com>2013-04-15 03:39:44 +1000
commit5cced7a31482d014fe31f815f38fd00e079cc491 (patch)
treecd5598f6ba4a17c8bc432225307c791367dfb7ef /nova/db
parent497b42372d820bb9bf2c9dfd482e5abf9ef1f940 (diff)
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
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py5
-rw-r--r--nova/db/sqlalchemy/api.py33
2 files changed, 38 insertions, 0 deletions
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").\
@@ -1849,6 +1863,22 @@ def instance_get_all_by_host(context, host, columns_to_join=None):
@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,
_instance_get_all_query(context, joins=[]).filter_by(host=host).
@@ -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