Fixed issue where floating ips were not cleaned up correctly on port delete
This commit is contained in:
@@ -13,14 +13,34 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
from quark.drivers.registry import DriverRegistryBase
|
from quark.drivers.registry import DriverRegistryBase
|
||||||
from quark.drivers import unicorn_driver as unicorn
|
from quark.drivers import unicorn_driver as unicorn
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
quark_router_opts = [
|
||||||
|
cfg.StrOpt('default_floating_ip_driver',
|
||||||
|
default='Unicorn',
|
||||||
|
help=_('Driver for floating IP')),
|
||||||
|
]
|
||||||
|
|
||||||
|
CONF.register_opts(quark_router_opts, 'QUARK')
|
||||||
|
|
||||||
|
|
||||||
class FloatingIPDriverRegistry(DriverRegistryBase):
|
class FloatingIPDriverRegistry(DriverRegistryBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.drivers = {
|
self.drivers = {
|
||||||
unicorn.UnicornDriver.get_name(): unicorn.UnicornDriver()}
|
unicorn.UnicornDriver.get_name(): unicorn.UnicornDriver()}
|
||||||
|
|
||||||
|
def get_driver(self, driver_name=None):
|
||||||
|
if not driver_name:
|
||||||
|
driver_name = CONF.QUARK.default_floating_ip_driver
|
||||||
|
|
||||||
|
if driver_name in self.drivers:
|
||||||
|
return self.drivers[driver_name]
|
||||||
|
|
||||||
|
raise Exception("Driver %s is not registered." % driver_name)
|
||||||
|
|
||||||
DRIVER_REGISTRY = FloatingIPDriverRegistry()
|
DRIVER_REGISTRY = FloatingIPDriverRegistry()
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ from oslo_utils import timeutils
|
|||||||
from quark.db import api as db_api
|
from quark.db import api as db_api
|
||||||
from quark.db import ip_types
|
from quark.db import ip_types
|
||||||
from quark.db import models
|
from quark.db import models
|
||||||
|
from quark.drivers import floating_ip_registry as registry
|
||||||
from quark import exceptions as q_exc
|
from quark import exceptions as q_exc
|
||||||
from quark import network_strategy
|
from quark import network_strategy
|
||||||
from quark import utils
|
from quark import utils
|
||||||
@@ -741,10 +742,20 @@ class QuarkIpam(object):
|
|||||||
# another trip to deallocate each IP, but keeping our
|
# another trip to deallocate each IP, but keeping our
|
||||||
# indices smaller probably provides more value than the
|
# indices smaller probably provides more value than the
|
||||||
# cost
|
# cost
|
||||||
|
# NOTE(aquillin): For floating IPs associated with the port, we do not
|
||||||
|
# want to deallocate the IP or disassociate the IP from
|
||||||
|
# the tenant, instead we will disassociate floating's
|
||||||
|
# fixed IP address.
|
||||||
context.session.flush()
|
context.session.flush()
|
||||||
for ip in ips_to_remove:
|
for ip in ips_to_remove:
|
||||||
if len(ip["ports"]) == 0:
|
if ip["address_type"] == ip_types.FLOATING:
|
||||||
self.deallocate_ip_address(context, ip)
|
if ip.fixed_ip:
|
||||||
|
db_api.floating_ip_disassociate_fixed_ip(context, ip)
|
||||||
|
driver = registry.DRIVER_REGISTRY.get_driver()
|
||||||
|
driver.remove_floating_ip(ip)
|
||||||
|
else:
|
||||||
|
if len(ip["ports"]) == 0:
|
||||||
|
self.deallocate_ip_address(context, ip)
|
||||||
|
|
||||||
# NCP-1509(roaet):
|
# NCP-1509(roaet):
|
||||||
# - started using admin_context due to tenant not claiming when realloc
|
# - started using admin_context due to tenant not claiming when realloc
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ CONF = cfg.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
quark_router_opts = [
|
quark_router_opts = [
|
||||||
cfg.StrOpt('default_floating_ip_driver',
|
|
||||||
default='Unicorn',
|
|
||||||
help=_('Driver for floating IP')),
|
|
||||||
cfg.StrOpt('floating_ip_segment_name', default='floating_ip',
|
cfg.StrOpt('floating_ip_segment_name', default='floating_ip',
|
||||||
help=_('Segment name for floating IP subnets')),
|
help=_('Segment name for floating IP subnets')),
|
||||||
cfg.StrOpt('floating_ip_ipam_strategy', default='ANY',
|
cfg.StrOpt('floating_ip_ipam_strategy', default='ANY',
|
||||||
@@ -133,8 +130,7 @@ def create_floatingip(context, content):
|
|||||||
flip = db_api.floating_ip_associate_fixed_ip(context, flip,
|
flip = db_api.floating_ip_associate_fixed_ip(context, flip,
|
||||||
fixed_ip)
|
fixed_ip)
|
||||||
|
|
||||||
flip_driver_type = CONF.QUARK.default_floating_ip_driver
|
flip_driver = registry.DRIVER_REGISTRY.get_driver()
|
||||||
flip_driver = registry.DRIVER_REGISTRY.get_driver(flip_driver_type)
|
|
||||||
|
|
||||||
flip_driver.register_floating_ip(flip, port, fixed_ip)
|
flip_driver.register_floating_ip(flip, port, fixed_ip)
|
||||||
|
|
||||||
@@ -206,8 +202,7 @@ def update_floatingip(context, id, content):
|
|||||||
flip = db_api.port_associate_ip(context, [port], flip, [port_id])
|
flip = db_api.port_associate_ip(context, [port], flip, [port_id])
|
||||||
flip = db_api.floating_ip_associate_fixed_ip(context, flip,
|
flip = db_api.floating_ip_associate_fixed_ip(context, flip,
|
||||||
fixed_ip)
|
fixed_ip)
|
||||||
flip_driver_type = CONF.QUARK.default_floating_ip_driver
|
flip_driver = registry.DRIVER_REGISTRY.get_driver()
|
||||||
flip_driver = registry.DRIVER_REGISTRY.get_driver(flip_driver_type)
|
|
||||||
|
|
||||||
if port:
|
if port:
|
||||||
if current_port:
|
if current_port:
|
||||||
@@ -261,8 +256,7 @@ def delete_floatingip(context, id):
|
|||||||
db_api.ip_address_deallocate(context, flip)
|
db_api.ip_address_deallocate(context, flip)
|
||||||
|
|
||||||
if flip.fixed_ip:
|
if flip.fixed_ip:
|
||||||
driver_type = CONF.QUARK.default_floating_ip_driver
|
driver = registry.DRIVER_REGISTRY.get_driver()
|
||||||
driver = registry.DRIVER_REGISTRY.get_driver(driver_type)
|
|
||||||
driver.remove_floating_ip(flip)
|
driver.remove_floating_ip(flip)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user