Пример #1
0
    def _update_router_db(self, context, router_id, data, gw_info):
        ha = data.pop('ha', None)

        if ha and data.get('distributed'):
            raise l3_ha.DistributedHARouterNotSupported()

        with context.session.begin(subtransactions=True):
            router_db = super(L3_HA_NAT_db_mixin,
                              self)._update_router_db(context, router_id, data,
                                                      gw_info)

            ha_not_changed = ha is None or ha == router_db.extra_attributes.ha
            if ha_not_changed:
                return router_db

            ha_network = self.get_ha_network(context, router_db.tenant_id)
            router_db.extra_attributes.ha = ha
            if not ha:
                self._delete_vr_id_allocation(
                    context, ha_network, router_db.extra_attributes.ha_vr_id)
                router_db.extra_attributes.ha_vr_id = None

        if ha:
            if not ha_network:
                ha_network = self._create_ha_network(context,
                                                     router_db.tenant_id)

            self._set_vr_id(context, router_db, ha_network)
            self._create_ha_interfaces(context, router_db, ha_network)
            self._notify_ha_interfaces_updated(context, router_db.id)
        else:
            self._delete_ha_interfaces(context, router_db.id)
            self._notify_ha_interfaces_updated(context, router_db.id)

        return router_db
Пример #2
0
    def create_router(self, context, router):
        is_ha = self._is_ha(router['router'])

        if is_ha and l3_dvr_db.is_distributed_router(router['router']):
            raise l3_ha.DistributedHARouterNotSupported()

        router['router']['ha'] = is_ha
        router_dict = super(L3_HA_NAT_db_mixin,
                            self).create_router(context, router)

        if is_ha:
            try:
                router_db = self._get_router(context, router_dict['id'])
                ha_network = self.get_ha_network(context, router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(
                        context, router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_dict['id'])
            router_dict['ha_vr_id'] = router_db.extra_attributes.ha_vr_id
        return router_dict
 def _schedule_router(self, plugin, context, router_id, candidates=None):
     sync_router = plugin.get_router(context, router_id)
     router_distributed = sync_router.get('distributed', False)
     if router_distributed or sync_router.get('ha', False):
         raise l3_ha.DistributedHARouterNotSupported()
     if candidates is None:
         candidates = self.get_all_l3_agents(plugin, context)
         LOG.debug('all_cap:%s' % candidates)
     if not candidates:
         return
     for chosen_agent in candidates:
         query = context.session.query(
             l3_agentschedulers_db.RouterL3AgentBinding)
         query = query.filter(
             l3_agentschedulers_db.RouterL3AgentBinding.router_id ==
             router_id,
             l3_agentschedulers_db.RouterL3AgentBinding.l3_agent_id ==
             chosen_agent['id'])
         try:
             query.one()
             LOG.debug('find old router_agent_binding %s-%s '
                       % (router_id, chosen_agent['id']))
         except sa_exc.NoResultFound:
             self.bind_router(context, router_id, chosen_agent)
     return chosen_agent
Пример #4
0
    def _create_router_db(self, context, router, tenant_id):
        router['ha'] = self._is_ha(router)

        if router['ha'] and l3_dvr_db.is_distributed_router(router):
            raise l3_ha.DistributedHARouterNotSupported()

        with context.session.begin(subtransactions=True):
            router_db = super(L3_HA_NAT_db_mixin,
                              self)._create_router_db(context, router,
                                                      tenant_id)

        if router['ha']:
            try:
                ha_network = self.get_ha_network(context, router_db.tenant_id)
                if not ha_network:
                    ha_network = self._create_ha_network(
                        context, router_db.tenant_id)

                self._set_vr_id(context, router_db, ha_network)
                self._create_ha_interfaces(context, router_db, ha_network)
                self._notify_ha_interfaces_updated(context, router_db.id)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self.delete_router(context, router_db.id)

        return router_db
Пример #5
0
    def _update_router_db(self, context, router_id, data, gw_info):
        router_db = self._get_router(context, router_id)

        original_distributed_state = router_db.extra_attributes.distributed
        original_ha_state = router_db.extra_attributes.ha

        requested_ha_state = data.pop('ha', None)
        requested_distributed_state = data.get('distributed', None)

        if ((original_ha_state and requested_distributed_state)
                or (requested_ha_state and original_distributed_state)
                or (requested_ha_state and requested_distributed_state)):
            raise l3_ha.DistributedHARouterNotSupported()

        with context.session.begin(subtransactions=True):
            router_db = super(L3_HA_NAT_db_mixin,
                              self)._update_router_db(context, router_id, data,
                                                      gw_info)

            ha_not_changed = (requested_ha_state is None
                              or requested_ha_state == original_ha_state)
            if ha_not_changed:
                return router_db

            if router_db.admin_state_up:
                msg = _('Cannot change HA attribute of active routers. Please '
                        'set router admin_state_up to False prior to upgrade.')
                raise n_exc.BadRequest(resource='router', msg=msg)

            ha_network = self.get_ha_network(context, router_db.tenant_id)
            router_db.extra_attributes.ha = requested_ha_state
            if not requested_ha_state:
                self._delete_vr_id_allocation(
                    context, ha_network, router_db.extra_attributes.ha_vr_id)
                router_db.extra_attributes.ha_vr_id = None

        # The HA attribute has changed. First unbind the router from agents
        # to force a proper re-scheduling to agents.
        # TODO(jschwarz): This will have to be more selective to get HA + DVR
        # working (Only unbind from dvr_snat nodes).
        self._unbind_ha_router(context, router_id)

        if requested_ha_state:
            if not ha_network:
                ha_network = self._create_ha_network(context,
                                                     router_db.tenant_id)

            self._set_vr_id(context, router_db, ha_network)
            self._create_ha_interfaces(context, router_db, ha_network)
            self._notify_ha_interfaces_updated(context, router_db.id)
        else:
            self._delete_ha_interfaces(context, router_db.id)
            self._notify_ha_interfaces_updated(context, router_db.id)

        return router_db