Merge "Adds support for floating ip pools"

This commit is contained in:
Jenkins
2012-01-10 12:31:48 +00:00
committed by Gerrit Code Review
2 changed files with 21 additions and 4 deletions

View File

@@ -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):

View File

@@ -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,