From a2e05bc255a4e50427e331edca822aaa87702848 Mon Sep 17 00:00:00 2001 From: Roey Chen Date: Wed, 12 Apr 2017 08:50:34 -0700 Subject: [PATCH] NSXv: Adding more rotuer driver notifications Change Ifbfa959526c5b5e3add94708d96517935e5cb3fa introduces event notifications specific to NSXv routers. Currently we're missing two notification calls in attach_router and detach_router for exclusive and shared rotuers, these are called when updating from one router type to the other. This patch also relocates the notification (before router services removed from edge) in router_interface_remove to be called before actually deleting the interface on the edge. This is needed since some callbacks require the interface to exists in order to complete it's action (e.g - cleaning RouterID from the edge dynamic routing section) Change-Id: Ifb11abfc315faf7b34f2fb35972744b855138cb9 --- .../nsx_v/drivers/exclusive_router_driver.py | 4 ++- .../nsx_v/drivers/shared_router_driver.py | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/drivers/exclusive_router_driver.py b/vmware_nsx/plugins/nsx_v/drivers/exclusive_router_driver.py index 160e8c9a6a..1019cc7d14 100644 --- a/vmware_nsx/plugins/nsx_v/drivers/exclusive_router_driver.py +++ b/vmware_nsx/plugins/nsx_v/drivers/exclusive_router_driver.py @@ -78,6 +78,8 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver): def detach_router(self, context, router_id, router): LOG.debug("Detach exclusive router id %s", router_id) + router_db = self.plugin._get_router(context, router_id) + self._notify_before_router_edge_association(context, router_db) self.edge_manager.unbind_router_on_edge(context, router_id) if self.plugin.metadata_proxy_handler: az = self.get_router_az_by_id(context, router_id) @@ -192,7 +194,7 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver): # Update static routes in all. self.plugin._update_routes(context, router_id, newnexthop) - if new_ext_net_id: + if new_ext_net_id or force_update: self._notify_after_router_edge_association(context, router) def add_router_interface(self, context, router_id, interface_info): diff --git a/vmware_nsx/plugins/nsx_v/drivers/shared_router_driver.py b/vmware_nsx/plugins/nsx_v/drivers/shared_router_driver.py index f364210a4b..cc83aa4e17 100644 --- a/vmware_nsx/plugins/nsx_v/drivers/shared_router_driver.py +++ b/vmware_nsx/plugins/nsx_v/drivers/shared_router_driver.py @@ -95,6 +95,8 @@ class RouterSharedDriver(router_driver.RouterBaseDriver): if not edge_id: return + router_db = self.plugin._get_router(context, router_id) + self._notify_before_router_edge_association(context, router_db) with locking.LockManager.get_lock(str(edge_id)): self._remove_router_services_on_edge(context, router_id) self._unbind_router_on_edge(context, router_id) @@ -108,6 +110,7 @@ class RouterSharedDriver(router_driver.RouterBaseDriver): LOG.debug("Shared router %s attached to edge %s", router_id, edge_id) with locking.LockManager.get_lock(str(edge_id)): self._add_router_services_on_available_edge(context, router_id) + self._notify_after_router_edge_association(context, router_db) def delete_router(self, context, router_id): # make sure that the router binding is cleaned up @@ -850,23 +853,25 @@ class RouterSharedDriver(router_driver.RouterBaseDriver): return info def remove_router_interface(self, context, router_id, interface_info): - detach = False edge_id = edge_utils.get_router_edge_id(context, router_id) with locking.LockManager.get_lock('nsx-shared-router-pool'): info = super( nsx_v.NsxVPluginV2, self.plugin).remove_router_interface( context, router_id, interface_info) + subnet = self.plugin.get_subnet(context, info['subnet_id']) + network_id = subnet['network_id'] + ports = self.plugin._get_router_interface_ports_by_network( + context, router_id, network_id) + if not ports: + router = self.plugin._get_router(context, router_id) + self._notify_before_router_edge_association(context, router) with locking.LockManager.get_lock(str(edge_id)): - subnet = self.plugin.get_subnet(context, info['subnet_id']) - network_id = subnet['network_id'] router_ids = self.edge_manager.get_routers_on_same_edge( context, router_id) self._update_nat_rules_on_routers(context, router_id, router_ids) self._update_subnets_and_dnat_firewall_on_routers( context, router_id, router_ids, allow_external=True) - ports = self.plugin._get_router_interface_ports_by_network( - context, router_id, network_id) if not ports: edge_utils.delete_interface(self.nsx_v, context, router_id, network_id) @@ -874,7 +879,9 @@ class RouterSharedDriver(router_driver.RouterBaseDriver): # router if not self.plugin._get_internal_network_ids_by_router( context, router_id): - detach = True + self._remove_router_services_on_edge(context, + router_id) + self._unbind_router_on_edge(context, router_id) else: address_groups = self.plugin._get_address_groups( context, router_id, network_id) @@ -882,12 +889,6 @@ class RouterSharedDriver(router_driver.RouterBaseDriver): router_id, network_id, address_groups) - if detach: - router = self.plugin._get_router(context, router_id) - self._notify_before_router_edge_association(context, router) - with locking.LockManager.get_lock(str(edge_id)): - self._remove_router_services_on_edge(context, router_id) - self._unbind_router_on_edge(context, router_id) return info def _update_edge_router(self, context, router_id):