Look for floatingips on configured subnets
Define a new configuration option to list the subnets where floatingips should be allocated, and use those subnets instead of all of the subnets on the external network. Change-Id: Ida1dbd9e463deb36cf3249deaad24e93f49bb575
This commit is contained in:
parent
d0d82ba511
commit
042635fdc0
@ -1,7 +1,22 @@
|
||||
from neutron.common import exceptions as q_exc
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.common import exceptions as q_exc
|
||||
from neutron.db.l3_db import DEVICE_OWNER_FLOATINGIP, FloatingIP
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.openstack.common import log
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
explicit_floating_ip_opts = [
|
||||
cfg.MultiStrOpt(
|
||||
'floatingip_subnet',
|
||||
default=[],
|
||||
help='UUID(s) of subnet(s) from which floating IPs should be allocated',
|
||||
required=True,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class ExplicitFloatingIPAllocationMixin(object):
|
||||
@ -12,7 +27,27 @@ class ExplicitFloatingIPAllocationMixin(object):
|
||||
|
||||
"""
|
||||
|
||||
def _allocate_floatingip_from_configured_subnets(self, context):
|
||||
cfg.CONF.register_opts(explicit_floating_ip_opts, group='akanda')
|
||||
LOG.debug('looking for floating ip on %s', str(cfg.CONF.akanda.floatingip_subnet))
|
||||
# NOTE(dhellmann): There may be a better way to do this, but
|
||||
# the "filter" argument to get_subnets() is not documented so
|
||||
# who knows.
|
||||
e_context = context.elevated()
|
||||
subnets = [
|
||||
self._get_subnet(e_context, unicode(s))
|
||||
for s in cfg.CONF.akanda.floatingip_subnet
|
||||
]
|
||||
if not subnets:
|
||||
LOG.error('config setting akanda.floatingip_subnet missing')
|
||||
raise q_exc.IpAddressGenerationFailure(net_id='UNKNOWN')
|
||||
# The base class method _generate_ip() handles the allocation
|
||||
# ranges and going from one subnet to the next when a network
|
||||
# is exhausted.
|
||||
return self._generate_ip(context, subnets)
|
||||
|
||||
def create_floatingip(self, context, floatingip):
|
||||
LOG.debug('create_floatingip %s', (floatingip,))
|
||||
fip = floatingip['floatingip']
|
||||
tenant_id = self._get_tenant_id_for_create(context, fip)
|
||||
fip_id = uuidutils.generate_uuid()
|
||||
@ -22,6 +57,12 @@ class ExplicitFloatingIPAllocationMixin(object):
|
||||
msg = _("Network %s is not a valid external network") % f_net_id
|
||||
raise q_exc.BadRequest(resource='floatingip', msg=msg)
|
||||
|
||||
# NOTE(dhellmann): Custom
|
||||
#
|
||||
# FIXME(dhellmann): This should probably verify that the subnet
|
||||
# being used is on the network the user requested.
|
||||
ip_to_use = self._allocate_floatingip_from_configured_subnets(context)
|
||||
|
||||
with context.session.begin(subtransactions=True):
|
||||
# This external port is never exposed to the tenant.
|
||||
# it is used purely for internal system and admin use when
|
||||
@ -31,7 +72,8 @@ class ExplicitFloatingIPAllocationMixin(object):
|
||||
{'tenant_id': '', # tenant intentionally not set
|
||||
'network_id': f_net_id,
|
||||
'mac_address': attributes.ATTR_NOT_SPECIFIED,
|
||||
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
|
||||
# NOTE(dhellmann): Custom
|
||||
'fixed_ips': [ip_to_use],
|
||||
'admin_state_up': True,
|
||||
'device_id': fip_id,
|
||||
'device_owner': DEVICE_OWNER_FLOATINGIP,
|
||||
|
Loading…
x
Reference in New Issue
Block a user