From f1e19b46cb6efdcd4b446095ef5efcb2a7c8359c Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Wed, 24 Oct 2012 16:42:03 +1030 Subject: 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/ # GET ip info /v2/{tenant_id}/os-fixed-ips//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 --- nova/db/api.py | 5 +++++ nova/db/sqlalchemy/api.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'nova/db') 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): -- cgit