Example #1
0
    def _update_cluster_bucket(self):
        bucket_name = AXClusterConfigPath(name_id=self._name_id).bucket()
        cluster_bucket = Cloud().get_bucket(bucket_name, aws_profile=self._aws_profile, region=self._aws_region)

        if not cluster_bucket.create():
            raise AXPlatformException("Failed to create S3 bucket {}".format(cluster_bucket.get_bucket_name()))
        logger.info("Created %s bucket ... DONE", cluster_bucket.get_bucket_name())
Example #2
0
    def update(self, iam):
        """
        Create all buckets in portal account.
        """
        logger.info("Creating applatix-support and applatix-upgrade buckets ...")
        support_bucket = Cloud().get_bucket(AXSupportConfigPath(name_id=self._name_id).bucket(),
                                            aws_profile=self._aws_profile, region=self._aws_region)
        upgrade_bucket = Cloud().get_bucket(AXUpgradeConfigPath(name_id=self._name_id).bucket(),
                                            aws_profile=self._aws_profile, region=self._aws_region)

        # Retry create while bucket is created is fine
        if not support_bucket.create():
            raise AXPlatformException("Failed to create S3 bucket {}".format(support_bucket.get_bucket_name()))

        # If policy is already there, we don't update
        if not support_bucket.get_policy():
            logger.info("Argo support bucket policy does not exist, creating new one...")
            if not support_bucket.put_policy(
                    policy=self._generate_bucket_policy_string(template=SUPPORT_BUCKET_POLICY_TEMPLATE,
                                                               bucket_name=support_bucket.get_bucket_name(),
                                                               iam=iam)
            ):
                raise AXPlatformException(
                    "Failed to configure policy for S3 bucket {}".format(support_bucket.get_bucket_name()))

        if not upgrade_bucket.create():
            raise AXPlatformException("Failed to create S3 bucket {}".format(support_bucket.get_bucket_name()))

        if not upgrade_bucket.get_policy():
            logger.info("Argo upgrade bucket policy does not exist, creating new one...")
            if not upgrade_bucket.put_policy(
                    policy=self._generate_bucket_policy_string(template=SUPPORT_BUCKET_POLICY_TEMPLATE,
                                                               bucket_name=upgrade_bucket.get_bucket_name(),
                                                               iam=iam)
            ):
                raise AXPlatformException(
                    "Failed to configure policy for S3 bucket {}".format(support_bucket.get_bucket_name()))

        # Tag them right away to avoid race deletion.
        upgrade_bucket.put_object(key=AXUpgradeConfigPath(name_id=self._name_id).tag(),
                                  data="tag",
                                  ACL="bucket-owner-full-control")
        support_bucket.put_object(key=AXSupportConfigPath(name_id=self._name_id).tag(),
                                  data="tag",
                                  ACL="bucket-owner-full-control")
        logger.info("Created %s and %s buckets ... DONE", support_bucket.get_bucket_name(),
                    upgrade_bucket.get_bucket_name())
Example #3
0
    def _update_data_bucket(self):
        data_bucket = Cloud().get_bucket(AXClusterDataPath(name_id=self._name_id).bucket(),
                                         aws_profile=self._aws_profile, region=self._aws_region)

        if not data_bucket.create():
            raise AXPlatformException("Failed to create S3 bucket {}".format(data_bucket.get_bucket_name()))
        # Update CORS config for data bucket too.
        logger.info("Checking CORS config for %s.", data_bucket.get_bucket_name())
        data_bucket.put_cors(DATA_CORS_CONFIG)

        logger.info("Created %s bucket ... DONE", data_bucket.get_bucket_name())