예제 #1
0
    def get_amphora_for_lb_subflow(self,
                                   prefix,
                                   role=constants.ROLE_STANDALONE,
                                   is_spare=False):
        """Tries to allocate a spare amphora to a loadbalancer if none

        exists, create a new amphora.
        """

        sf_name = prefix + '-' + constants.GET_AMPHORA_FOR_LB_SUBFLOW

        # Don't replace a spare with another spare, just build a fresh one.
        if is_spare:
            get_spare_amp_flow = linear_flow.Flow(sf_name)

            get_spare_amp_flow.add(
                self._get_create_amp_for_lb_subflow(prefix,
                                                    role,
                                                    is_spare=is_spare))
            return get_spare_amp_flow

        # We need a graph flow here for a conditional flow
        amp_for_lb_flow = graph_flow.Flow(sf_name)

        # Setup the task that maps an amphora to a load balancer
        allocate_and_associate_amp = database_tasks.MapLoadbalancerToAmphora(
            name=sf_name + '-' + constants.MAP_LOADBALANCER_TO_AMPHORA,
            requires=(constants.LOADBALANCER_ID, constants.FLAVOR,
                      constants.AVAILABILITY_ZONE),
            provides=constants.AMPHORA_ID)

        # Define a subflow for if we successfully map an amphora
        map_lb_to_amp = self._get_post_map_lb_subflow(prefix, role)
        # Define a subflow for if we can't map an amphora
        create_amp = self._get_create_amp_for_lb_subflow(prefix, role)

        # Add them to the graph flow
        amp_for_lb_flow.add(allocate_and_associate_amp, map_lb_to_amp,
                            create_amp)

        # Setup the decider for the path if we can map an amphora
        amp_for_lb_flow.link(allocate_and_associate_amp,
                             map_lb_to_amp,
                             decider=self._allocate_amp_to_lb_decider,
                             decider_depth='flow')
        # Setup the decider for the path if we can't map an amphora
        amp_for_lb_flow.link(allocate_and_associate_amp,
                             create_amp,
                             decider=self._create_new_amp_for_lb_decider,
                             decider_depth='flow')

        return amp_for_lb_flow
예제 #2
0
    def get_amphora_for_lb_subflow(self,
                                   prefix,
                                   role=constants.ROLE_STANDALONE):
        """Tries to allocate a spare amphora to a loadbalancer if none

        exists, create a new amphora.
        """

        sf_name = prefix + '-' + constants.GET_AMPHORA_FOR_LB_SUBFLOW

        # We need a graph flow here for a conditional flow
        amp_for_lb_flow = graph_flow.Flow(sf_name)

        # Setup the task that maps an amphora to a load balancer
        allocate_and_associate_amp = database_tasks.MapLoadbalancerToAmphora(
            name=sf_name + '-' + constants.MAP_LOADBALANCER_TO_AMPHORA,
            requires=(constants.LOADBALANCER_ID, constants.FLAVOR,
                      constants.AVAILABILITY_ZONE),
            provides=constants.AMPHORA_ID)

        # Define a subflow for if we successfully map an amphora
        map_lb_to_amp = self._get_post_map_lb_subflow(prefix, role)
        # Define a subflow for if we can't map an amphora
        create_amp = self._get_create_amp_for_lb_subflow(prefix, role)

        # Add them to the graph flow
        amp_for_lb_flow.add(allocate_and_associate_amp, map_lb_to_amp,
                            create_amp)

        # Setup the decider for the path if we can map an amphora
        amp_for_lb_flow.link(allocate_and_associate_amp,
                             map_lb_to_amp,
                             decider=self._allocate_amp_to_lb_decider,
                             decider_depth='flow')
        # Setup the decider for the path if we can't map an amphora
        amp_for_lb_flow.link(allocate_and_associate_amp,
                             create_amp,
                             decider=self._create_new_amp_for_lb_decider,
                             decider_depth='flow')

        # Plug the network
        # todo(xgerman): Rework failover flow
        if prefix != constants.FAILOVER_AMPHORA_FLOW:
            sf_name = prefix + '-' + constants.AMP_PLUG_NET_SUBFLOW
            amp_for_lb_net_flow = linear_flow.Flow(sf_name)
            amp_for_lb_net_flow.add(amp_for_lb_flow)
            amp_for_lb_net_flow.add(*self._get_amp_net_subflow(sf_name))
            return amp_for_lb_net_flow

        return amp_for_lb_flow