diff options
| author | Aaron Lee <aaron.lee@rackspace.com> | 2011-12-09 17:53:15 -0600 |
|---|---|---|
| committer | Aaron Lee <aaron.lee@rackspace.com> | 2011-12-09 17:53:15 -0600 |
| commit | 1e35236519239ef2b4acbb78249502b7bd8ce9b8 (patch) | |
| tree | da5e399dfbc57aeac4c01394bd3372b1f630736b | |
| parent | 0c6c7700299e225aee2c86fbe725c8e146b9f0d4 (diff) | |
fixed_ips by vif does not raise
It makes more sense if this method returns an
empty array instead of raising when it finds no
ips. This lets the iteration over that array
handle the 0 case, and we can use a conditional on
the len(of the ips) if really needed. I'm not sure
that log is needed to say "No fixed IPs
deallocated" or if that is an artifact of needing
something to put in the exception handler.
Change-Id: Ib9f66affb5360fb11a3ab5f415a0e57602cec886
| -rw-r--r-- | nova/db/api.py | 4 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 5 | ||||
| -rw-r--r-- | nova/exception.py | 4 | ||||
| -rw-r--r-- | nova/network/quantum/nova_ipam_lib.py | 21 |
4 files changed, 13 insertions, 21 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index bc413319e..0d9de80a0 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -416,9 +416,9 @@ def fixed_ip_get_by_network_host(context, network_id, host): return IMPL.fixed_ip_get_by_network_host(context, network_id, host) -def fixed_ip_get_by_virtual_interface(context, vif_id): +def fixed_ips_by_virtual_interface(context, vif_id): """Get fixed ips by virtual interface or raise if none exist.""" - return IMPL.fixed_ip_get_by_virtual_interface(context, vif_id) + return IMPL.fixed_ips_by_virtual_interface(context, vif_id) def fixed_ip_get_network(context, address): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 2619c247f..9108ee825 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -876,15 +876,12 @@ def fixed_ip_get_by_network_host(context, network_id, host): @require_context -def fixed_ip_get_by_virtual_interface(context, vif_id): +def fixed_ips_by_virtual_interface(context, vif_id): result = model_query(context, models.FixedIp, read_deleted="no").\ options(joinedload('floating_ips')).\ filter_by(virtual_interface_id=vif_id).\ all() - if not result: - raise exception.FixedIpNotFoundForVirtualInterface(vif_id=vif_id) - return result diff --git a/nova/exception.py b/nova/exception.py index 565e55387..5f336ea1e 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -515,10 +515,6 @@ class FixedIpNotFoundForSpecificInstance(FixedIpNotFound): message = _("Instance %(instance_id)s doesn't have fixed ip '%(ip)s'.") -class FixedIpNotFoundForVirtualInterface(FixedIpNotFound): - message = _("Virtual interface %(vif_id)s has zero associated fixed ips.") - - class FixedIpNotFoundForHost(FixedIpNotFound): message = _("Host %(host)s has zero fixed ips.") diff --git a/nova/network/quantum/nova_ipam_lib.py b/nova/network/quantum/nova_ipam_lib.py index 72abe20c8..9a50d5da7 100644 --- a/nova/network/quantum/nova_ipam_lib.py +++ b/nova/network/quantum/nova_ipam_lib.py @@ -172,7 +172,7 @@ class QuantumNovaIPAMLib(object): the specified virtual interface, based on the fixed_ips table. """ vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) - fixed_ips = db.fixed_ip_get_by_virtual_interface(context, + fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips] @@ -203,17 +203,16 @@ class QuantumNovaIPAMLib(object): """Deallocate all fixed IPs associated with the specified virtual interface. """ - try: - admin_context = context.elevated() - fixed_ips = db.fixed_ip_get_by_virtual_interface(admin_context, - vif_ref['id']) - for fixed_ip in fixed_ips: - db.fixed_ip_update(admin_context, fixed_ip['address'], - {'allocated': False, - 'virtual_interface_id': None}) - except exception.FixedIpNotFoundForInstance: + admin_context = context.elevated() + fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, + vif_ref['id']) + for fixed_ip in fixed_ips: + db.fixed_ip_update(admin_context, fixed_ip['address'], + {'allocated': False, + 'virtual_interface_id': None}) + if len(fixed_ips) == 0: LOG.error(_('No fixed IPs to deallocate for vif %s' % - vif_ref['id'])) + vif_ref['id'])) def get_allocated_ips(self, context, subnet_id, project_id): """Returns a list of (ip, vif_id) pairs""" |
