Esempio n. 1
0
    def _get_post_map_lb_subflow(self, prefix, role):
        """Set amphora type after mapped to lb."""

        sf_name = prefix + '-' + constants.POST_MAP_AMP_TO_LB_SUBFLOW
        post_map_amp_to_lb = linear_flow.Flow(
            sf_name)

        post_map_amp_to_lb.add(database_tasks.ReloadAmphora(
            name=sf_name + '-' + constants.RELOAD_AMPHORA,
            requires=constants.AMPHORA_ID,
            provides=constants.AMPHORA))

        if role == constants.ROLE_MASTER:
            post_map_amp_to_lb.add(database_tasks.MarkAmphoraMasterInDB(
                name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            post_map_amp_to_lb.add(database_tasks.MarkAmphoraBackupInDB(
                name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            post_map_amp_to_lb.add(database_tasks.MarkAmphoraStandAloneInDB(
                name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                requires=constants.AMPHORA))

        return post_map_amp_to_lb
Esempio n. 2
0
    def get_create_load_balancer_flow(self):
        """Creates a flow to create a load balancer.

        :returns: The flow for creating a load balancer
        """

        # Note this flow is a bit strange in how it handles building
        # Amphora if there are no spares.  TaskFlow has a spec for
        # a conditional flow that would make this cleaner once implemented.
        # https://review.openstack.org/#/c/98946/

        create_LB_flow = linear_flow.Flow(constants.CREATE_LOADBALANCER_FLOW)

        create_LB_flow.add(database_tasks.MapLoadbalancerToAmphora(
            requires=constants.LOADBALANCER_ID,
            provides=constants.AMPHORA_ID))
        create_LB_flow.add(database_tasks.ReloadAmphora(
            requires=constants.AMPHORA_ID,
            provides=constants.AMPHORA))
        create_LB_flow.add(database_tasks.ReloadLoadBalancer(
            name=constants.RELOAD_LB_AFTER_AMP_ASSOC,
            requires=constants.LOADBALANCER_ID,
            provides=constants.LOADBALANCER))
        new_LB_net_subflow = self.get_new_LB_networking_subflow()
        create_LB_flow.add(new_LB_net_subflow)
        create_LB_flow.add(database_tasks.MarkLBActiveInDB(
            requires=constants.LOADBALANCER))

        return create_LB_flow
Esempio n. 3
0
    def get_create_amphora_for_lb_flow(self):
        """Creates a flow to create an amphora for a load balancer.

        This flow is used when there are no spare amphora available
        for a new load balancer.  It builds an amphora and allocates
        for the specific load balancer.

        :returns: The The flow for creating the amphora
        """
        create_amp_for_lb_flow = linear_flow.Flow(
            constants.CREATE_AMPHORA_FOR_LB_FLOW)
        create_amp_for_lb_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        if self.REST_AMPHORA_DRIVER:
            create_amp_for_lb_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))
            create_amp_for_lb_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM),
                    provides=constants.COMPUTE_ID))
        else:
            create_amp_for_lb_flow.add(
                compute_tasks.ComputeCreate(requires=constants.AMPHORA_ID,
                                            provides=constants.COMPUTE_ID))
        create_amp_for_lb_flow.add(
            database_tasks.UpdateAmphoraComputeId(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        wait_flow = linear_flow.Flow(
            constants.WAIT_FOR_AMPHORA,
            retry=retry.Times(CONF.controller_worker.amp_active_retries))
        wait_flow.add(
            compute_tasks.ComputeWait(requires=constants.COMPUTE_ID,
                                      provides=constants.COMPUTE_OBJ))
        wait_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        create_amp_for_lb_flow.add(wait_flow)
        create_amp_for_lb_flow.add(
            amphora_driver_tasks.AmphoraFinalize(requires=constants.AMPHORA))
        create_amp_for_lb_flow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        create_amp_for_lb_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        create_amp_for_lb_flow.add(
            database_tasks.ReloadLoadBalancer(
                name=constants.RELOAD_LB_AFTER_AMP_ASSOC,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        new_LB_net_subflow = self._lb_flows.get_new_LB_networking_subflow()
        create_amp_for_lb_flow.add(new_LB_net_subflow)
        create_amp_for_lb_flow.add(
            database_tasks.MarkLBActiveInDB(requires=constants.LOADBALANCER))

        return create_amp_for_lb_flow
Esempio n. 4
0
    def _get_vthunder_for_amphora_subflow(self, prefix, role):
        """Create amphora in existing vThunder."""

        sf_name = prefix + '-' + 'VTHUNDER_TO_AMPHORA_SUBFLOW'
        vthunder_for_amphora_subflow = linear_flow.Flow(sf_name)
        vthunder_for_amphora_subflow.add(database_tasks.CreateAmphoraInDB(
            name=sf_name + '-' + constants.CREATE_AMPHORA_INDB,
            provides=constants.AMPHORA_ID))
        vthunder_for_amphora_subflow.add(a10_database_tasks.GetComputeForProject(
            name=sf_name + '-' + 'get_compute_id',
            requires=constants.LOADBALANCER,
            provides=constants.COMPUTE_ID))
        vthunder_for_amphora_subflow.add(database_tasks.UpdateAmphoraComputeId(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        vthunder_for_amphora_subflow.add(compute_tasks.ComputeActiveWait(
            name=sf_name + '-' + constants.COMPUTE_WAIT,
            requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
            provides=constants.COMPUTE_OBJ))
        vthunder_for_amphora_subflow.add(database_tasks.UpdateAmphoraInfo(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
            provides=constants.AMPHORA))
        # create vThunder entry in custom DB
        vthunder_for_amphora_subflow.add(a10_database_tasks.CreateVThunderEntry(
            name=sf_name + '-' + 'set load balancer status PENDING_CREATE',
            requires=(constants.AMPHORA, constants.LOADBALANCER),
            inject={"role": role, "status": constants.PENDING_CREATE}))
        # Get VThunder details from database
        vthunder_for_amphora_subflow.add(a10_database_tasks.GetVThunderByLoadBalancer(
            name=sf_name + '-' + 'Get_Loadbalancer_from_db',
            requires=constants.LOADBALANCER,
            provides=a10constants.VTHUNDER))
        vthunder_for_amphora_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        vthunder_for_amphora_subflow.add(database_tasks.ReloadAmphora(
            name=sf_name + '-' + constants.RELOAD_AMPHORA,
            requires=constants.AMPHORA_ID,
            provides=constants.AMPHORA))
        if role == constants.ROLE_MASTER:
            vthunder_for_amphora_subflow.add(database_tasks.MarkAmphoraMasterInDB(
                name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            vthunder_for_amphora_subflow.add(database_tasks.MarkAmphoraBackupInDB(
                name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))
        return vthunder_for_amphora_subflow
Esempio n. 5
0
    def test_reload_amphora(self, mock_amp_get, mock_generate_uuid, mock_LOG,
                            mock_get_session, mock_loadbalancer_repo_update,
                            mock_listener_repo_update,
                            mock_amphora_repo_update,
                            mock_amphora_repo_delete):

        reload_amp = database_tasks.ReloadAmphora()
        amp = reload_amp.execute(AMP_ID)

        repo.AmphoraRepository.get.assert_called_once_with('TEST', id=AMP_ID)

        self.assertEqual(_amphora_mock, amp)
Esempio n. 6
0
    def get_create_amphora_flow(self):
        """Creates a flow to create an amphora.

        :returns: The flow for creating the amphora
        """
        create_amphora_flow = linear_flow.Flow(constants.CREATE_AMPHORA_FLOW)
        create_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        create_amphora_flow.add(
            lifecycle_tasks.AmphoraIDToErrorOnRevertTask(
                requires=constants.AMPHORA_ID))
        if self.REST_AMPHORA_DRIVER:
            create_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))

            create_amphora_flow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            create_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM,
                              constants.BUILD_TYPE_PRIORITY),
                    provides=constants.COMPUTE_ID))
        else:
            create_amphora_flow.add(
                compute_tasks.ComputeCreate(
                    requires=(constants.AMPHORA_ID,
                              constants.BUILD_TYPE_PRIORITY),
                    provides=constants.COMPUTE_ID))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amphora_flow.add(
            compute_tasks.ComputeActiveWait(requires=(constants.COMPUTE_ID,
                                                      constants.AMPHORA_ID),
                                            provides=constants.COMPUTE_OBJ))
        create_amphora_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraComputeConnectivityWait(
                requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraReadyInDB(requires=constants.AMPHORA))

        return create_amphora_flow
Esempio n. 7
0
    def get_create_amphora_flow(self):
        """Creates a flow to create an amphora.

        Ideally that should be configurable in the
        config file - a db session needs to be placed
        into the flow

        :returns: The flow for creating the amphora
        """
        create_amphora_flow = linear_flow.Flow(constants.CREATE_AMPHORA_FLOW)
        create_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        if self.REST_AMPHORA_DRIVER:
            create_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))

            create_amphora_flow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            create_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM),
                    provides=constants.COMPUTE_ID))
        else:
            create_amphora_flow.add(
                compute_tasks.ComputeCreate(requires=constants.AMPHORA_ID,
                                            provides=constants.COMPUTE_ID))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amphora_flow.add(
            compute_tasks.ComputeWait(requires=constants.COMPUTE_ID,
                                      provides=constants.COMPUTE_OBJ))
        create_amphora_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraReadyInDB(requires=constants.AMPHORA))

        return create_amphora_flow
Esempio n. 8
0
    def _get_amp_net_subflow(self, sf_name):
        flows = []
        flows.append(
            network_tasks.PlugVIPAmpphora(
                name=sf_name + '-' + constants.PLUG_VIP_AMPHORA,
                requires=(constants.LOADBALANCER, constants.AMPHORA,
                          constants.SUBNET),
                provides=constants.AMP_DATA))

        flows.append(
            network_tasks.ApplyQosAmphora(
                name=sf_name + '-' + constants.APPLY_QOS_AMP,
                requires=(constants.LOADBALANCER, constants.AMP_DATA,
                          constants.UPDATE_DICT)))
        flows.append(
            database_tasks.UpdateAmphoraVIPData(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_VIP_DATA,
                requires=constants.AMP_DATA))
        flows.append(
            database_tasks.ReloadAmphora(name=sf_name + '-' +
                                         constants.RELOAD_AMP_AFTER_PLUG_VIP,
                                         requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        flows.append(
            database_tasks.ReloadLoadBalancer(
                name=sf_name + '-' + constants.RELOAD_LB_AFTER_PLUG_VIP,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        flows.append(
            network_tasks.GetAmphoraNetworkConfigs(
                name=sf_name + '-' + constants.GET_AMP_NETWORK_CONFIG,
                requires=(constants.LOADBALANCER, constants.AMPHORA),
                provides=constants.AMPHORA_NETWORK_CONFIG))
        flows.append(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                name=sf_name + '-' + constants.AMP_POST_VIP_PLUG,
                rebind={
                    constants.AMPHORAE_NETWORK_CONFIG:
                    constants.AMPHORA_NETWORK_CONFIG
                },
                requires=(constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        return flows
Esempio n. 9
0
    def _get_vthunder_for_amphora_subflow(self, prefix, role):
        """Subflow to create lb in existing vThunder."""

        sf_name = prefix + '-' + a10constants.LB_TO_VTHUNDER_SUBFLOW
        vthunder_for_amphora_subflow = linear_flow.Flow(sf_name)
        vthunder_for_amphora_subflow.add(
            database_tasks.CreateAmphoraInDB(name=sf_name + '-' +
                                             constants.CREATE_AMPHORA_INDB,
                                             provides=constants.AMPHORA_ID))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.ValidateComputeForProject(
                name=sf_name + '-' + a10constants.VALIDATE_COMPUTE_FOR_PROJECT,
                requires=constants.LOADBALANCER,
                inject={"role": role},
                provides=constants.COMPUTE_ID))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateAmphoraComputeId(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        vthunder_for_amphora_subflow.add(
            compute_tasks.ComputeActiveWait(
                name=sf_name + '-' + constants.COMPUTE_WAIT,
                requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
                provides=constants.COMPUTE_OBJ))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateAmphoraInfo(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
                provides=constants.AMPHORA))
        # create vThunder entry in custom DB
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.CreateVThunderEntry(
                name=sf_name + '-' + a10constants.CREATE_VTHUNDER_ENTRY,
                requires=(constants.AMPHORA, constants.LOADBALANCER),
                inject={
                    "role": role,
                    "status": constants.PENDING_CREATE
                }))
        # Get VThunder details from database
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.GetVThunderByLoadBalancer(
                name=sf_name + '-' + a10constants.VTHUNDER_BY_LB,
                requires=constants.LOADBALANCER,
                provides=a10constants.VTHUNDER))
        vthunder_for_amphora_subflow.add(
            database_tasks.ReloadLoadBalancer(
                name=sf_name + '-' + constants.RELOADLOAD_BALANCER,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        vthunder_for_amphora_subflow.add(
            a10_network_tasks.GetLBResourceSubnet(
                name=sf_name + '-' + a10constants.GET_LB_RESOURCE,
                rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
                provides=constants.SUBNET))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.GetChildProjectsOfParentPartition(
                name=sf_name + '-' + a10constants.GET_PROJECT_COUNT,
                requires=[a10constants.VTHUNDER],
                rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
                provides=a10constants.PARTITION_PROJECT_LIST))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.CountLoadbalancersInProjectBySubnet(
                name=sf_name + '-' + a10constants.GET_LB_COUNT_SUBNET,
                requires=[
                    constants.SUBNET, a10constants.PARTITION_PROJECT_LIST
                ],
                provides=a10constants.LB_COUNT_SUBNET))
        vthunder_for_amphora_subflow.add(
            a10_network_tasks.AllocateVIP(
                name=sf_name + '-' + a10constants.ALLOCATE_VIP,
                requires=[
                    constants.LOADBALANCER, a10constants.LB_COUNT_SUBNET
                ],
                provides=constants.VIP))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateVIPAfterAllocation(
                name=sf_name + '-' + a10constants.UPDATE_VIP_AFTER_ALLOCATION,
                requires=(constants.LOADBALANCER_ID, constants.VIP),
                provides=constants.LOADBALANCER))
        vthunder_for_amphora_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        vthunder_for_amphora_subflow.add(
            database_tasks.ReloadAmphora(name=sf_name + '-' +
                                         constants.RELOAD_AMPHORA,
                                         requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        vthunder_for_amphora_subflow.add(
            vthunder_tasks.AllowL2DSR(
                name=sf_name + '-' + a10constants.ALLOW_L2DSR,
                requires=(constants.SUBNET, constants.AMPHORA)))
        if role == constants.ROLE_MASTER:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))
        return vthunder_for_amphora_subflow
Esempio n. 10
0
    def _get_create_amp_for_lb_subflow(self, prefix, role):
        """Flow to create a new vThunder for lb."""

        sf_name = prefix + '-' + constants.CREATE_AMP_FOR_LB_SUBFLOW
        create_amp_for_lb_subflow = linear_flow.Flow(sf_name)
        create_amp_for_lb_subflow.add(
            database_tasks.CreateAmphoraInDB(name=sf_name + '-' +
                                             constants.CREATE_AMPHORA_INDB,
                                             provides=constants.AMPHORA_ID))
        # VIP subnet integration at bootup
        create_amp_for_lb_subflow.add(
            database_tasks.ReloadLoadBalancer(
                name=sf_name + '-' + constants.RELOADLOAD_BALANCER,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        require_server_group_id_condition = (
            role in (constants.ROLE_BACKUP, constants.ROLE_MASTER)
            and CONF.a10_nova.enable_anti_affinity)

        if require_server_group_id_condition:
            create_amp_for_lb_subflow.add(
                compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(constants.AMPHORA_ID,
                              constants.BUILD_TYPE_PRIORITY,
                              constants.SERVER_GROUP_ID,
                              constants.LOADBALANCER),
                    provides=constants.COMPUTE_ID))
        else:
            create_amp_for_lb_subflow.add(
                compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(constants.AMPHORA_ID,
                              constants.BUILD_TYPE_PRIORITY,
                              constants.LOADBALANCER),
                    provides=constants.COMPUTE_ID))

        create_amp_for_lb_subflow.add(
            database_tasks.UpdateAmphoraComputeId(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(
            database_tasks.MarkAmphoraBootingInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_BOOTING_INDB,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(
            compute_tasks.ComputeActiveWait(
                name=sf_name + '-' + constants.COMPUTE_WAIT,
                requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
                provides=constants.COMPUTE_OBJ))
        create_amp_for_lb_subflow.add(
            database_tasks.UpdateAmphoraInfo(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
                provides=constants.AMPHORA))
        # create vThunder entry in custom DB
        create_amp_for_lb_subflow.add(
            a10_database_tasks.CreateVThunderEntry(
                name=sf_name + '-' + a10constants.CREATE_VTHUNDER_ENTRY,
                requires=(constants.AMPHORA, constants.LOADBALANCER),
                inject={
                    a10constants.ROLE: role,
                    a10constants.STATUS: constants.PENDING_CREATE
                }))
        # Get VThunder details from database
        create_amp_for_lb_subflow.add(
            a10_database_tasks.GetVThunderByLoadBalancer(
                name=sf_name + '-' + a10constants.VTHUNDER_BY_LB,
                requires=constants.LOADBALANCER,
                provides=a10constants.VTHUNDER))
        create_amp_for_lb_subflow.add(
            vthunder_tasks.VThunderComputeConnectivityWait(
                name=sf_name + '-' +
                a10constants.WAIT_FOR_VTHUNDER_CONNECTIVITY,
                requires=(a10constants.VTHUNDER, constants.AMPHORA)))
        create_amp_for_lb_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        create_amp_for_lb_subflow.add(
            database_tasks.ReloadAmphora(name=sf_name + '-' +
                                         constants.RELOAD_AMPHORA,
                                         requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        create_amp_for_lb_subflow.add(
            a10_network_tasks.GetLBResourceSubnet(
                name=sf_name + '-' + a10constants.GET_LB_RESOURCE,
                rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
                provides=constants.SUBNET))
        create_amp_for_lb_subflow.add(
            vthunder_tasks.AllowL2DSR(
                name=sf_name + '-' + a10constants.ALLOW_L2DSR,
                requires=(constants.SUBNET, constants.AMPHORA)))
        if role == constants.ROLE_MASTER:
            create_amp_for_lb_subflow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            create_amp_for_lb_subflow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            create_amp_for_lb_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        return create_amp_for_lb_subflow
Esempio n. 11
0
    def _get_create_amp_for_lb_subflow(self, prefix, role):
        """Create a new amphora for lb."""

        sf_name = prefix + '-' + constants.CREATE_AMP_FOR_LB_SUBFLOW
        create_amp_for_lb_subflow = linear_flow.Flow(sf_name)
        create_amp_for_lb_subflow.add(database_tasks.CreateAmphoraInDB(
            name=sf_name + '-' + constants.CREATE_AMPHORA_INDB,
            provides=constants.AMPHORA_ID))

        anti_affinity = CONF.nova.enable_anti_affinity

        if self.REST_AMPHORA_DRIVER:
            create_amp_for_lb_subflow.add(cert_task.GenerateServerPEMTask(
                name=sf_name + '-' + constants.GENERATE_SERVER_PEM,
                provides=constants.SERVER_PEM))

            create_amp_for_lb_subflow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    name=sf_name + '-' + constants.UPDATE_CERT_EXPIRATION,
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            if role in (constants.ROLE_BACKUP, constants.ROLE_MASTER
                        ) and anti_affinity:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM,
                              constants.SERVER_GROUP_ID),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM),
                    provides=constants.COMPUTE_ID))
        else:

            if role in (constants.ROLE_BACKUP, constants.ROLE_MASTER
                        ) and anti_affinity:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(constants.AMPHORA_ID, constants.SERVER_GROUP_ID),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=constants.AMPHORA_ID,
                    provides=constants.COMPUTE_ID))

        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraComputeId(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraBootingInDB(
            name=sf_name + '-' + constants.MARK_AMPHORA_BOOTING_INDB,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(compute_tasks.ComputeWait(
            name=sf_name + '-' + constants.COMPUTE_WAIT,
            requires=constants.COMPUTE_ID,
            provides=constants.COMPUTE_OBJ))
        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraInfo(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
            provides=constants.AMPHORA))
        create_amp_for_lb_subflow.add(amphora_driver_tasks.AmphoraFinalize(
            name=sf_name + '-' + constants.AMPHORA_FINALIZE,
            requires=constants.AMPHORA))
        create_amp_for_lb_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        create_amp_for_lb_subflow.add(database_tasks.ReloadAmphora(
            name=sf_name + '-' + constants.RELOAD_AMPHORA,
            requires=constants.AMPHORA_ID,
            provides=constants.AMPHORA))

        if role == constants.ROLE_MASTER:
            create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraMasterInDB(
                name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraBackupInDB(
                name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            create_amp_for_lb_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        return create_amp_for_lb_subflow
Esempio n. 12
0
    def get_failover_flow(self,
                          role=constants.ROLE_STANDALONE,
                          load_balancer=None):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)

        failover_amphora_flow.add(
            lifecycle_tasks.AmphoraToErrorOnRevertTask(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # Note: It seems intuitive to boot an amphora prior to deleting
        #       the old amphora, however this is a complicated issue.
        #       If the target host (due to anit-affinity) is resource
        #       constrained, this will fail where a post-delete will
        #       succeed. Since this is async with the API it would result
        #       in the LB ending in ERROR though the amps are still alive.
        #       Consider in the future making this a complicated
        #       try-on-failure-retry flow, or move upgrade failovers to be
        #       synchronous with the API. For now spares pool and act/stdby
        #       will mitigate most of this delay.

        # Delete the old amphora
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraPendingDeleteInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraHealthBusy(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            network_tasks.WaitForPortDetach(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # If this is an unallocated amp (spares pool), we're done
        if not load_balancer:
            failover_amphora_flow.add(
                database_tasks.DisableAmphoraHealthMonitoring(
                    rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                    requires=constants.AMPHORA))
            return failover_amphora_flow

        # Save failed amphora details for later
        failover_amphora_flow.add(
            database_tasks.GetAmphoraDetails(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA,
                provides=constants.AMP_DATA))

        # Get a new amphora
        # Note: Role doesn't matter here.  We will update it later.
        get_amp_subflow = self.get_amphora_for_lb_subflow(
            prefix=constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(get_amp_subflow)

        # Update the new amphora with the failed amphora details
        failover_amphora_flow.add(
            database_tasks.UpdateAmpFailoverDetails(
                requires=(constants.AMPHORA, constants.AMP_DATA)))

        # Update the data stored in the flow from the database
        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        failover_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))

        # Prepare to reconnect the network interface(s)
        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))
        failover_amphora_flow.add(
            database_tasks.GetAmphoraeFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.AMPHORAE))

        # Plug the VIP ports into the new amphora
        # The reason for moving these steps here is the udp listeners want to
        # do some kernel configuration before Listener update for forbidding
        # failure during rebuild amphora.
        failover_amphora_flow.add(
            network_tasks.PlugVIPPort(
                requires=(constants.AMPHORA,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.AMPHORA, constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))

        # Listeners update needs to be run on all amphora to update
        # their peer configurations. So parallelize this with an
        # unordered subflow.
        update_amps_subflow = unordered_flow.Flow(
            constants.UPDATE_AMPS_SUBFLOW)

        timeout_dict = {
            constants.CONN_MAX_RETRIES:
            CONF.haproxy_amphora.active_connection_max_retries,
            constants.CONN_RETRY_INTERVAL:
            CONF.haproxy_amphora.active_connection_rety_interval
        }

        # Setup parallel flows for each amp. We don't know the new amp
        # details at flow creation time, so setup a subflow for each
        # amp on the LB, they let the task index into a list of amps
        # to find the amphora it should work on.
        amp_index = 0
        for amp in load_balancer.amphorae:
            if amp.status == constants.DELETED:
                continue
            update_amps_subflow.add(
                amphora_driver_tasks.AmpListenersUpdate(
                    name=constants.AMP_LISTENER_UPDATE + '-' + str(amp_index),
                    requires=(constants.LISTENERS, constants.AMPHORAE),
                    inject={
                        constants.AMPHORA_INDEX: amp_index,
                        constants.TIMEOUT_DICT: timeout_dict
                    }))
            amp_index += 1

        failover_amphora_flow.add(update_amps_subflow)

        # Plug the member networks into the new amphora
        failover_amphora_flow.add(
            network_tasks.CalculateAmphoraDelta(
                requires=(constants.LOADBALANCER, constants.AMPHORA),
                provides=constants.DELTA))

        failover_amphora_flow.add(
            network_tasks.HandleNetworkDelta(requires=(constants.AMPHORA,
                                                       constants.DELTA),
                                             provides=constants.ADDED_PORTS))

        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))

        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                name='octavia-failover-LB-reload-2',
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        # Handle the amphora role and VRRP if necessary
        if role == constants.ROLE_MASTER:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_BACKUP:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_STANDALONE:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(
                requires=(constants.LOADBALANCER, constants.LISTENERS,
                          constants.AMPHORA)))
        failover_amphora_flow.add(
            database_tasks.DisableAmphoraHealthMonitoring(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        return failover_amphora_flow
Esempio n. 13
0
    def get_failover_flow(self,
                          role=constants.ROLE_STANDALONE,
                          load_balancer_id=None):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)

        failover_amphora_flow.add(
            lifecycle_tasks.AmphoraToErrorOnRevertTask(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # Note: It seems intuitive to boot an amphora prior to deleting
        #       the old amphora, however this is a complicated issue.
        #       If the target host (due to anit-affinity) is resource
        #       constrained, this will fail where a post-delete will
        #       succeed. Since this is async with the API it would result
        #       in the LB ending in ERROR though the amps are still alive.
        #       Consider in the future making this a complicated
        #       try-on-failure-retry flow, or move upgrade failovers to be
        #       synchronous with the API. For now spares pool and act/stdby
        #       will mitigate most of this delay.

        # Delete the old amphora
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraPendingDeleteInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraHealthBusy(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            network_tasks.WaitForPortDetach(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # If this is an unallocated amp (spares pool), we're done
        if not load_balancer_id:
            failover_amphora_flow.add(
                database_tasks.DisableAmphoraHealthMonitoring(
                    rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                    requires=constants.AMPHORA))
            return failover_amphora_flow

        # Save failed amphora details for later
        failover_amphora_flow.add(
            database_tasks.GetAmphoraDetails(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA,
                provides=constants.AMP_DATA))

        # Get a new amphora
        # Note: Role doesn't matter here.  We will update it later.
        get_amp_subflow = self.get_amphora_for_lb_subflow(
            prefix=constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(get_amp_subflow)

        # Update the new amphora with the failed amphora details
        failover_amphora_flow.add(
            database_tasks.UpdateAmpFailoverDetails(
                requires=(constants.AMPHORA, constants.AMP_DATA)))

        # Update the data stored in the flow from the database
        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        failover_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))

        # Prepare to reconnect the network interface(s)
        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        # Plug the VIP ports into the new amphora
        failover_amphora_flow.add(
            network_tasks.PlugVIPPort(
                requires=(constants.AMPHORA,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.AMPHORA, constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))

        # Plug the member networks into the new amphora
        failover_amphora_flow.add(
            network_tasks.CalculateDelta(requires=constants.LOADBALANCER,
                                         provides=constants.DELTAS))
        failover_amphora_flow.add(
            network_tasks.HandleNetworkDeltas(requires=constants.DELTAS,
                                              provides=constants.ADDED_PORTS))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))

        # Handle the amphora role and VRRP if necessary
        if role == constants.ROLE_MASTER:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_BACKUP:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_STANDALONE:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))
        failover_amphora_flow.add(
            database_tasks.DisableAmphoraHealthMonitoring(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        return failover_amphora_flow
Esempio n. 14
0
    def get_failover_flow(self,
                          role=constants.ROLE_STANDALONE,
                          status=constants.AMPHORA_READY):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)

        failover_amphora_flow.add(
            lifecycle_tasks.AmphoraToErrorOnRevertTask(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        if status == constants.AMPHORA_ALLOCATED:
            failover_amphora_flow.add(
                database_tasks.TestLBStatusSetPendingInDB(
                    requires=constants.LOADBALANCER_ID))

        # Delete the old amphora
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraPendingDeleteInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraHealthBusy(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            network_tasks.WaitForPortDetach(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.DisableAmphoraHealthMonitoring(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # If this is an unallocated amp (spares pool), we're done
        if status != constants.AMPHORA_ALLOCATED:
            return failover_amphora_flow

        # Save failed amphora details for later
        failover_amphora_flow.add(
            database_tasks.GetAmphoraDetails(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA,
                provides=constants.AMP_DATA))

        # Get a new amphora
        # Note: Role doesn't matter here.  We will update it later.
        get_amp_subflow = self.get_amphora_for_lb_subflow(
            prefix=constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(get_amp_subflow)

        # Update the new amphora with the failed amphora details
        failover_amphora_flow.add(
            database_tasks.UpdateAmpFailoverDetails(
                requires=(constants.AMPHORA, constants.AMP_DATA)))

        # Update the data stored in the flow from the database
        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        failover_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))

        # Prepare to reconnect the network interface(s)
        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        # Plug the VIP ports into the new amphora
        failover_amphora_flow.add(
            network_tasks.PlugVIPPort(
                requires=(constants.AMPHORA,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.AMPHORA, constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))

        # Plug the member networks into the new amphora
        failover_amphora_flow.add(
            network_tasks.CalculateDelta(requires=constants.LOADBALANCER,
                                         provides=constants.DELTAS))
        failover_amphora_flow.add(
            network_tasks.HandleNetworkDeltas(requires=constants.DELTAS,
                                              provides=constants.ADDED_PORTS))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))

        # Handle the amphora role and VRRP if necessary
        if role == constants.ROLE_MASTER:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_BACKUP:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_STANDALONE:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))
        failover_amphora_flow.add(
            database_tasks.MarkLBActiveInDB(requires=[constants.LOADBALANCER]))

        return failover_amphora_flow
Esempio n. 15
0
    def get_extension_flow(self, distributor):
        """Extend a amphora for load balancer.

        :returns: The flow for loadbalancer extension
        """

        extension_flow = linear_flow.Flow(
            constants.EXTENSION_LOADBALANCER_FLOW)

        get_amp_subflow = self.get_amphora_for_lb_subflow(
            prefix=constants.EXTENSION_LOADBALANCER_FLOW,
            role=constants.ROLE_ACTIVE)
        extension_flow.add(get_amp_subflow)

        # Update the data stored in the flow from the database
        extension_flow.add(
            database_tasks.ReloadLoadBalancer(
                name='first',
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        extension_flow.add(
            network_tasks.PlugAmphoraVIP(requires=(constants.AMPHORA,
                                                   constants.LOADBALANCER),
                                         provides=constants.AMPS_DATA))
        extension_flow.add(
            database_tasks.UpdateAmphoraVIPData(requires=constants.AMPS_DATA))

        # Update the data stored in the flow from the database
        extension_flow.add(
            database_tasks.ReloadLoadBalancer(
                name='second',
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        extension_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))

        # Prepare to reconnect the network interface(s)
        extension_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        extension_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))
        extension_flow.add(
            database_tasks.GetAmphoraeFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.AMPHORAE))
        extension_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.AMPHORA, constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))

        timeout_dict = {
            constants.CONN_MAX_RETRIES:
            CONF.haproxy_amphora.active_connection_max_retries,
            constants.CONN_RETRY_INTERVAL:
            CONF.haproxy_amphora.active_connection_rety_interval
        }

        extension_flow.add(
            amphora_driver_tasks.AmpsListenersUpdate(
                name=constants.AMP_LISTENER_UPDATE,
                requires=(constants.LISTENERS, constants.LOADBALANCER),
                inject=({
                    constants.TIMEOUT_DICT: timeout_dict
                })))

        # Plug the member networks into the new amphora
        extension_flow.add(
            network_tasks.CalculateAmphoraDelta(
                requires=(constants.LOADBALANCER, constants.AMPHORA),
                provides=constants.DELTA))

        extension_flow.add(
            network_tasks.HandleNetworkDelta(requires=(constants.AMPHORA,
                                                       constants.DELTA),
                                             provides=constants.ADDED_PORTS))

        extension_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))

        extension_flow.add(
            database_tasks.ReloadLoadBalancer(
                name='octavia-extension-LB-reload-2',
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        extension_flow.add(
            self.get_distributor_flows('octavia-extension-distributor-flow',
                                       distributor))

        extension_flow.add(
            amphora_driver_tasks.ListenersStart(
                requires=(constants.LOADBALANCER, constants.LISTENERS,
                          constants.AMPHORA)))
        return extension_flow
Esempio n. 16
0
    def get_failover_flow(self):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(
            network_tasks.RetrievePortIDsOnAmphoraExceptLBNetwork(
                requires=constants.AMPHORA, provides=constants.PORTS))
        failover_amphora_flow.add(
            network_tasks.FailoverPreparationForAmphora(
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        failover_amphora_flow.add(
            database_tasks.GetUpdatedFailoverAmpNetworkDetailsAsList(
                requires=(constants.AMPHORA_ID, constants.AMPHORA),
                provides=constants.AMPS_DATA))
        if self.REST_AMPHORA_DRIVER:
            failover_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))
            failover_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM),
                    provides=constants.COMPUTE_ID))
        else:
            failover_amphora_flow.add(
                compute_tasks.ComputeCreate(requires=constants.AMPHORA_ID,
                                            provides=constants.COMPUTE_ID))
        failover_amphora_flow.add(
            database_tasks.UpdateAmphoraComputeId(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        failover_amphora_flow.add(
            database_tasks.AssociateFailoverAmphoraWithLBID(
                requires=(constants.AMPHORA_ID, constants.LOADBALANCER_ID)))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        wait_flow = linear_flow.Flow(
            constants.WAIT_FOR_AMPHORA,
            retry=retry.Times(CONF.controller_worker.amp_active_retries))
        wait_flow.add(
            compute_tasks.ComputeWait(requires=constants.COMPUTE_ID,
                                      provides=constants.COMPUTE_OBJ))
        wait_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        failover_amphora_flow.add(wait_flow)
        failover_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.FAILOVER_AMPHORA))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.UpdateAmphoraVIPData(requires=constants.AMPS_DATA))
        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))
        failover_amphora_flow.add(
            database_tasks.GetVipFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.VIP))
        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersUpdate(requires=(constants.LISTENERS,
                                                           constants.VIP)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            network_tasks.GetMemberPorts(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=(constants.LOADBALANCER, constants.AMPHORA),
                provides=constants.MEMBER_PORTS))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostNetworkPlug(
                rebind={
                    constants.AMPHORA: constants.FAILOVER_AMPHORA,
                    constants.PORTS: constants.MEMBER_PORTS
                },
                requires=(constants.AMPHORA, constants.PORTS)))
        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(requires=(constants.LISTENERS,
                                                          constants.VIP)))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))

        return failover_amphora_flow