Openstack Swift Quotas初探(Grizzly)

Swift组件是Openstack的对象存储(Object Storage)解决方案。在早期的版本中,swift对于配额是没有限制的,不能够对不同用户所使用的空间进行限制。后来出现了开源的中间件 swquota(https://github.com/cschwede/swquota)可以对swift做出配额的限制,如今在2013年4月发布的Grizzly版本Openstack中,swift(1.8.0)集成了swquota中间件,以下是对此功能的初步探究。

在新版本的swift中的配额主要体现在Container Quotas与Account Quotas两个功能上,分别是对Container和Account上传文件的大小、个数等方面进行限制,需要使用此功能首先要在/etc/swift/proxy-server.conf文件中进行配置,修改完后重启swift服务:


#1.修改[pipeline:main]

[pipeline:main]

pipeline = catch_errors healthcheck cache ratelimit authtoken keystoneauth account-quotas container-quotas proxy-logging proxy-server


#2.加入[filter:container-quotas]与[filter:account-quotas]
[filter:container-quotas]
use = egg:swift#container_quotas
[filter:account-quotas]
use = egg:swift#account_quotas


配置重启完毕,需要对配额进行设置,这个过程需要设置reseller用户角色
1. 假定添加名为bingo的tenant
keystone --os-username admin --os_password adminpwd --os_tenant_name admin --os_auth_url http://localhost:5000/v2.0 tenant-create --name bingo --description bingo_tenant --enabled true
2.在bingo下添加用户reseller
keystone --os-username admin --os_password adminpwd --os_tenant_name admin --os_auth_url http://localhost:5000/v2.0 user-create --name reseller --tenant-id tenant_id --pass bingo --email bingo@example.com --enabled true
3.将reseller加入ResellerAdmin角色中
keystone role-list
keystone user-role-add --user-id xxxxx --role-id xxxxx --tenant-id xxxxx


添加reseller用户之后就可以设置相关的配额了:

Container_Quotas:

1. X-Container-Meta-Quota-Bytes -- 目标container可上传的最大字节数

2. X-Container-Meta-Quota-Count -- 目标container可上传的最大文件个数

Account_Quotas:

1. X-Account-Meta-Quota-Bytes -- 单个上传最大字节数

2. Quota-Byes -- 1必须配合2才能有效果

设置方法:

swift -V 2 -A http://192.168.65.203:5000/v2.0 -U test:reseller -K reseller post -m quota-bytes:5000

注:reseller用户必须在ResellerAdmin角色中,这个限额只针对test tenant有效

取消设置

swift -V 2 -A http://192.168.65.203:5000/v2.0 -U test:reseller -K reseller post -m quota-bytes:


Bug fix:

使用keystone做认证时,针对Quota-Byes设置可能会出现 [403 Forbidden] 错误

修改swift/common/middleware/account_quotas.py 文件

new_quota = request.headers.get('X-Account-Meta-Quota-Bytes')

#Add by kevin start
eccp_roles = request.environ.get('HTTP_X_ROLES', '')
if isinstance(eccp_roles, basestring):
    if (set(eccp_roles.split(',')) & set({'reseller','reseller_admin','ResellerAdmin'})):
        request.environ['reseller_request'] = True
#Add by kevin end

if request.environ.get('reseller_request') is True:
    if new_quota and not new_quota.isdigit():
        return HTTPBadRequest()
    return self.app


使得当用户加入ResellerAdmin角色之后能够通过验证。


另外需要注意的是在实验过程中不断发生swift与keystone验证401 Unauthorized的问题,经调试发现是keystone中关于swift的endpoint的注册IP地址使用的是虚拟机分配的地址(本人是在虚拟机的环境下再安装虚拟机实验,所以第一层虚拟机的地址是由openstack自动分配的fixed ip10.0.0.x类型,这样其他几台机器如果通过这个地址进行权限验证就可能出现问题,解决方法是将endpoint的地址修改为浮动ip),使用winpdb( http://winpdb.org/ )进行调试是非常不错的。


Good luck


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值