'Handler to cleanup distributed resources after intf removal.'

@registry.receives(resources.ROUTER_INTERFACE, [events.AFTER_DELETE])
@db_api.retry_if_session_inactive()
def _cleanup_after_interface_removal(self, resource, event, trigger, context, port, interface_info, router_id, **kwargs):

    router = self.l3plugin._get_router(context, router_id)
    if (not router.extra_attributes.distributed):
        return
    plugin = directory.get_plugin(plugin_constants.L3)
    router_hosts_for_removed = plugin._get_dvr_hosts_for_subnets(context, subnet_ids={ip['subnet_id'] for ip in port['fixed_ips']})
    router_hosts_after = plugin._get_dvr_hosts_for_router(context, router_id)
    removed_hosts = (set(router_hosts_for_removed) - set(router_hosts_after))
    if removed_hosts:
        agents = plugin.get_l3_agents(context, filters={'host': removed_hosts})
        bindings = rb_obj.RouterL3AgentBinding.get_objects(context, router_id=router_id)
        snat_binding = (bindings.pop() if bindings else None)
        for agent in agents:
            is_this_snat_agent = (snat_binding and (snat_binding.l3_agent_id == agent['id']))
            if (not is_this_snat_agent):
                self.l3plugin.l3_rpc_notifier.router_removed_from_agent(context, router_id, agent['host'])
    sub_id = (interface_info.get('subnet_id') or port['fixed_ips'][0]['subnet_id'])
    is_multiple_prefix_csport = self._check_for_multiprefix_csnat_port_and_update(context, router, port['network_id'], sub_id)
    if (not is_multiple_prefix_csport):
        self.delete_csnat_router_interface_ports(context.elevated(), router, subnet_id=sub_id)
