193
195
def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
194
"""Override to delete the fip agent gw port on disassociate."""
196
"""Override to create and delete floating agent gw port for DVR.
198
Floating IP Agent gateway port will be created when a
199
floatingIP association happens.
200
Floating IP Agent gateway port will be deleted when a
201
floatingIP disassociation happens.
195
203
fip_port = fip.get('port_id')
196
204
unused_fip_agent_gw_port = (
197
205
fip_port is None and floatingip_db['fixed_port_id'])
198
if unused_fip_agent_gw_port:
206
if unused_fip_agent_gw_port and floatingip_db.get('router_id'):
199
207
admin_ctx = context.elevated()
200
self.clear_unused_fip_agent_gw_port(
201
admin_ctx, floatingip_db)
208
router_dict = self.get_router(
209
admin_ctx, floatingip_db['router_id'])
210
# Check if distributed router and then delete the
211
# FloatingIP agent gateway port
212
if router_dict.get('distributed'):
213
self.clear_unused_fip_agent_gw_port(
214
admin_ctx, floatingip_db)
202
215
super(L3_NAT_with_dvr_db_mixin, self)._update_fip_assoc(
203
216
context, fip, floatingip_db, external_port)
217
associate_fip = fip_port and floatingip_db['id']
218
if associate_fip and floatingip_db.get('router_id'):
219
admin_ctx = context.elevated()
220
router_dict = self.get_router(
221
admin_ctx, floatingip_db['router_id'])
222
# Check if distributed router and then create the
223
# FloatingIP agent gateway port
224
if router_dict.get('distributed'):
225
vm_hostid = self.get_vm_port_hostid(
228
# FIXME (Swami): This FIP Agent Gateway port should be
229
# created only once and there should not be a duplicate
230
# for the same host. Until we find a good solution for
231
# augmenting multiple server requests we should use the
234
self.create_fip_agent_gw_port_if_not_exists(
235
admin_ctx, external_port['network_id'],
237
LOG.debug("FIP Agent gateway port: %s", fip_agent_port)
205
239
def clear_unused_fip_agent_gw_port(
206
240
self, context, floatingip_db):
215
249
fip_hostid = self.get_vm_port_hostid(
216
250
context, floatingip_db['fixed_port_id'])
217
if fip_hostid and self.check_fips_availability_on_host(
218
context, fip_hostid):
219
LOG.debug('Deleting the Agent GW Port on host: %s', fip_hostid)
220
self.delete_floatingip_agent_gateway_port(context, fip_hostid)
251
if fip_hostid and self.check_fips_availability_on_host_ext_net(
252
context, fip_hostid, floatingip_db['floating_network_id']):
253
LOG.debug('Deleting the Agent GW Port for ext-net: '
254
'%s', floatingip_db['floating_network_id'])
255
self.delete_floatingip_agent_gateway_port(
256
context, fip_hostid, floatingip_db['floating_network_id'])
222
258
def delete_floatingip(self, context, id):
223
259
floatingip = self._get_floatingip(context, id)
297
333
port, subnet = self._remove_interface_by_subnet(
298
334
context, router_id, subnet_id, device_owner)
300
if router.extra_attributes.distributed and router.gw_port:
301
self.delete_csnat_router_interface_ports(
302
context.elevated(), router, subnet_id=subnet_id)
336
if router.extra_attributes.distributed:
338
self.delete_csnat_router_interface_ports(
339
context.elevated(), router, subnet_id=subnet_id)
340
plugin = manager.NeutronManager.get_service_plugins().get(
341
constants.L3_ROUTER_NAT)
342
l3_agents = plugin.get_l3_agents_hosting_routers(context,
344
for l3_agent in l3_agents:
345
if not plugin.check_ports_exist_on_l3agent(context, l3_agent,
347
plugin.remove_router_from_l3_agent(
348
context, l3_agent['id'], router_id)
304
350
router_interface_info = self._make_router_interface_info(
305
351
router_id, port['tenant_id'], port['id'],
442
def check_fips_availability_on_host(self, context, host_id):
443
"""Query all floating_ips and filter by particular host."""
490
def check_fips_availability_on_host_ext_net(
491
self, context, host_id, fip_ext_net_id):
492
"""Query all floating_ips and filter on host and external net."""
444
493
fip_count_on_host = 0
445
494
with context.session.begin(subtransactions=True):
446
495
routers = self._get_sync_routers(context, router_ids=None)
449
498
# Check for the active floatingip in the host
450
499
for fip in floating_ips:
451
500
f_host = self.get_vm_port_hostid(context, fip['port_id'])
452
if f_host == host_id:
501
if (f_host == host_id and
502
(fip['floating_network_id'] == fip_ext_net_id)):
453
503
fip_count_on_host += 1
454
504
# If fip_count greater than 1 or equal to zero no action taken
455
505
# if the fip_count is equal to 1, then this would be last active
461
def delete_floatingip_agent_gateway_port(self, context, host_id):
462
"""Function to delete the FIP agent gateway port on host."""
511
def delete_floatingip_agent_gateway_port(
512
self, context, host_id, ext_net_id):
513
"""Function to delete FIP gateway port with given ext_net_id."""
463
514
# delete any fip agent gw port
464
device_filter = {'device_owner': [DEVICE_OWNER_AGENT_GW]}
515
device_filter = {'device_owner': [DEVICE_OWNER_AGENT_GW],
516
'network_id': [ext_net_id]}
465
517
ports = self._core_plugin.get_ports(context,
466
518
filters=device_filter)