8000 Bump to v7.16.0 by lihsai0 · Pull Request #457 · qiniu/python-sdk · GitHub
[go: up one dir, main page]

Skip to content

Bump to v7.16.0 #457

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

Merged
merged 12 commits into from
Mar 25, 2025
Next Next commit
DP-5290 python-sdk/cdn: 查询域名带宽,支持type参数
- cdn/manager: add DataType class(enum), add optional parameter 'data_type' to
`CdnManager.get_bandwidth_data` & `CdnManager.get_flux_data`
- see https://jira.qiniu.io/browse/DP-5290
  • Loading branch information
yuansl committed Dec 9, 2024
commit f3a0b9b49518d414c5f4444dc17c2d94467bf5f7
8 changes: 7 additions & 1 deletion examples/cdn_bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
查询指定域名指定时间段内的带宽
"""
import qiniu
from qiniu import CdnManager
from qiniu import CdnManager, DataType


# 账户ak,sk
Expand All @@ -31,3 +31,9 @@

print(ret)
print(info)

ret, info = cdn_manager.get_bandwidth_data(
urls, startDate, endDate, granularity, data_type=DataType.BANDWIDTH)

print(ret)
print(info)
2 changes: 1 addition & 1 deletion qiniu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
build_batch_stat, build_batch_delete, build_batch_restoreAr, build_batch_restore_ar
from .services.storage.uploader import put_data, put_file, put_stream
from .services.storage.upload_progress_recorder import UploadProgressRecorder
from .services.cdn.manager import CdnManager, create_timestamp_anti_leech_url, DomainManager
from .services.cdn.manager import CdnManager, DataType, create_timestamp_anti_leech_url, DomainManager
from .services.processing.pfop import PersistentFop
from .services.processing.cmd import build_op, pipe_cmd, op_save
from .services.compute.app import AccountClient
Expand Down
20 changes: 17 additions & 3 deletions qiniu/services/cdn/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@

from qiniu.compat import is_py2
from qiniu.compat import is_py3
from enum import Enum

import hashlib

class DataType(Enum):
BANDWIDTH = 'bandwidth'
X302BANDWIDTH = '302bandwidth'
X302MBANDWIDTH = '302mbandwidth'
FLOW = 'flow'
X302FLOW = '302flow'
X302MFLOW = '302mflow'

def urlencode(str):
if is_py2:
Expand Down Expand Up @@ -60,7 +68,7 @@ def refresh_urls_and_dirs(self, urls, dirs):
Returns:
一个dict变量和一个ResponseInfo对象
参考代码 examples/cdn_manager.py
"""
"""
req = {}
if urls is not None and len(urls) > 0:
req.update({"urls": urls})
Expand Down Expand Up @@ -89,7 +97,7 @@ def prefetch_urls(self, urls):
url = '{0}/v2/tune/prefetch'.format(self.server)
return self.__post(url, body)

def get_bandwidth_data(self, domains, start_date, end_date, granularity):
def get_bandwidth_data(self, domains, start_date, end_date, granularity, data_type=None):
"""
查询带宽数据,文档 https://developer.qiniu.com/fusion/api/traffic-bandwidth

Expand All @@ -98,6 +106,7 @@ def get_bandwidth_data(self, domains, start_date, end_date, granularity):
start_date: 起始日期
end_date: 结束日期
granularity: 数据间隔
data_type: 计量数据类型, see class DataType.XXXBANDWIDTH

Returns:
一个dict变量和一个ResponseInfo对象
Expand All @@ -108,12 +117,14 @@ def get_bandwidth_data(self, domains, start_date, end_date, granularity):
req.update({"startDate": start_date})
req.update({"endDate": end_date})
req.update({"granularity": granularity})
if data_type is not None:
req.update({'type': data_type.value}) # should be one of 'bandwidth', '302bandwidth', '302mbandwidth'

body = json.dumps(req)
url = '{0}/v2/tune/bandwidth'.format(self.server)
return self.__post(url, body)

def get_flux_data(self, domains, start_date, end_date, granularity):
def get_flux_data(self, domains, start_date, end_date, granularity, data_type=None):
"""
查询流量数据,文档 https://developer.qiniu.com/fusion/api/traffic-bandwidth

Expand All @@ -122,6 +133,7 @@ def get_flux_data(self, domains, start_date, end_date, granularity):
start_date: 起始日期
end_date: 结束日期
granularity: 数据间隔
data_type: 计量数据类型, see class DataType.XXXFLOW

Returns:
一个dict变量和一个ResponseInfo对象
Expand All @@ -132,6 +144,8 @@ def get_flux_data(self, domains, start_date, end_date, granularity):
req.update({"startDate": start_date})
req.update({"endDate": end_date})
req.update({"granularity": granularity})
if data_type is not None:
req.update({'type': data_type.value}) # should be one of 'flow', '302flow', '302mflow'

body = json.dumps(req)
url = '{0}/v2/tune/flux'.format(self.server)
Expand Down
0