From 80f6ddf3d403d82277215ccebe3a6480ba539721 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 4 Jan 2012 12:47:40 -0800 Subject: [PATCH] Adds support for floating ip pools * Implements blueprint multiple-floating-ip-ranges * Adds pool and interface fields to floating ip tables * Adds extension to get a list of available pools * Optionally allows a pool to be specified when allocating * Changes nova-manage command to allow pool and interface * Ip binding uses the interface from table instead of flag * Adds default pool flag to use when pool is not specified * updates test to work with new fields * adds tests for extension Change-Id: Ieb4cbbf07b211697d08178b1cf2252caf75049a2 --- nova/db/api.py | 12 +++++++++--- nova/db/sqlalchemy/api.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/nova/db/api.py b/nova/db/api.py index e3ba9a1b5..5f9f9f43e 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -1,5 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. @@ -237,13 +238,18 @@ def floating_ip_get(context, id): return IMPL.floating_ip_get(context, id) -def floating_ip_allocate_address(context, project_id): - """Allocate free floating ip and return the address. +def floating_ip_get_pools(context): + """Returns a list of floating ip pools""" + return IMPL.floating_ip_get_pools(context) + + +def floating_ip_allocate_address(context, project_id, pool): + """Allocate free floating ip from specified pool and return the address. Raises if one is not available. """ - return IMPL.floating_ip_allocate_address(context, project_id) + return IMPL.floating_ip_allocate_address(context, project_id, pool) def floating_ip_create(context, values): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index eba393256..83a022292 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1,5 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. @@ -489,7 +490,16 @@ def floating_ip_get(context, id): @require_context -def floating_ip_allocate_address(context, project_id): +def floating_ip_get_pools(context): + session = get_session() + pools = [] + for result in session.query(models.FloatingIp.pool).distinct(): + pools.append({'name': result[0]}) + return pools + + +@require_context +def floating_ip_allocate_address(context, project_id, pool): authorize_project_context(context, project_id) session = get_session() with session.begin(): @@ -497,6 +507,7 @@ def floating_ip_allocate_address(context, project_id): session=session, read_deleted="no").\ filter_by(fixed_ip_id=None).\ filter_by(project_id=None).\ + filter_by(pool=pool).\ with_lockmode('update').\ first() # NOTE(vish): if with_lockmode isn't supported, as in sqlite,