Esempio n. 1
0
def get_bucket(conn, bucket_id):
    """
    Get a bucket from an s3 connection

    :param conn: The ``boto.s3.connection.S3Connection``
    :param bucket_id: ID of the bucket to fetch
    :raises ``glance.exception.NotFound`` if bucket is not found.
    """

    bucket = conn.get_bucket(bucket_id)
    if not bucket:
        msg = "Could not find bucket with ID %s" % bucket_id
        LOG.debug(msg)
        raise exception.NotFound(msg)

    return bucket
Esempio n. 2
0
def get_key(bucket, obj):
    """
    Get a key from a bucket

    :param bucket: The ``boto.s3.Bucket``
    :param obj: Object to get the key for
    :raises ``glance.exception.NotFound`` if key is not found.
    """

    key = bucket.get_key(obj)
    if not key or not key.exists():
        msg = ("Could not find key %(obj)s in bucket %(bucket)s" % {
            'obj': obj,
            'bucket': bucket
        })
        LOG.debug(msg)
        raise exception.NotFound(msg)
    return key