示例#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 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'])
示例#4
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'])