summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorChris Yeoh <cyeoh@au1.ibm.com>2012-10-24 16:42:03 +1030
committerChris Yeoh <cyeoh@au1.ibm.com>2012-11-13 23:56:40 +1030
commitf1e19b46cb6efdcd4b446095ef5efcb2a7c8359c (patch)
treec06deebf9c7acd1efc9a39537e698d579293a1a1 /nova/db
parent3c9e48d1119b77428346680c2a009c44ff9bf2ce (diff)
Adds REST API support for Fixed IPs
This adds an extension that provides a REST API for getting information about a fixed ip, reserving a fixed ip and unreserving a fixed ip. The interface is accessed via /v2/{tenant_id}/os-fixed-ips/<ip_address> # GET ip info /v2/{tenant_id}/os-fixed-ips/<ip_address>/action # POST reserve/unreserve ip This forms part of the work to provide APIs for functionality currently implemented by nova-manage that needs direct db access so nova-manage can eventually be removed Adds db function fixed_ip_get_by_address_detailed in order to optimise being able to get the instance and network information for a fixed ip at the same time as the rest of the fixed ip information Change-Id: I92edf4e6b74b14bb9c49d5bc0c79e40d3a496bc5 Implements: blueprint apis-for-nova-manage DocImpact
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py5
-rw-r--r--nova/db/sqlalchemy/api.py23
2 files changed, 28 insertions, 0 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 04786a1fb..45686d9ef 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -466,6 +466,11 @@ def fixed_ip_get_by_address(context, address):
return IMPL.fixed_ip_get_by_address(context, address)
+def fixed_ip_get_by_address_detailed(context, address):
+ """Get detailed fixed ip info by address or raise if it does not exist."""
+ return IMPL.fixed_ip_get_by_address_detailed(context, address)
+
+
def fixed_ip_get_by_instance(context, instance_uuid):
"""Get fixed ips by instance or raise if none exist."""
return IMPL.fixed_ip_get_by_instance(context, instance_uuid)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 72caad74d..bc92aaa62 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1151,6 +1151,29 @@ def fixed_ip_get_by_address(context, address, session=None):
return result
+@require_admin_context
+def fixed_ip_get_by_address_detailed(context, address, session=None):
+ # This method returns a tuple of (models.FixedIp, models.Network,
+ # models.Instance).
+ if not session:
+ session = get_session()
+
+ result = session.query(models.FixedIp, models.Network, models.Instance).\
+ filter_by(address=address).\
+ outerjoin((models.Network,
+ models.Network.id ==
+ models.FixedIp.network_id)).\
+ outerjoin((models.Instance,
+ models.Instance.uuid ==
+ models.FixedIp.instance_uuid)).\
+ first()
+
+ if not result:
+ raise exception.FixedIpNotFoundForAddress(address=address)
+
+ return result
+
+
@require_context
def fixed_ip_get_by_instance(context, instance_uuid):
if not uuidutils.is_uuid_like(instance_uuid):