当前位置: 首页 > 工具软件 > boto > 使用案例 >

在客户端使用python来调用boto S3 API来操作librados库

公西马鲁
2023-12-01

实验环境:
客户端:ubuntu17.04
服务端: ceph集群
基本上常用的API接口在下面网页里面都有:
http://boto.readthedocs.io/en/latest/s3_tut.html
下面附上我的一个示例:

#!/usr/bin/pyhton
import boto
import boto.s3.connection
from timeit import Timer
from boto.s3.key import Key
access_key = 'OHP5X3XQSC1IOWQUYDNT'
secret_key = 'BqiUlhfWGvsz30FVCjzUhPesGH4NDa69joNHEYep'
conn = boto.connect_s3(
            aws_access_key_id = access_key,
                aws_secret_access_key = secret_key,
                    host = '192.168.1.220', port=80,
                        is_secure=False,
                            calling_format = boto.s3.connection.OrdinaryCallingFormat(),
                            )

'''
print "create a bucket\n"
bucket = conn.create_bucket('my-first-s3-bucket')

'''


'''
print "write file to bucket:\n"
bucket = conn.get_bucket('my-first-s3-bucket')
k = Key(bucket)
k.key = 'myfile'
for i in range(1024):
       k.set_contents_from_filename('lxl.txt')
'''



'''
print "delete a bucket:\n"

full_bucket = conn.get_bucket('my-first-s3-bucket')
for key in full_bucket.list():
    key.delete()

conn.delete_bucket('my-first-s3-bucket')
'''




for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(name = bucket.name,created = bucket.creation_date,)

这个代码示例接的是我的下面这篇博客,如果不太明白的可以看看:
http://blog.csdn.net/cloudxli/article/details/79438857

 类似资料: