Created
October 15, 2012 05:27
-
-
Save bussyjd/3890939 to your computer and use it in GitHub Desktop.
A simple demonstration of the S3 API of RADOS Gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto | |
import boto.s3.connection | |
access_key = 'J64L2H11GU5DA15E7KY3' | |
secret_key = '5ClGdd9ttXNDOAhqvBQbqXzZIXQGK++QEb9GojMY' | |
conn = boto.connect_s3( | |
aws_access_key_id = access_key, | |
aws_secret_access_key = secret_key, | |
host = 'stacktest3', | |
calling_format = boto.s3.connection.OrdinaryCallingFormat(), | |
) | |
# Outputs the list of the current buckets | |
print "List of buckets:" | |
for bucket in conn.get_all_buckets(): | |
print "{name}\t{created}".format( | |
name = bucket.name, | |
created = bucket.creation_date, | |
) | |
### Bucket creation | |
bucketname = 'my-bucket' | |
bucket = conn.create_bucket(bucketname) | |
key = bucket.new_key('test.txt') | |
key.set_contents_from_string('Welcome to RADOS Gateway test!') | |
### Print the list of keys on my bucket | |
print "List of keys in "+bucketname+":" | |
for key in bucket.list(): | |
print "{name}\t{size}\t{modified}".format( | |
name = key.name, | |
size = key.size, | |
modified = key.last_modified, | |
) | |
### Prints the content o my key | |
print "The content of text.txt is:" | |
print key.get_contents_as_string() | |
### Deletes the key | |
bucket.delete_key('test.txt') | |
### Bucket deletion | |
### /!\ The bucket must be empty before | |
conn.delete_bucket(bucket.name) | |
print 'bucket "' + bucketname + '" successfuly deleted\n' | |
print "\t[OK]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment