From 6083273c9949b0e49a0c0af7cfc8f0fb83ea7c79 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Sat, 11 Sep 2010 03:06:27 -0700 Subject: fix network association issue --- nova/db/sqlalchemy/api.py | 1 + nova/network/manager.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 02ebdd222..bcdea4b67 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -185,6 +185,7 @@ def fixed_ip_allocate(_context, network_id): ).filter_by(allocated=False ).filter_by(leased=False ).filter_by(deleted=False + ).filter_by(instance=None ).with_lockmode('update' ).first() # NOTE(vish): if with_lockmode isn't supported, as in sqlite, diff --git a/nova/network/manager.py b/nova/network/manager.py index 79280384c..18a8ec0a1 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -96,6 +96,10 @@ class NetworkManager(manager.Manager): """Gets a fixed ip from the pool""" raise NotImplementedError() + def deallocate_fixed_ip(self, context, instance_id, *args, **kwargs): + """Returns a fixed ip to the pool""" + raise NotImplementedError() + def setup_fixed_ip(self, context, address): """Sets up rules for fixed ip""" raise NotImplementedError() @@ -174,6 +178,11 @@ class FlatManager(NetworkManager): self.db.fixed_ip_instance_associate(context, address, instance_id) return address + def deallocate_fixed_ip(self, context, address, *args, **kwargs): + """Returns a fixed ip to the pool""" + self.db.fixed_ip_deallocate(context, address) + self.db.fixed_ip_instance_disassociate(context, address) + def setup_compute_network(self, context, project_id): """Network is created manually""" pass @@ -216,6 +225,14 @@ class VlanManager(NetworkManager): self.db.fixed_ip_instance_associate(context, address, instance_id) return address + def deallocate_fixed_ip(self, context, address, *args, **kwargs): + """Returns a fixed ip to the pool""" + self.db.fixed_ip_deallocate(context, address) + fixed_ip_ref = self.db.fixed_ip_get_by_address(context, address) + if not fixed_ip_ref['leased']: + self.db.fixed_ip_instance_disassociate(context, address) + + def setup_fixed_ip(self, context, address): """Sets forwarding rules and dhcp for fixed ip""" fixed_ip_ref = self.db.fixed_ip_get_by_address(context, address) @@ -258,13 +275,11 @@ class VlanManager(NetworkManager): if instance_ref['mac_address'] != mac: raise exception.Error("IP %s released from bad mac %s vs %s" % (address, instance_ref['mac_address'], mac)) - if fixed_ip_ref['allocated']: + self.db.fixed_ip_update(context, address, {'leased': False}) + if not fixed_ip_ref['allocated']: + self.db.fixed_ip_instance_disassociate(context, address) + else: logging.warn("IP %s released that is still allocated", address) - self.db.fixed_ip_update(context, address, {'leased': False}) - return - self.db.fixed_ip_update(context, address, {'allocated': False, - 'leased': False}) - self.db.fixed_ip_instance_disassociate(context, address) def allocate_network(self, context, project_id): """Set up the network""" -- cgit