Exemplo n.º 1
0
    def _validate_router_migration(self, context, router_db, router_res):
        """Allow transition only when admin_state_up=False"""
        original_distributed_state = router_db.extra_attributes.distributed
        requested_distributed_state = router_res.get('distributed', None)

        distributed_changed = (
            requested_distributed_state is not None and
            requested_distributed_state != original_distributed_state)
        if not distributed_changed:
            return False
        if router_db.admin_state_up:
            msg = _("Cannot change the 'distributed' attribute of active "
                    "routers. Please set router admin_state_up to False "
                    "prior to upgrade")
            raise n_exc.BadRequest(resource='router', msg=msg)

        # Notify advanced services of the imminent state transition
        # for the router.
        try:
            kwargs = {'context': context, 'router': router_db}
            registry.notify(
                resources.ROUTER, events.BEFORE_UPDATE, self, **kwargs)
        except exceptions.CallbackFailure as e:
            # NOTE(armax): preserve old check's behavior
            if len(e.errors) == 1:
                raise e.errors[0].error
            raise l3_exc.RouterInUse(router_id=router_db['id'], reason=e)
        return True
Exemplo n.º 2
0
def migration_callback(resource, event, trigger, **kwargs):
    context = kwargs['context']
    router = kwargs['router']
    fw_plugin = directory.get_plugin(fwaas_constants.FIREWALL)
    if fw_plugin:
        tenant_firewalls = fw_plugin.get_firewalls(
            context, filters={'tenant_id': [router['tenant_id']]})
        if tenant_firewalls:
            raise l3.RouterInUse(router_id=router['id'])
Exemplo n.º 3
0
 def _check_router_not_in_use(self, context, router_id):
     try:
         kwargs = {'context': context, 'router_id': router_id}
         registry.notify(resources.ROUTER, events.BEFORE_DELETE, self,
                         **kwargs)
     except exceptions.CallbackFailure as e:
         with excutils.save_and_reraise_exception():
             if len(e.errors) == 1:
                 raise e.errors[0].error
             raise l3_exc.RouterInUse(router_id=router_id, reason=e)
Exemplo n.º 4
0
 def _check_router_not_in_use(self, context, router_id):
     try:
         registry.publish(
             resources.ROUTER, events.BEFORE_DELETE, self,
             payload=events.DBEventPayload(context, resource_id=router_id))
     except exceptions.CallbackFailure as e:
         with excutils.save_and_reraise_exception():
             if len(e.errors) == 1:
                 raise e.errors[0].error
             raise l3_exc.RouterInUse(router_id=router_id, reason=e)
Exemplo n.º 5
0
 def check_router_in_use(self, context, router_id):
     vpnservices = self.get_vpnservices(
         context, filters={'router_id': [router_id]})
     if vpnservices:
         plural = "s" if len(vpnservices) > 1 else ""
         services = ",".join([v['id'] for v in vpnservices])
         raise l3_exception.RouterInUse(
             router_id=router_id,
             reason="is currently used by VPN service%(plural)s "
                    "(%(services)s)" % {'plural': plural,
                                        'services': services})
 def set_router_for_bgp_speaker(self, context, bgp_sp_id, r_id):
     """Sets the routers associated with the bgp speaker."""
     try:
         with db_api.context_manager.writer.using(context):
             bgp_router_db = model.BgpSpeakerRouterAssociation(
                 bgp_speaker_id=bgp_sp_id, router_id=r_id)
             context.session.add(bgp_router_db)
     except db_exc.DBDuplicateEntry:
         raise l3_exc.RouterInUse(
             router_id=r_id,
             reason='is already associated with bgp speaker')
     except db_exc.DBReferenceError:
         raise l3_exc.RouterNotFound(router_id=r_id)
 def bgp_speaker_callback(self, resource, event, trigger, **kwargs):
     router_id = kwargs['router_id']
     context = kwargs.get('context')
     if self.get_bgp_speaker_associated_with_router(context, router_id):
         raise l3_exc.RouterInUse(router_id=router_id,
                                  reason='is associated with bgp speaker')
Exemplo n.º 8
0
 def bgp_speaker_callback(self, resource, event, trigger, payload=None):
     router_id = payload.resource_id
     context = payload.context
     if self.get_bgp_speaker_associated_with_router(context, router_id):
         raise l3_exc.RouterInUse(
             router_id=router_id, reason='is associated with bgp speaker')