0
点赞
收藏
分享

微信扫一扫

ceph swift python 例子

whiteMu 2023-03-17 阅读 76

import swiftclient
user = 'kaka:momo'
key = '123456'

conn = swiftclient.Connection(
user=user,
key=key,
authurl='http://192.168.164.221:5588/auth',
)
container_name = 'my-new-container'
conn.put_container(container_name)

with open('hello.txt', 'r') as hello_file:
conn.put_object(container_name, 'hello.txt',
contents= hello_file.read(),
content_type='text/plain')

#LIST OWNED CONTAINERS
for container in conn.get_account()[1]:
print(container['name'])
#The output will look something like this:


#LIST A CONTAINER’S CONTENT
#This gets a list of objects in the container, and prints out each object’s name, the file size, and last modified date:

for data in conn.get_container(container_name)[1]:
print('{0}\t{1}\t{2}'.format(data['name'], data['bytes'], data['last_modified']))

obj_tuple = conn.get_object(container_name, 'hello.txt')
with open('my_hello.txt', 'w') as my_hello:
my_hello.write(str(obj_tuple[1], 'utf-8'))
#DELETE AN OBJECT
#This deletes the object hello.txt:

conn.delete_object(container_name, 'hello.txt')
#DELETE A CONTAINER
#The container must be empty! Otherwise the request won’t work!

conn.delete_container(container_name)

提醒:

user 需要为子用户

authurl 结尾为 /auth


举报

相关推荐

0 条评论