Skip to content

Commit 61b110d

Browse files
committed
add put/get bucket intelligenttiering
1 parent 974e4a8 commit 61b110d

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

qcloud_cos/cos_client.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,76 @@ def get_bucket_referer(self, Bucket, **kwargs):
27972797
format_dict(data['DomainList'], ['Domain'])
27982798
return data
27992799

2800+
def put_bucket_intelligenttiering(self, Bucket, IntelligentTieringConfiguration={}, **kwargs):
2801+
"""设置存储桶智能分层配置
2802+
2803+
:param Bucket(string): 存储桶名称.
2804+
:param IntelligentTieringConfiguration(dict): 只能分层配置
2805+
:param kwargs(dict): 设置请求headers.
2806+
:return: None.
2807+
2808+
.. code-block:: python
2809+
2810+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2811+
client = CosS3Client(config)
2812+
2813+
intelligent_tiering_conf = {
2814+
'Status': 'Enable',
2815+
'Transition': {
2816+
'Days': '30|60|90',
2817+
'RequestFrequent': '1'
2818+
}
2819+
}
2820+
client.put_bucket_intelligenttiering(Bucket="bucket", IntelligentTieringConfiguration=intelligent_tiering_conf)
2821+
"""
2822+
2823+
xml_config = format_xml(data=IntelligentTieringConfiguration, root='IntelligentTieringConfiguration')
2824+
headers = mapped(kwargs)
2825+
headers['Content-Type'] = 'application/xml'
2826+
params = {'intelligenttiering': ''}
2827+
url = self._conf.uri(bucket=Bucket)
2828+
logger.info("put bucket intelligenttiering, url=:{url} ,headers=:{headers}".format(
2829+
url=url,
2830+
headers=headers))
2831+
rt = self.send_request(
2832+
method='PUT',
2833+
url=url,
2834+
bucket=Bucket,
2835+
data=xml_config,
2836+
auth=CosS3Auth(self._conf, params=params),
2837+
headers=headers,
2838+
params=params)
2839+
return None
2840+
2841+
def get_bucket_intelligenttiering(self, Bucket, **kwargs):
2842+
"""获取存储桶智能分层配置
2843+
:param Bucket(string): 存储桶名称.
2844+
:param IntelligentTieringConfiguration(dict): 只能分层配置
2845+
:param kwargs(dict): 设置请求headers.
2846+
:return(dict): 智能分层配置.
2847+
2848+
.. code-block:: python
2849+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
2850+
client = CosS3Client(config)
2851+
client.get_bucket_intelligenttiering(Bucket='bucket')
2852+
"""
2853+
2854+
headers = mapped(kwargs)
2855+
params = {'intelligenttiering': ''}
2856+
url = self._conf.uri(bucket=Bucket)
2857+
logger.info("get bucket intelligenttiering, url=:{url} ,headers=:{headers}".format(
2858+
url=url,
2859+
headers=headers))
2860+
rt = self.send_request(
2861+
method='GET',
2862+
url=url,
2863+
bucket=Bucket,
2864+
auth=CosS3Auth(self._conf, params=params),
2865+
headers=headers,
2866+
params=params)
2867+
data = xml_to_dict(rt.content)
2868+
return data
2869+
28002870
# service interface begin
28012871
def list_buckets(self, **kwargs):
28022872
"""列出所有bucket

ut/test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,24 @@ def test_download_file():
12411241
if os.path.exists(file_name):
12421242
os.remove(file_name)
12431243

1244+
def test_put_get_bucket_intelligenttiering():
1245+
"""测试设置获取智能分层"""
1246+
intelligent_tiering_conf = {
1247+
'Status': 'Enable',
1248+
'Transition': {
1249+
'Days': '30',
1250+
'RequestFrequent': '1'
1251+
}
1252+
}
1253+
response = client.put_bucket_intelligenttiering(
1254+
Bucket=test_bucket,
1255+
IntelligentTieringConfiguration=intelligent_tiering_conf
1256+
)
1257+
time.sleep(2)
1258+
response = client.get_bucket_intelligenttiering(
1259+
Bucket=test_bucket,
1260+
)
1261+
12441262
if __name__ == "__main__":
12451263
setUp()
12461264
"""
@@ -1268,6 +1286,7 @@ def test_download_file():
12681286
test_select_object()
12691287
_test_get_object_sensitive_content_recognition()
12701288
test_download_file()
1289+
test_put_get_bucket_intelligenttiering()
12711290
"""
12721291

12731292
tearDown()

0 commit comments

Comments
 (0)