When vpn=true in allocate ip, it attempts to allocate the ip that is reserved in the network. Unfortunately fixed_ip_associate attempts to ignore reserved ips.

This fix allows to filter reserved ip address only when vpn=True.
This commit is contained in:
Tushar Patil 2011-09-12 02:11:43 +00:00 committed by Tarmac
commit ff0e970530
2 changed files with 11 additions and 4 deletions
nova/db
api.py
sqlalchemy

@ -324,13 +324,15 @@ def migration_get_by_instance_and_status(context, instance_uuid, status):
####################
def fixed_ip_associate(context, address, instance_id, network_id=None):
def fixed_ip_associate(context, address, instance_id, network_id=None,
reserved=False):
"""Associate fixed ip to instance.
Raises if fixed ip is not available.
"""
return IMPL.fixed_ip_associate(context, address, instance_id, network_id)
return IMPL.fixed_ip_associate(context, address, instance_id, network_id,
reserved)
def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None):

@ -669,14 +669,19 @@ def floating_ip_update(context, address, values):
@require_admin_context
def fixed_ip_associate(context, address, instance_id, network_id=None):
def fixed_ip_associate(context, address, instance_id, network_id=None,
reserved=False):
"""Keyword arguments:
reserved -- should be a boolean value(True or False), exact value will be
used to filter on the fixed ip address
"""
session = get_session()
with session.begin():
network_or_none = or_(models.FixedIp.network_id == network_id,
models.FixedIp.network_id == None)
fixed_ip_ref = session.query(models.FixedIp).\
filter(network_or_none).\
filter_by(reserved=False).\
filter_by(reserved=reserved).\
filter_by(deleted=False).\
filter_by(address=address).\
with_lockmode('update').\