Exemplo n.º 1
0
def create_rok_bucket(bucket, client=None):
    from rok_gw_client.client import RokClient, GatewayClientError
    if client is None:
        client = RokClient()

    # FIXME: Currently the Rok API only supports update-or-create for buckets,
    # so we do a HEAD first to avoid updating an existing bucket. This
    # obviously has a small race, which should be removed by extending the Rok
    # API with an exclusive creation API call.
    try:
        return False, client.bucket_info(bucket)
    except GatewayClientError as e:
        if e.response.status_code != 404:
            raise

        logger.info("Creating bucket: %s", bucket)
        return client.bucket_create(bucket)
Exemplo n.º 2
0
def create_rok_bucket(bucket, client=None):
    """Create a new Rok bucket."""
    log.info("Creating Rok bucket '%s'...", bucket)
    from rok_gw_client.client import RokClient, GatewayClientError
    if client is None:
        client = RokClient()

    # FIXME: Currently the Rok API only supports update-or-create for buckets,
    # so we do a HEAD first to avoid updating an existing bucket. This
    # obviously has a small race, which should be removed by extending the Rok
    # API with an exclusive creation API call.
    try:
        bucket_info = client.bucket_info(bucket)
        log.info("Rok bucket '%s' already exists", bucket)
        return False, bucket_info
    except GatewayClientError as e:
        if e.response.status_code != 404:
            raise

        created, bucket_info = client.bucket_create(bucket)
        log.info("Successfully created Rok bucket '%s'", bucket)
        return created, bucket_info