Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bucket_usedspace and bucket_filecount functions for BucketManager class #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions qiniu/services/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from qiniu import config
from qiniu import http
from qiniu.utils import urlsafe_base64_encode, entry
from datetime import datetime, timedelta


class BucketManager(object):
Expand Down Expand Up @@ -359,6 +360,63 @@ def bucket_domain(self, bucket_name):
url = "{0}/v6/domain/list?tbl={1}".format(config.get_default("default_api_host"), bucket_name)
return self.__get(url, options)

def bucket_usedspace(self, bucket_name, begin_time=None, end_time=None, g=None):
"""
获取bucket的存储空间大小.可查询当天计量,统计延迟大概 5 分钟。
Args:
bucket_name: 存储空间名
begin_time: 起始日期字符串,闭区间,例如: 20060102150405
end_time: 结束日期字符串,开区间,例如: 20060102150405
g: 时间粒度,支持 day;当天支持5min、hour、day
"""
url = "{0}/v6/space".format(config.get_default("default_api_host"))
now_time = datetime.now()
hour_ago = now_time + timedelta(hours=-1)

if begin_time is None:
begin_time=datetime.strftime(hour_ago, '%Y%m%d%H%M%S')
if end_time is None:
end_time=datetime.strftime(now_time, '%Y%m%d%H%M%S')
if g is None:
g="hour"
params = {
"bucket": bucket_name,
"begin": begin_time,
"end": end_time,
"g": g
}
return self.__get(url, params=params)

def bucket_filecount(self, bucket_name, begin_time=None, end_time=None, g=None):
"""
获取bucket的存储空间文件数量.可查询当天计量,统计延迟大概 5 分钟。
Args:
bucket_name: 存储空间名
begin_time: 起始日期字符串,闭区间,例如: 20060102150405
end_time: 结束日期字符串,开区间,例如: 20060102150405
g: 时间粒度,支持 day;当天支持5min、hour、day
"""
url = "{0}/v6/count".format(config.get_default("default_api_host"))

now_time = datetime.now()
hour_ago = now_time + timedelta(hours=-1)

if begin_time is None:
begin_time=datetime.strftime(hour_ago, '%Y%m%d%H%M%S')
if end_time is None:
end_time=datetime.strftime(now_time, '%Y%m%d%H%M%S')
if g is None:
g="hour"

params = {
"bucket": bucket_name,
"begin": begin_time,
"end": end_time,
"g": g
}

return self.__get(url, params=params)

def change_bucket_permission(self, bucket_name, private):
"""
设置 存储空间访问权限
Expand Down