def _metadata_route_update(self, context, router_id):
        """Update metadata relative routes.
        The func can only be used when there is no gateway on vdr.
        """
        md_gw_data = self._get_metadata_gw_data(context, router_id)

        # Setup metadata route on VDR
        self._update_routes_on_tlr(
            context, router_id, newnexthop=None,
            metadata_gateway=md_gw_data)
        if not md_gw_data:
            # No more DHCP interfaces on VDR. Remove DHCP binding
            nsxv_db.delete_vdr_dhcp_binding(context.session, router_id)
        return md_gw_data
    def remove_router_interface(self, context, router_id, interface_info):
        info = super(nsx_v.NsxVPluginV2, self.plugin).remove_router_interface(
            context, router_id, interface_info)
        router_db = self.plugin._get_router(context, router_id)
        subnet = self.plugin.get_subnet(context, info['subnet_id'])
        network_id = subnet['network_id']

        with locking.LockManager.get_lock(self._get_edge_id(context,
                                                            router_id)):
            if router_db.gw_port and router_db.enable_snat:
                plr_id = self.edge_manager.get_plr_by_tlr_id(
                    context, router_id)
                self.plugin._update_nat_rules(context, router_db, plr_id)
                # Open firewall flows on plr
                self.plugin._update_subnets_and_dnat_firewall(
                    context, router_db, router_id=plr_id)
                # Update static routes of plr
                nexthop = self.plugin._get_external_attachment_info(
                    context, router_db)[2]
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                self._update_routes(context, router_id, nexthop, md_gw_data)
                if (subnet['enable_dhcp']
                    and self.plugin.metadata_proxy_handler
                    and not md_gw_data):
                    # No more DHCP interfaces on VDR. Remove DHCP binding
                    nsxv_db.delete_vdr_dhcp_binding(context.session, router_id)

            # If DHCP is disabled, this remove cannot trigger metadata change
            # as metadata is served via DHCP Edge
            elif (subnet['enable_dhcp']
                  and self.plugin.metadata_proxy_handler):
                md_gw_data = self._get_metadata_gw_data(context, router_id)
                if self._metadata_cfg_required_after_port_remove(
                    context, router_id, subnet):
                    self._metadata_route_update(context, router_id)

            self.plugin._update_subnets_and_dnat_firewall(context, router_db)
            # Safly remove interface, VDR can have interface to only one subnet
            # in a given network.
            edge_utils.delete_interface(
                self.nsx_v, context, router_id, network_id, dist=True)

            # The network would be the last one attached to the VDR if
            # md_gw_data is None. For such condition, we just keep network
            # attached to the dhcp edge since the dhcp edge is a pure dhcp
            # support edge now
            if (self.plugin.metadata_proxy_handler and subnet['enable_dhcp']
                and md_gw_data):
                # Detach network from VDR-dedicated DHCP Edge
                vdr_dhcp_binding = nsxv_db.get_vdr_dhcp_binding_by_vdr(
                    context.session, router_id)

                # A case where we do not have a vdr_dhcp_binding indicates a DB
                # inconsistency. We check for this anyway, in case that
                # something is broken.
                if vdr_dhcp_binding:
                    self.edge_manager.reset_sysctl_rp_filter_for_vdr_dhcp(
                        context, vdr_dhcp_binding['dhcp_edge_id'], network_id)

                    self.edge_manager.remove_network_from_dhcp_edge(
                        context, network_id, vdr_dhcp_binding['dhcp_edge_id'])
                else:
                    LOG.error(_LE('VDR DHCP binding is missing for %s'),
                              router_id)

                # Reattach to regular DHCP Edge
                self.edge_manager.create_dhcp_edge_service(
                    context, network_id, subnet)

                address_groups = (
                    self.plugin._create_network_dhcp_address_group(context,
                                                                   network_id))
                self.edge_manager.update_dhcp_edge_service(
                    context, network_id, address_groups=address_groups)

            return info