OpenStack Object Storage又名swift。
OpenStack Object Storage是一种冗余的,可扩展的,动态的存储服务提供者,其核心思想是提供一种安全的,自动调整大小和基于网络存取方式来存储数据。
OpenStack Object Storage允许用户存储与检索文件和内容通过一种简单的Web Service interface(ReST:Representational State Transfer)。如今,已有多种语言实现了ReSTful的API,所以对开发人员来说将这些整合到应用变得容易多了。
更多的关于OpenStack Object Storage信息:http://docs.openstack.org/developer/swift/
本文建立在你已经安装了OpenStack Object Storage服务
curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://172.26.xxx.xxx:xxxx/auth/v1.0
curl -k -X GET -H 'X-Auth-Token:AUTH_xxxxxxxxxxxxxxxxxxxxxxxxxxxx'http://172.26.xxx.xxx:xxxx/auth/v1/Auth_test
可以使用查询参数
curl -k -X GET -H 'X-Auth-Token:AUTH_xxxxxxxxxxxxxxxxxxxxxxxxxxxx'http://172.26.xxx.xxx:xxxx/auth/v1/Auth_test?limit=3
curl -v -X HEAD -H 'X-Auth-Token:AUTH_XXXXXXXXXXXXXXXXXXXXXX' http://172.26.xxx.xxx:xxxx/v1/AUTH_test?format=xml
返回以下响应信息
curl -v -X POST -H 'X-Auth-Token:AUTH_xxxxxxxxxxxxxxxxxx' -H 'X-Account-Meta-Book:swift' http://172.26.xxx.xxx:xxxx/v1/AUTH_test?
然后,查看账户元数据,发现该header已经添加
curl -v -X POST -H 'X-Auth-Token:AUTH_xxxxxxxxxxxxx' -H 'X-Remove-Account-Meta-Book:x' http://172.26.xxx.xxx:xxxx/v1/AUTH_test?format=xml
然后查看账户元数据,发现header已经删除
GET | /account/container | 列出对象 |
PUT | /account/container | 创建一个容器 |
DELETE | /account/container | 删除一个容器 |
HEAD | /account/container | 查询容器元数据 |
curl -v -X GET -H 'X-Auth-Token:AUTH_tkada7xxxxxxxx' http://172.26.xxx.xxx:xxxx/v1/AUTH_test/test
可以通过设置查询参数prefix来设置前缀匹配,如
curl -X GET -H 'X-Auth-Token:AUTH_tkada7cf96780947xxxx' http://172.26.xxx.xxx:xxxx/v1/AUTH_test/test?prefix=2385
查询AUTH_test账户,test容器下,已2385开头的对象
url -v -X PUT -H 'X-Auth-Token:AUTH_tkada7cf967809471xxxxxx' http://172.26.xxx.xxx:xxxx/v1/AUTH_test/learnCreateContainer
可以按照 X-Container-Meta-xxx的格式给容器添加标签,例如
curl -v -X PUT -H 'X-Auth-Token:AUTH_tk6fad162b657944ef9221ddxxxxx' -H 'X-Container-Meta-InspectedBy:lidashuai' http://172.26.xxx.xxx:8081/v1/AUTH_test/learnCreateContainer1
curl -v -X DELETE -H 'X-Auth-Token:AUTH_tk6fad162b657944ef9223a61ddxxxxx' http://172.26.xxx.xxx:xxxx/v1/AUTH_test/learnCreateContaine
GET | /account/container/object | 获取对象数据 |
PUT | /account/container/object | 创建或者更新对象 |
PUT | /account/container/object | 分块传输编码 |
DELETE | /account/container/object | 删除对象 |
HEAD | /account/container/object | 查看对象元数据 |
POST | /account/container/object | 更新对象元数据 |
curl -X GET -H 'X-Auth-Token:AUTH_tk6fad162b6xxxxxxx' -H 'Range: bytes=10-20' http://172.26.xxx.xxx:xxxx/v1/AUTH_test/test/961/E4D320B7-F335-xxxxxxx
响应体中包含对象数据,响应头包含对象元数据
curl -v -X PUT -T ./1.txt -H 'Content-Type: text/html' -H 'X-Auth-Token:AUTH_tk6faxxxxx' http://172.26.xxx.xxx:xxxx/v1/AUTH_xxxx/learnCreateContainer/1.txt
需要指定Content-Type或者Content-length在header中,否则会返回411错误
PUT /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
Content-Type: video/mp4
Content-Encoding: gzip
PUT /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.com
X-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
Content-Type: image/jpeg
X-Delete-At: 1339429105
PUT /<api version>/<account>/<destcontainer>/<destobject> HTTP/1.1
Host: <storage URL>
X-Auth-Token: <some-auth-token>
X-Copy-From: /<sourcecontainer>/<sourceobject>
Content-Length: 0