注:swift1.1版使用swift-auth-add-user生成用户,swift1.3之后用户信息全部记录在proxy-server.conf 的[filter:tempauth]过滤器里,差别并不明显。文章完成时的安装环境为swift1.1,swift版本稳定之后会补充说明因版本差异而造成的变动!
OpenStack Hands on lab系列相关文章 见
相关阅读:
CentOS 6.4 安装OpenStack Nova
3.2swift应该如何使用OpenStack Object Storage Developer Guide 列举了通用API,这里只是对常用的操作做简单举例
约定:
account: test
user:tester
password: testing
account: test user:tester password: testing用户的生成参照1.1节swift安装教程。
(注:st是swifttool 的缩写,swift1.3之后st更名为swift,因此实践时请注意版本差异!)
3.2.1 使用st任何安装了st的机器都可以使用,并不限于storage node 或者 proxy-auth node
查询用户状态
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing stat
StorageURL: https://192.168.1.31:8080/v1/AUTH_d6084598cca04ee6a0951dbdd89612c6
Auth Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead
Account: AUTH_d6084598cca04ee6a0951dbdd89612c6
Containers: 2
Objects: 8
Bytes: 15177385
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing stat StorageURL: https://192.168.1.31:8080/v1/AUTH_d6084598cca04ee6a0951dbdd89612c6 Auth Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead Account: AUTH_d6084598cca04ee6a0951dbdd89612c6 Containers: 2 Objects: 8 Bytes: 15177385列表用户的container和object
swift@node31:~$ st -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing list
images
mp3
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing list images
1Mb.file
test.jpg
test1.jpg
swift@node31:~$ st -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing list images mp3 swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing list images 1Mb.file test.jpg test1.jpg上传object
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing upload images 1Mb.file
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing upload images 1Mb.file下载object
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing download images 1Mb.file
1Mb.file
swift@node31:~$ st -v -A https://192.168.1.31:11000/v1.0 -U test:tester -K testing download images 1Mb.file 1Mb.file 3.2.2使用curlcurl用来自定义网络报文,因此可以和提供Restful API的swift进行交互。从curl的格式来看,大概能窥测到使用语言封装object请求的方法。:)
查询用户状态
zzfancy@129:~$ curl -k -D - -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' https://192.168.1.31:11000/v1.0
HTTP/1.1 204 No Content
X-Storage-Url: https://192.168.1.31:8080/v1/AUTH_d6084598cca04ee6a0951dbdd89612c6
X-Storage-Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead
X-Auth-Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead
Content-Length: 0
Date: Tue, 02 Aug 2011 08:43:10 GMT
zzfancy@129:~$ curl -k -D - -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' https://192.168.1.31:11000/v1.0 HTTP/1.1 204 No Content X-Storage-Url: https://192.168.1.31:8080/v1/AUTH_d6084598cca04ee6a0951dbdd89612c6 X-Storage-Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead X-Auth-Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead Content-Length: 0 Date: Tue, 02 Aug 2011 08:43:10 GMT查看空间使用情况
zzfancy@129:~$ curl -k -X HEAD -D - -H 'X-Auth-Token: AUTH_tkefdc936d7e94493982d78f3dd6c16ead' https://192.168.1.31:8080/v1/AUTH_d6084598cca04ee6a0951dbdd89612c6
HTTP/1.1 204 No Content
X-Account-Object-Count: 8
X-Account-Bytes-Used: 15177385
X-Account-Container-Count: 2
Content-Length: 0