示例#1
0
    def validate_agent_router_combination(self, context, agent, router):
        """Validate if the router can be correctly assigned to the agent.

        :raises: RouterL3AgentMismatch if attempting to assign DVR router
          to legacy agent.
        :raises: InvalidL3Agent if attempting to assign router to an
          unsuitable agent (disabled, type != L3, incompatible configuration)
        :raises: DVRL3CannotAssignToDvrAgent if attempting to assign a
          router to an agent in 'dvr' mode.
        """
        if agent['agent_type'] != constants.AGENT_TYPE_L3:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])

        agent_mode = self._get_agent_mode(agent)

        if agent_mode in [
                constants.L3_AGENT_MODE_DVR,
                l_consts.L3_AGENT_MODE_DVR_NO_EXTERNAL
        ]:
            raise l3agentscheduler.DVRL3CannotAssignToDvrAgent()

        if (agent_mode == constants.L3_AGENT_MODE_LEGACY
                and router.get('distributed')):
            raise l3agentscheduler.RouterL3AgentMismatch(
                router_id=router['id'], agent_id=agent['id'])

        is_suitable_agent = (agentschedulers_db.services_available(
            agent['admin_state_up']) and self.get_l3_agent_candidates(
                context, router, [agent], ignore_admin_state=True))
        if not is_suitable_agent:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
示例#2
0
    def validate_agent_router_combination(self, context, agent, router):
        """Validate if the router can be correctly assigned to the agent.

        :raises: RouterL3AgentMismatch if attempting to assign DVR router
          to legacy agent, or centralized router to compute's L3 agents.
        :raises: InvalidL3Agent if attempting to assign router to an
          unsuitable agent (disabled, type != L3, incompatible configuration)
        :raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR
          router from one DVR Agent to another.
        """
        is_distributed = router.get('distributed')
        agent_conf = self.get_configuration_dict(agent)
        agent_mode = agent_conf.get('agent_mode', 'legacy')
        router_type = ('distributed' if is_distributed else 'centralized')
        is_agent_router_types_incompatible = (
            agent_mode == 'dvr' and not is_distributed
            or agent_mode == 'legacy' and is_distributed)
        if is_agent_router_types_incompatible:
            raise l3agentscheduler.RouterL3AgentMismatch(
                router_type=router_type,
                router_id=router['id'],
                agent_mode=agent_mode,
                agent_id=agent['id'])
        if agent_mode == 'dvr' and is_distributed:
            raise l3agentscheduler.DVRL3CannotAssignToDvrAgent(
                router_type=router_type,
                router_id=router['id'],
                agent_id=agent['id'])

        is_wrong_type_or_unsuitable_agent = (
            agent['agent_type'] != constants.AGENT_TYPE_L3
            or not agent['admin_state_up']
            or not self.get_l3_agent_candidates(context, router, [agent]))
        if is_wrong_type_or_unsuitable_agent:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
示例#3
0
    def add_router_to_l3_agent(self, context, id, router_id):
        """Add a l3 agent to host a router."""
        router = self.get_router(context, router_id)
        with context.session.begin(subtransactions=True):
            agent_db = self._get_agent(context, id)
            if (agent_db['agent_type'] != constants.AGENT_TYPE_L3 or
                not agent_db['admin_state_up'] or
                not self.get_l3_agent_candidates(router, [agent_db])):
                raise l3agentscheduler.InvalidL3Agent(id=id)
            query = context.session.query(RouterL3AgentBinding)
            try:
                binding = query.filter(
                    RouterL3AgentBinding.l3_agent_id == agent_db.id,
                    RouterL3AgentBinding.router_id == router_id).one()
                if binding:
                    raise l3agentscheduler.RouterHostedByL3Agent(
                        router_id=router_id, agent_id=id)
            except exc.NoResultFound:
                pass

            result = self.auto_schedule_routers(context,
                                                agent_db.host,
                                                [router_id])
            if not result:
                raise l3agentscheduler.RouterSchedulingFailed(
                    router_id=router_id, agent_id=id)

        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if l3_notifier:
            l3_notifier.router_added_to_agent(
                context, [router_id], agent_db.host)
示例#4
0
    def add_firewall_to_l3_agent(self, context, agent_id, firewall_id):
        """Add a l3 agent to host a firewall."""
        firewall = self.get_firewall(context, firewall_id)
        with context.session.begin(subtransactions=True):
            agent_db = self._get_agent(context, agent_id)
            if (agent_db['agent_type'] != constants.AGENT_TYPE_L3 or
                not agent_db['admin_state_up']):
                raise l3agentscheduler.InvalidL3Agent(id=agent_id)
            query = context.session.query(FirewallL3AgentBinding)
            try:
                binding = query.filter_by(firewall_id=firewall_id).one()

                raise l3agentscheduler.FirewallHostedByL3Agent(
                    firewall_id=firewall_id,
                    agent_id=binding.l3_agent_id)
            except exc.NoResultFound:
                pass

            result = self.auto_schedule_firewalls(context,
                                                agent_db.host,
                                                [firewall_id])
            if not result:
                raise l3agentscheduler.FirewallSchedulingFailed(
                    firewall_id=firewall_id, agent_id=agent_id)

        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if l3_notifier:
            l3_notifier.firewall_added_to_agent(
                context, [firewall_id], agent_db.host)
示例#5
0
    def validate_agent_router_combination(self, context, agent, router):
        """Validate if the router can be correctly assigned to the agent.

        :raises: RouterL3AgentMismatch if attempting to assign DVR router
          to legacy agent, or centralized router to compute's L3 agents.
        :raises: InvalidL3Agent if attempting to assign router to an
          unsuitable agent (disabled, type != L3, incompatible configuration)
        :raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR
          router from one DVR Agent to another.
        """
        if agent['agent_type'] != constants.AGENT_TYPE_L3:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])

        is_distributed = router.get('distributed')
        agent_conf = self.get_configuration_dict(agent)
        agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
                                    constants.L3_AGENT_MODE_LEGACY)
        router_type = ('distributed' if is_distributed else 'centralized')

        is_agent_router_types_incompatible = (
            agent_mode == constants.L3_AGENT_MODE_DVR and not is_distributed
            or agent_mode == constants.L3_AGENT_MODE_LEGACY and is_distributed)
        if is_agent_router_types_incompatible:
            raise l3agentscheduler.RouterL3AgentMismatch(
                router_type=router_type,
                router_id=router['id'],
                agent_mode=agent_mode,
                agent_id=agent['id'])
        if agent_mode == constants.L3_AGENT_MODE_DVR and is_distributed:
            raise l3agentscheduler.DVRL3CannotAssignToDvrAgent(
                router_type=router_type,
                router_id=router['id'],
                agent_id=agent['id'])

        is_suitable_agent = (
            agentschedulers_db.services_available(agent['admin_state_up'])
            and (self.get_l3_agent_candidates(
                context, router, [agent], ignore_admin_state=True)
                 or self.get_snat_candidates(router, [agent])))
        if not is_suitable_agent:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
示例#6
0
    def validate_agent_router_combination(self, context, agent, router):
        """Validate if the router can be correctly assigned to the agent.

        :raises: RouterL3AgentMismatch if attempting to assign DVR router
          to legacy agent, or centralized router to compute's L3 agents.
        :raises: InvalidL3Agent if attempting to assign router to an
          unsuitable agent (disabled, type != L3, incompatible configuration)
        :raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR
          router from one DVR Agent to another dvr agent.
        :raises: DVRL3CannotAssignRouterWithNoGateway if attempting to
          assign DVR router to dvr_snat agent when there is no gateway
          associated with the DVR router.
        """
        is_distributed = router.get('distributed')
        agent_conf = self.get_configuration_dict(agent)
        agent_mode = agent_conf.get('agent_mode', 'legacy')
        router_type = ('distributed' if is_distributed else 'centralized')
        is_agent_router_types_incompatible = (
            agent_mode == 'dvr' and not is_distributed
            or agent_mode == 'legacy' and is_distributed
        )
        if is_agent_router_types_incompatible:
            raise l3agentscheduler.RouterL3AgentMismatch(
                router_type=router_type, router_id=router['id'],
                agent_mode=agent_mode, agent_id=agent['id'])
        assign_to_dvr_agent = agent_mode == 'dvr'
        if assign_to_dvr_agent and is_distributed:
            raise l3agentscheduler.DVRL3CannotAssignToDvrAgent(
                router_type=router_type, router_id=router['id'],
                agent_mode=agent_mode, agent_id=agent['id'])
        assign_to_dvr_agent = agent_mode == 'dvr_snat'
        assign_router_with_no_gateway = not (
            router.get('external_gateway_info', None))
        if (assign_to_dvr_agent and is_distributed and
            assign_router_with_no_gateway):
            raise l3agentscheduler.DVRL3CannotAssignRouterWithNoGateway(
                router_type=router_type, router_id=router['id'],
                agent_mode=agent_mode, agent_id=agent['id'])

        is_suitable_agent = (
            self.get_l3_agent_candidates(context, router, [agent]) or
            self.get_snat_candidates(router, [agent])
        )
        is_wrong_type = (
            agent['agent_type'] != constants.AGENT_TYPE_L3
        )
        if is_wrong_type or not is_suitable_agent:
            raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
    def add_router_to_l3_agent(self, context, agent_id, router_id):
        """Add a l3 agent to host a router."""
        router = self.get_router(context, router_id)
        distributed = router.get('distributed')
        with context.session.begin(subtransactions=True):
            agent_db = self._get_agent(context, agent_id)
            agent_conf = self.get_configuration_dict(agent_db)
            agent_mode = agent_conf.get('agent_mode', 'legacy')
            if (not distributed and agent_mode == 'dvr'
                    or distributed and agent_mode == 'legacy'):
                router_type = ('distributed' if distributed else 'centralized')
                raise l3agentscheduler.RouterL3AgentMismatch(
                    router_type=router_type,
                    router_id=router_id,
                    agent_mode=agent_mode,
                    agent_id=agent_id)
            if (agent_db['agent_type'] != constants.AGENT_TYPE_L3
                    or not agent_db['admin_state_up']
                    or not self.get_l3_agent_candidates(
                        context, router, [agent_db])):
                raise l3agentscheduler.InvalidL3Agent(id=agent_id)
            query = context.session.query(RouterL3AgentBinding)
            if distributed:
                binding = query.filter_by(router_id=router_id,
                                          l3_agent_id=agent_id).first()
                if binding:
                    raise l3agentscheduler.RouterHostedByL3Agent(
                        router_id=router_id, agent_id=binding.l3_agent_id)
            else:
                try:
                    binding = query.filter_by(router_id=router_id).one()

                    raise l3agentscheduler.RouterHostedByL3Agent(
                        router_id=router_id, agent_id=binding.l3_agent_id)
                except exc.NoResultFound:
                    pass

            result = self.auto_schedule_routers(context, agent_db.host,
                                                [router_id])
            if not result:
                raise l3agentscheduler.RouterSchedulingFailed(
                    router_id=router_id, agent_id=agent_id)

        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if l3_notifier:
            l3_notifier.router_added_to_agent(context, [router_id],
                                              agent_db.host)