swift 设置account-quotas container-quotas

1.创建role ResellerAdmin
keystone role-create --name ResellerAdmin
keystone user-role-add --user=tester --tenant=test --role=ResellerAdmin

2.修改proxy-server.conf
#修改pipeline
pipeline = healthcheck proxy-logging cache authtoken keystoneauth proxy-logging account-quotas container-quotas  proxy-server
在最下方增加以下内容:
[filter:account-quotas]
use = egg:swift#account_quotas

[filter:container-quotas]
use = egg:swift#container_quotas

3重新启动proxyserver.

4.用户test可以给container设置quota
    #用test用户请求token.
    curl -d '{"auth": {"tenantName": "test", "passwordCredentials":{"username": "tester", "password": "testing"}}}' -H "Content-type: application/json" http://192.168.81.158:5000/v2.0/tokens
    #设置环境变量。
    export STORAGE_URL=http://192.168.81.158:8080/v1/AUTH_3e2a0a2df18b4f86a52e2dc6ad3cb989
    export TOKEN_ID=164b940abe0b4bfabc2701bb82819c1f
    
#查看account的元信息
curl --head   -H "X-Auth-Token:${TOKEN_ID}"  "${STORAGE_URL}"
HTTP/1.1 204 No Content
Content-Length: 0
Accept-Ranges: bytes
X-Timestamp: 1397700876.39185
X-Account-Bytes-Used: 460992
X-Account-Container-Count: 6
Content-Type: text/plain; charset=utf-8
X-Account-Object-Count: 9
X-Trans-Id: txcb63c0cea73b4dd88d7a8-0053732f4f
Date: Wed, 14 May 2014 08:54:39 GMT

#设置account的quota.
curl -d '' -H "X-Auth-Token:${TOKEN_ID}" -H "X-Account-Meta-Quota-Bytes: 560992" "${STORAGE_URL}"  

#再输入account的元信息,发现有元数据X-Account-Meta-Quota-Bytes: 560992

curl --head   -H "X-Auth-Token:${TOKEN_ID}"  "${STORAGE_URL}"
HTTP/1.1 204 No Content
Content-Length: 0
X-Account-Container-Count: 6
X-Account-Object-Count: 9
X-Timestamp: 1397700876.39185
X-Account-Bytes-Used: 460992
X-Account-Meta-Quota-Bytes: 560992
Content-Type: text/plain; charset=utf-8
Accept-Ranges: bytes
X-Trans-Id: tx1207c74f9c1c4ab8a85f5-0053732f8f
Date: Wed, 14 May 2014 08:55:43 GMT


#上传10m的文件,返加499错误。
curl -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer"

 curl -v -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer/10mfile" -T 10mfile
* About to connect() to 192.168.81.158 port 8080 (#0)
*   Trying 192.168.81.158... connected
* Connected to 192.168.81.158 (192.168.81.158) port 8080 (#0)
> PUT /v1/AUTH_3e2a0a2df18b4f86a52e2dc6ad3cb989/testContainer/10mfile HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.81.158:8080
> Accept: */*
> X-Auth-Token:164b940abe0b4bfabc2701bb82819c1f
> Content-Length: 10485760
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 499 Client Disconnect
< Content-Length: 89
< Content-Type: text/html; charset=UTF-8
< X-Trans-Id: tx22d77431507d49e2b4afe-0053733157
< Date: Wed, 14 May 2014 09:03:20 GMT
<
* Connection #0 to host 192.168.81.158 left intact
* Closing connection #0
<html><h1>Client Disconnect</h1><p>The client was disconnected during request.</p></html>
curl -H "X-Auth-Token:${TOKEN_ID}" ${STORAGE_URL}/testContainer


#remove account quota.
curl -d '' -H "X-Auth-Token:${TOKEN_ID}"  -H "X-Remove-Account-Meta-Quota-Bytes: anyvalue" "${STORAGE_URL}"
#再查看account元信息,没有X-Account-Meta-Quota-Bytes这一项。
curl -d '' -H "X-Auth-Token:${TOKEN_ID}" -H "X-Account-Meta-Quota-Bytes: " "${STORAGE_URL}"  
HTTP/1.1 204 No Content
Content-Length: 0
Accept-Ranges: bytes
X-Timestamp: 1397700876.39185
X-Account-Bytes-Used: 460992
X-Account-Container-Count: 7
Content-Type: text/plain; charset=utf-8
X-Account-Object-Count: 9
X-Trans-Id: tx6f366c2d26bc451b9d495-00537331fa
Date: Wed, 14 May 2014 09:06:02 GMT

#上传10m的文件,成功。
curl -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer"
 curl -v -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer/10mfile" -T 10mfile
curl  -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer"


#设置container testContainer的quota为20m.
curl -d '' -H "X-Auth-Token:${TOKEN_ID}" -H "X-Container-Meta-Quota-Bytes: 20000000" "${STORAGE_URL}/testContainer"  

#再次上传10m文件,上传不了,因为已经上传一个10m文件。
 curl -v -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer/10_2mfile" -T 10mfile
* About to connect() to 192.168.81.158 port 8080 (#0)
*   Trying 192.168.81.158... connected
* Connected to 192.168.81.158 (192.168.81.158) port 8080 (#0)
> PUT /v1/AUTH_3e2a0a2df18b4f86a52e2dc6ad3cb989/testContainer/10_2mfile HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.81.158:8080
> Accept: */*
> X-Auth-Token:164b940abe0b4bfabc2701bb82819c1f
> Content-Length: 10485760
> Expect: 100-continue
>
< HTTP/1.1 413 Request Entity Too Large
< Content-Length: 21
< Content-Type: text/html; charset=UTF-8
< X-Trans-Id: txb1961d9e568b4b16b4951-0053733923
< Date: Wed, 14 May 2014 09:36:35 GMT
<
* Connection #0 to host 192.168.81.158 left intact
* Closing connection #0

#上传1m文件,成功。
 curl -v -X PUT -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer/10_2mfile" -T 1mfile
* About to connect() to 192.168.81.158 port 8080 (#0)
*   Trying 192.168.81.158... connected
* Connected to 192.168.81.158 (192.168.81.158) port 8080 (#0)
> PUT /v1/AUTH_3e2a0a2df18b4f86a52e2dc6ad3cb989/testContainer/10_2mfile HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.81.158:8080
> Accept: */*
> X-Auth-Token:164b940abe0b4bfabc2701bb82819c1f
> Content-Length: 1048576
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 201 Created
< Last-Modified: Wed, 14 May 2014 09:36:45 GMT
< Content-Length: 0
< Etag: e65010dfb56424c697b504af3da87723
< Content-Type: text/html; charset=UTF-8
< X-Trans-Id: tx83bda1fef89a4253ad34f-005373392c
< Date: Wed, 14 May 2014 09:36:44 GMT
<
* Connection #0 to host 192.168.81.158 left intact
* Closing connection #0


#查看container元信息。
 curl --head -H "X-Auth-Token:${TOKEN_ID}" "${STORAGE_URL}/testContainer"
HTTP/1.1 204 No Content
Content-Length: 0
X-Container-Object-Count: 2
Accept-Ranges: bytes
X-Timestamp: 1400057949.42876
X-Container-Bytes-Used: 11534336
Content-Type: text/plain; charset=utf-8
X-Container-Meta-Quota-Bytes: 20000000
X-Trans-Id: txa8cdaef2035041168e81e-005373399b
Date: Wed, 14 May 2014 09:38:35 GMT

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值