def run(self):
        self.info("running")
        for region_name, accounts in self.manifest.get_accounts_by_region(
        ).items():
            yield general_tasks.DeleteCloudFormationStackTask(
                account_id=self.puppet_account_id,
                region=region_name,
                stack_name="servicecatalog-puppet-shares",
            )

        for (
                region_name,
                sharing_policies,
        ) in self.manifest.get_sharing_policies_by_region().items():
            yield EnsureEventBridgeEventBusTask(
                puppet_account_id=self.puppet_account_id,
                region=region_name,
            )

            yield GeneratePolicies(
                manifest_file_path=self.manifest_file_path,
                puppet_account_id=self.puppet_account_id,
                should_use_sns=self.should_use_sns,
                should_use_product_plans=self.should_use_product_plans,
                include_expanded_from=self.include_expanded_from,
                single_account=self.single_account,
                is_dry_run=self.is_dry_run,
                execution_mode=self.execution_mode,
                region=region_name,
                sharing_policies=sharing_policies,
            )

        self.info("Finished generating policies")
        for (
                region_name,
                shares_by_portfolio_account,
        ) in self.manifest.get_shares_by_region_portfolio_account(
                self.puppet_account_id).items():
            for (
                    portfolio_name,
                    shares_by_account,
            ) in shares_by_portfolio_account.items():
                for account_id, share in shares_by_account.items():
                    yield portfoliomanagement_tasks.CreateShareForAccountLaunchRegion(
                        manifest_file_path=self.manifest_file_path,
                        puppet_account_id=self.puppet_account_id,
                        account_id=account_id,
                        region=region_name,
                        portfolio=portfolio_name,
                    )

        self.write_output(self.params_for_results_display())
Ejemplo n.º 2
0
    def requires(self):
        portfolios = dict()
        requirements = dict(
            deletes=list(),
            ensure_event_buses=list(),
            generate_policies=list(),
            portfolios=portfolios,
        )
        for region_name, accounts in self.manifest.get_accounts_by_region(
        ).items():
            requirements["deletes"].append(
                general_tasks.DeleteCloudFormationStackTask(
                    account_id=self.puppet_account_id,
                    region=region_name,
                    stack_name="servicecatalog-puppet-shares",
                ))

        for (
                region_name,
                sharing_policies,
        ) in self.manifest.get_sharing_policies_by_region().items():
            requirements["ensure_event_buses"].append(
                EnsureEventBridgeEventBusTask(
                    puppet_account_id=self.puppet_account_id,
                    region=region_name,
                ))

            requirements["generate_policies"].append(
                GeneratePolicies(
                    puppet_account_id=self.puppet_account_id,
                    manifest_file_path=self.manifest_file_path,
                    region=region_name,
                    sharing_policies=sharing_policies,
                    should_use_sns=self.should_use_sns,
                    cache_invalidator=self.cache_invalidator,
                ))

        for (
                region_name,
                shares_by_portfolio_account,
        ) in self.manifest.get_shares_by_region_portfolio_account(
                self.puppet_account_id, self.section).items():
            for (
                    portfolio_name,
                    shares_by_account,
            ) in shares_by_portfolio_account.items():
                for account_id, share in shares_by_account.items():
                    i = "_".join([
                        str(self.puppet_account_id),
                        portfolio_name,
                        str(account_id),
                        region_name,
                    ])
                    portfolios[
                        i] = portfoliomanagement_tasks.GetPortfolioByPortfolioName(
                            manifest_file_path=self.manifest_file_path,
                            puppet_account_id=self.puppet_account_id,
                            portfolio=portfolio_name,
                            account_id=self.puppet_account_id,
                            region=region_name,
                            cache_invalidator=self.cache_invalidator,
                        )
        return requirements