Example #1
0
    def _notify_agents_router_rescheduled(self, context, router_id, old_agents,
                                          new_agents):
        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if not l3_notifier:
            return

        old_hosts = [agent['host'] for agent in old_agents]
        new_hosts = [agent['host'] for agent in new_agents]
        for host in set(old_hosts) - set(new_hosts):
            l3_notifier.router_removed_from_agent(context, router_id, host)

        for agent in new_agents:
            # Need to make sure agents are notified or unschedule otherwise
            for attempt in range(AGENT_NOTIFY_MAX_ATTEMPTS):
                try:
                    l3_notifier.router_added_to_agent(context, [router_id],
                                                      agent['host'])
                    break
                except oslo_messaging.MessagingException:
                    LOG.warning(
                        _LW('Failed to notify L3 agent on host '
                            '%(host)s about added router. Attempt '
                            '%(attempt)d out of %(max_attempts)d'), {
                                'host': agent['host'],
                                'attempt': attempt + 1,
                                'max_attempts': AGENT_NOTIFY_MAX_ATTEMPTS
                            })
            else:
                self._unbind_router(context, router_id, agent['id'])
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)
Example #2
0
    def reschedule_router(self, context, router_id, candidates=None):
        """Reschedule router to a new l3 agent

        Remove the router from the agent(s) currently hosting it and
        schedule it again
        """
        cur_agents = self.list_l3_agents_hosting_router(context,
                                                        router_id)['agents']
        with context.session.begin(subtransactions=True):
            for agent in cur_agents:
                self._unbind_router(context, router_id, agent['id'])

            new_agent = self.schedule_router(context,
                                             router_id,
                                             candidates=candidates)
            if not new_agent:
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)

        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if l3_notifier:
            for agent in cur_agents:
                l3_notifier.router_removed_from_agent(context, router_id,
                                                      agent['host'])
            l3_notifier.router_added_to_agent(context, [router_id],
                                              new_agent.host)
    def reschedule_router(self, context, router_id, candidates=None):
        """Reschedule router to new l3 agents

        Remove the router from l3 agents currently hosting it and
        schedule it again
        """
        router = self.get_router(context, router_id)
        is_distributed = router.get('distributed', False)
        if not is_distributed:
            return super(L3_DVRsch_db_mixin,
                         self).reschedule_router(context, router_id,
                                                 candidates)

        old_agents = self.list_l3_agents_hosting_router(context,
                                                        router_id)['agents']
        with context.session.begin(subtransactions=True):
            for agent in old_agents:
                self._unbind_router(context, router_id, agent['id'])
                self.unbind_snat_servicenode(context, router_id)

            self.schedule_router(context, router_id, candidates=candidates)
            new_agents = self.list_l3_agents_hosting_router(
                context, router_id)['agents']
            if not new_agents:
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)

        l3_notifier = self.agent_notifiers.get(q_const.AGENT_TYPE_L3)
        if l3_notifier:
            old_hosts = [agent['host'] for agent in old_agents]
            new_hosts = [agent['host'] for agent in new_agents]
            for host in set(old_hosts) - set(new_hosts):
                l3_notifier.router_removed_from_agent(context, router_id, host)
            for host in new_hosts:
                l3_notifier.router_added_to_agent(context, [router_id], host)
Example #4
0
    def _notify_agents_router_rescheduled(self, context, router_id, old_agents,
                                          new_agents):
        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if not l3_notifier:
            return

        old_hosts = [agent['host'] for agent in old_agents]
        new_hosts = [agent['host'] for agent in new_agents]
        router = self.get_router(context, router_id)
        for host in set(old_hosts) - set(new_hosts):
            retain_router = self._check_router_retain_needed(
                context, router, host)
            if retain_router:
                l3_notifier.routers_updated_on_host(context, [router_id], host)
            else:
                l3_notifier.router_removed_from_agent(context, router_id, host)

        for agent in new_agents:
            try:
                l3_notifier.router_added_to_agent(context, [router_id],
                                                  agent['host'])
            except oslo_messaging.MessagingException:
                self._unbind_router(context, router_id, agent['id'])
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)
Example #5
0
    def reschedule_router(self, context, router_id, candidates=None):
        """Reschedule router to (a) new l3 agent(s)

        Remove the router from the agent(s) currently hosting it and
        schedule it again
        """
        cur_agents = self.list_l3_agents_hosting_router(context,
                                                        router_id)['agents']
        with context.session.begin(subtransactions=True):
            cur_agents_ids = [agent['id'] for agent in cur_agents]
            self._unschedule_router(context, router_id, cur_agents_ids)

            self.schedule_router(context, router_id, candidates=candidates)
            new_agents = self.list_l3_agents_hosting_router(
                context, router_id)['agents']
            if not new_agents:
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)

        self._notify_agents_router_rescheduled(context, router_id, cur_agents,
                                               new_agents)
Example #6
0
    def reschedule_router(self, context, router_id, candidates=None):
        """Reschedule router to (a) new l3 agent(s)

        Remove the router from the agent(s) currently hosting it and
        schedule it again
        """
        cur_agents = self.list_l3_agents_hosting_router(context,
                                                        router_id)['agents']
        with db_api.CONTEXT_WRITER.using(context):
            cur_agents_ids = [agent['id'] for agent in cur_agents]
            self._unschedule_router(context, router_id, cur_agents_ids)

            self.schedule_router(context, router_id, candidates=candidates)
            new_agents = self.list_l3_agents_hosting_router(
                context, router_id)['agents']
            if not new_agents:
                raise l3agentscheduler.RouterReschedulingFailed(
                    router_id=router_id)

        self._notify_agents_router_rescheduled(context, router_id, cur_agents,
                                               new_agents)