def _check_lb_service_on_router(self, resource, event, trigger, payload=None):
    'Prevent removing a router GW or deleting a router used by LB'
    router_id = payload.resource_id
    context = payload.context
    nsx_router_id = nsx_db.get_nsx_router_id(context.session, router_id)
    if (not nsx_router_id):
        return
    nsxlib = self.loadbalancer.core_plugin.nsxlib
    service_client = nsxlib.load_balancer.service
    lb_service = service_client.get_router_lb_service(nsx_router_id)
    if lb_service:
        msg = (_('Cannot delete a %s as it still has lb service attachment') % resource)
        raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
    core_plugin = self.loadbalancer.core_plugin
    router_subnets = core_plugin._load_router_subnet_cidrs_from_db(context.elevated(), router_id)
    subnet_ids = [subnet['id'] for subnet in router_subnets]
    if (subnet_ids and self._get_lb_ports(context.elevated(), subnet_ids)):
        msg = (_('Cannot delete a %s as it used by a loadbalancer') % resource)
        raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
Prevent removing a router GW or deleting a router used by LB
def _check_lb_service_on_router(self, resource, event, trigger, payload=None):
    
    router_id = payload.resource_id
    context = payload.context
    nsx_router_id = nsx_db.get_nsx_router_id(context.session, router_id)
    if (not nsx_router_id):
        return
    nsxlib = self.loadbalancer.core_plugin.nsxlib
    service_client = nsxlib.load_balancer.service
    lb_service = service_client.get_router_lb_service(nsx_router_id)
    if lb_service:
        msg = (_('Cannot delete a %s as it still has lb service attachment') % resource)
        raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)
    core_plugin = self.loadbalancer.core_plugin
    router_subnets = core_plugin._load_router_subnet_cidrs_from_db(context.elevated(), router_id)
    subnet_ids = [subnet['id'] for subnet in router_subnets]
    if (subnet_ids and self._get_lb_ports(context.elevated(), subnet_ids)):
        msg = (_('Cannot delete a %s as it used by a loadbalancer') % resource)
        raise n_exc.BadRequest(resource='lbaas-lb', msg=msg)