Merge "Fix inconsistent usages for network resources"

This commit is contained in:
Jenkins
2013-09-09 15:03:00 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 13 deletions

View File

@@ -214,7 +214,8 @@ class FloatingIP(object):
# called into from other places
try:
if use_quota:
reservations = QUOTAS.reserve(context, floating_ips=1)
reservations = QUOTAS.reserve(context, floating_ips=1,
project_id=project_id)
except exception.OverQuota:
LOG.warn(_("Quota exceeded for %s, tried to allocate "
"floating IP"), context.project_id)
@@ -229,11 +230,12 @@ class FloatingIP(object):
# Commit the reservations
if use_quota:
QUOTAS.commit(context, reservations)
QUOTAS.commit(context, reservations, project_id=project_id)
except Exception:
with excutils.save_and_reraise_exception():
if use_quota:
QUOTAS.rollback(context, reservations)
QUOTAS.rollback(context, reservations,
project_id=project_id)
return floating_ip
@@ -263,10 +265,13 @@ class FloatingIP(object):
floating_ip=floating_ip['address'])
self.notifier.info(context, 'network.floating_ip.deallocate', payload)
project_id = floating_ip['project_id']
# Get reservations...
try:
if use_quota:
reservations = QUOTAS.reserve(context, floating_ips=-1)
reservations = QUOTAS.reserve(context,
project_id=project_id,
floating_ips=-1)
else:
reservations = None
except Exception:
@@ -278,7 +283,7 @@ class FloatingIP(object):
# Commit the reservations
if reservations:
QUOTAS.commit(context, reservations)
QUOTAS.commit(context, reservations, project_id=project_id)
@rpc_common.client_exceptions(exception.FloatingIpNotFoundForAddress)
def associate_floating_ip(self, context, floating_address, fixed_address,

View File

@@ -880,8 +880,16 @@ class NetworkManager(manager.Manager):
instance_uuid = fixed_ip_ref['instance_uuid']
vif_id = fixed_ip_ref['virtual_interface_id']
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = self.db.instance_get_by_uuid(
context.elevated(read_deleted='yes'),
instance_uuid)
project_id = instance.project_id
try:
reservations = self.quotas.reserve(context, fixed_ips=-1)
reservations = self.quotas.reserve(context,
project_id=project_id,
fixed_ips=-1)
except Exception:
reservations = None
LOG.exception(_("Failed to update usages deallocating "
@@ -890,12 +898,6 @@ class NetworkManager(manager.Manager):
self._do_trigger_security_group_members_refresh_for_instance(
instance_uuid)
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = self.db.instance_get_by_uuid(
context.elevated(read_deleted='yes'),
instance_uuid)
if self._validate_instance_zone_for_dns_domain(context, instance):
for n in self.instance_dns_manager.get_entries_by_address(address,
self.instance_dns_domain):
@@ -951,7 +953,7 @@ class NetworkManager(manager.Manager):
# Commit the reservations
if reservations:
self.quotas.commit(context, reservations)
self.quotas.commit(context, reservations, project_id=project_id)
def lease_fixed_ip(self, context, address):
"""Called by dhcp-bridge when ip is leased."""