bce-python-sdk 0.9.56__py3-none-any.whl → 0.9.59__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
baidubce/__init__.py CHANGED
@@ -18,7 +18,7 @@ from builtins import bytes
18
18
  from . import protocol
19
19
 
20
20
 
21
- SDK_VERSION = b'0.9.56'
21
+ SDK_VERSION = b'0.9.59'
22
22
  DEFAULT_SERVICE_DOMAIN = b'bcebos.com'
23
23
  URL_PREFIX = b'/v1'
24
24
  DEFAULT_ENCODING = 'UTF-8'
@@ -237,9 +237,18 @@ def send_request(
237
237
  if http_method == b'GET' and 300 <= http_response.status < 400:
238
238
  headers_map = {k: v for k, v in headers_list}
239
239
  if 'location' in headers_map:
240
+ try:
241
+ http_response.read()
242
+ except Exception:
243
+ _logger.info("ignore read response body error")
244
+ try:
245
+ http_response.close()
246
+ except Exception:
247
+ _logger.info("ignore close response connection error")
240
248
  location = headers_map.get('location')
241
249
  _logger.debug('request auto follow redirect location is %s', location)
242
250
  parsed_url = urlparse(location)
251
+ redirect_conn = None
243
252
  if protocol.name == baidubce.protocol.HTTP.name:
244
253
  redirect_conn = http.client.HTTPConnection(parsed_url.netloc,
245
254
  timeout=config.connection_timeout_in_mills / 1000)
@@ -248,8 +257,10 @@ def send_request(
248
257
  timeout=config.connection_timeout_in_mills / 1000)
249
258
  else:
250
259
  raise ValueError('Invalid protocol: %s, either HTTP or HTTPS is expected.' % protocol)
251
- redirect_conn.request("GET", parsed_url.path + "?" + parsed_url.query,
260
+ redirect_conn.putrequest("GET", parsed_url.path + "?" + parsed_url.query,
252
261
  skip_host=True, skip_accept_encoding=True)
262
+ redirect_conn.putheader("Host", parsed_url.netloc)
263
+ redirect_conn.endheaders()
253
264
  http_response = redirect_conn.getresponse()
254
265
  for handler_function in response_handler_functions:
255
266
  if handler_function(http_response, response):
@@ -118,6 +118,16 @@ BOS_PROCESS = b"x-bce-process"
118
118
 
119
119
  BOS_BASE_ALLOW_HEADERS = set([BOS_TRAFFIC_LIMIT, BOS_VERSIONING, BOS_TAGGING, BOS_PROCESS, BOS_OBJECT_EXPIRES])
120
120
 
121
+ BOS_IF_MATCH = b"If-Match"
122
+
123
+ BOS_IF_NONE_MATCH = b"If-None-Match"
124
+
125
+ BOS_IF_MODIFIED_SINCE = b"If-Modified-Since"
126
+
127
+ BOS_IF_UNMODIFIED_SINCE = b"If-Unmodified-Since"
128
+
129
+ BOS_COND_READ_WRITE_HEADERS = set([BOS_IF_UNMODIFIED_SINCE, BOS_IF_MATCH, BOS_IF_NONE_MATCH])
130
+
121
131
  # BOS HTTP Headers END
122
132
 
123
133
  # STS HTTP Headers
@@ -1516,7 +1516,9 @@ class BccClient(bce_base_client.BceBaseClient):
1516
1516
  @required(instance_id=(bytes, str), # ***Unicode***
1517
1517
  image_id=(bytes, str)) # ***Unicode***
1518
1518
  def rebuild_instance(self, instance_id, image_id, admin_pass=None, key_pair_id=None, is_keep_image_login=None,
1519
- config=None):
1519
+ config=None, user_data=None, clean_last_user_data=None, is_open_hostEye=None,
1520
+ sys_root_size=None, is_preserve_data=None, raid_id=None, data_partition_type=None,
1521
+ root_partition_type=None):
1520
1522
  """
1521
1523
  Rebuilding the instance owned by the user.
1522
1524
  After rebuilding the instance,
@@ -1545,6 +1547,40 @@ class BccClient(bce_base_client.BceBaseClient):
1545
1547
  key_pair_id or admin_pass is required for rebuild instance.
1546
1548
  :type key_pair_id: string
1547
1549
 
1550
+ :param user_data:
1551
+ User data to pass to the instance at launch time.
1552
+ :type user_data: string
1553
+
1554
+ :param clean_last_user_data:
1555
+ Indicates whether to clean the user data after the instance has been rebuilded.
1556
+ Default value is False.
1557
+ :type clean_user_data: boolean
1558
+
1559
+ :param is_open_hostEye:
1560
+ Indicates whether to open host eye.
1561
+ :type is_open_hostEye: boolean
1562
+
1563
+ :param sys_root_size:
1564
+ System partition size (unit: GB).
1565
+ :type sys_root_size: int
1566
+
1567
+ :param is_preserve_data:
1568
+ Indicates whether to preserve data during the instance rebuilding process.
1569
+ Default value is False.
1570
+ :type is_preserve_data: boolean
1571
+
1572
+ :param raid_id:
1573
+ RAID ID.
1574
+ :type raid_id: string
1575
+
1576
+ :param data_partition_type:
1577
+ Data partition type.
1578
+ :type data_partition_type: string
1579
+
1580
+ :param root_partition_type:
1581
+ Root partition type.
1582
+ :type root_partition_type: string
1583
+
1548
1584
  :return:
1549
1585
  :rtype baidubce.bce_response.BceResponse
1550
1586
  """
@@ -1561,6 +1597,22 @@ class BccClient(bce_base_client.BceBaseClient):
1561
1597
  secret_access_key = self.config.credentials.secret_access_key
1562
1598
  cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
1563
1599
  body['adminPass'] = cipher_admin_pass
1600
+ if user_data is not None:
1601
+ body['userData'] = user_data
1602
+ if clean_last_user_data is not None:
1603
+ body['cleanLastUserData'] = clean_last_user_data
1604
+ if is_open_hostEye is not None:
1605
+ body['isOpenHostEye'] = is_open_hostEye
1606
+ if sys_root_size is not None:
1607
+ body['sysRootSize'] = sys_root_size
1608
+ if is_preserve_data is not None:
1609
+ body['isPreserveData'] = is_preserve_data
1610
+ if raid_id is not None:
1611
+ body['raidId'] = raid_id
1612
+ if data_partition_type is not None:
1613
+ body['dataPartitionType'] = data_partition_type
1614
+ if root_partition_type is not None:
1615
+ body['rootPartitionType'] = root_partition_type
1564
1616
  params = {
1565
1617
  'rebuild': None
1566
1618
  }
@@ -2602,12 +2654,17 @@ class BccClient(bce_base_client.BceBaseClient):
2602
2654
  def modify_volume_charge_type(self,
2603
2655
  volume_id,
2604
2656
  billing=None,
2657
+ effective_type=None,
2605
2658
  config=None):
2606
2659
  """
2607
2660
  :param volume_id: volume id
2608
2661
  :type volume_id: string
2609
2662
  :param billing: payment information
2610
2663
  :type billing: bcc_model.Billing
2664
+ :param effective_type: Optional parameters:
2665
+ AtOnce (switch to pay-as-you-go immediately),
2666
+ AfterExpiration (switch to pay-as-you-go after expiration).
2667
+ Defaults to AfterExpiration if not provided.
2611
2668
  :param config:
2612
2669
 
2613
2670
  :return:
@@ -2619,6 +2676,7 @@ class BccClient(bce_base_client.BceBaseClient):
2619
2676
  if billing is None:
2620
2677
  billing = default_billing_to_purchase_reserved
2621
2678
  body = {
2679
+ 'effectiveType': effective_type,
2622
2680
  'billing': billing.__dict__
2623
2681
  }
2624
2682
 
@@ -3999,7 +4057,8 @@ class BccClient(bce_base_client.BceBaseClient):
3999
4057
  user_data=None, spec_id=None, deletion_protection=None, is_open_hosteye=None,
4000
4058
  hosteye_type=None, res_group_id=None, enable_ht=None, data_partition_type=None,
4001
4059
  root_partition_type=None, file_systems=None, disable_root_disk_serial=None,
4002
- internal_ips=None, network_purchase_type=None, is_keep_image_login=None):
4060
+ internal_ips=None, network_purchase_type=None, is_keep_image_login=None,
4061
+ reserved_instance=None):
4003
4062
  """
4004
4063
  Create a bcc Instance with the specified options.
4005
4064
  You must fill the field of clientToken,which is especially for keeping idempotent.
@@ -4385,7 +4444,8 @@ class BccClient(bce_base_client.BceBaseClient):
4385
4444
  body['networkPurchaseType'] = network_purchase_type
4386
4445
  if is_keep_image_login is not None:
4387
4446
  body['keepImageLogin'] = is_keep_image_login
4388
-
4447
+ if reserved_instance is not None:
4448
+ body['reservedInstance'] = reserved_instance
4389
4449
  return self._send_request(http_methods.POST, path, json.dumps(body),
4390
4450
  params=params, config=config)
4391
4451
 
@@ -4432,7 +4492,8 @@ class BccClient(bce_base_client.BceBaseClient):
4432
4492
  @required(instance_id=(bytes, str)) # ***Unicode***
4433
4493
  def release_instance_with_related_resources(self, instance_id, related_release_flag=None,
4434
4494
  delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
4435
- bcc_recycle_flag=None, client_token=None, config=None):
4495
+ bcc_recycle_flag=None, cds_attribute_active=None,
4496
+ client_token=None, config=None):
4436
4497
  """
4437
4498
  Releasing the instance owned by the user.
4438
4499
  Only the Postpaid instance or Prepaid which is expired can be released.
@@ -4481,6 +4542,8 @@ class BccClient(bce_base_client.BceBaseClient):
4481
4542
  body['deleteRelatedEnisFlag'] = delete_related_enis_flag
4482
4543
  if bcc_recycle_flag is not None:
4483
4544
  body['bccRecycleFlag'] = bcc_recycle_flag
4545
+ if bcc_recycle_flag is not None:
4546
+ body['cdsAttributeActive'] = cds_attribute_active
4484
4547
  return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
4485
4548
 
4486
4549
  @required(instance_id=(bytes, str)) # ***Unicode***
@@ -5608,7 +5671,9 @@ class BccClient(bce_base_client.BceBaseClient):
5608
5671
  return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
5609
5672
 
5610
5673
  def batch_rebuild_instances(self, image_id, admin_pass, instance_ids, keypair_id=None, is_keep_image_login=None,
5611
- client_token=None, config=None):
5674
+ client_token=None, config=None, user_data=None, use_last_user_data=None,
5675
+ is_open_hostEye=None, sys_root_size=None, is_preserve_data=None, raid_id=None,
5676
+ data_partition_type=None, root_partition_type=None):
5612
5677
  """
5613
5678
  Batch rebuild instances.
5614
5679
 
@@ -5628,6 +5693,30 @@ class BccClient(bce_base_client.BceBaseClient):
5628
5693
  Set the id of the keypair to be bound. (optional param)
5629
5694
  :type keypair_id: string
5630
5695
 
5696
+ :param user_data:
5697
+ UserData of the instance.
5698
+
5699
+ :param use_last_user_data:
5700
+ Use last user data.
5701
+
5702
+ :param is_open_hostEye:
5703
+ Is open host eye.
5704
+
5705
+ :param sys_root_size:
5706
+ System disk size.
5707
+
5708
+ :param is_preserve_data:
5709
+ Preserve data.
5710
+
5711
+ :param raid_id:
5712
+ Raid id.
5713
+
5714
+ :param data_partition_type:
5715
+ Data partition type.
5716
+
5717
+ :param root_partition_type:
5718
+ Root partition type.
5719
+
5631
5720
  :return:
5632
5721
  :rtype baidubce.bce_response.BceResponse
5633
5722
  """
@@ -5649,6 +5738,22 @@ class BccClient(bce_base_client.BceBaseClient):
5649
5738
  body['keypairId'] = keypair_id
5650
5739
  if is_keep_image_login is not None:
5651
5740
  body['keepImageLogin'] = is_keep_image_login
5741
+ if user_data is not None:
5742
+ body['userData'] = user_data
5743
+ if use_last_user_data is not None:
5744
+ body['useLastUserData'] = use_last_user_data
5745
+ if is_open_hostEye is not None:
5746
+ body['isOpenHostEye'] = is_open_hostEye
5747
+ if sys_root_size is not None:
5748
+ body['sysRootSize'] = sys_root_size
5749
+ if is_preserve_data is not None:
5750
+ body['isPreserveData'] = is_preserve_data
5751
+ if raid_id is not None:
5752
+ body['raidId'] = raid_id
5753
+ if data_partition_type is not None:
5754
+ body['dataPartitionType'] = data_partition_type
5755
+ if root_partition_type is not None:
5756
+ body['rootPartitionType'] = root_partition_type
5652
5757
  return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
5653
5758
 
5654
5759
  def change_to_prepaid(self, instance_id, duration, relation_cds, auto_renew, auto_renew_period=None,
@@ -5929,7 +6034,8 @@ class BccClient(bce_base_client.BceBaseClient):
5929
6034
 
5930
6035
  def batch_delete_instance_with_related_resource(self, instance_ids, related_release_flag=None,
5931
6036
  delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
5932
- bcc_recycle_flag=None, client_token=None, config=None):
6037
+ bcc_recycle_flag=None, cds_attribute_active=None,
6038
+ client_token=None, config=None):
5933
6039
  """
5934
6040
  batch delete instance with related resource
5935
6041
 
@@ -5974,6 +6080,8 @@ class BccClient(bce_base_client.BceBaseClient):
5974
6080
  body['deleteRelatedEnisFlag'] = delete_related_enis_flag
5975
6081
  if bcc_recycle_flag is not None:
5976
6082
  body['bccRecycleFlag'] = bcc_recycle_flag
6083
+ if bcc_recycle_flag is not None:
6084
+ body['cdsAttributeActive'] = cds_attribute_active
5977
6085
  return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
5978
6086
 
5979
6087
  def batch_start_instance(self, instance_ids, client_token=None, config=None):
@@ -70,11 +70,12 @@ class CreateCdsModel(object):
70
70
  param: encryptKey
71
71
  """
72
72
 
73
- def __init__(self, cdsSizeInGB=None, storageType='hp1', snapshotId=None, encryptKey=None):
73
+ def __init__(self, cdsSizeInGB=None, storageType='hp1', snapshotId=None, encryptKey=None, deleteWithInstance=None):
74
74
  self.cdsSizeInGB = cdsSizeInGB
75
75
  self.storageType = storageType
76
76
  self.snapshotId = snapshotId
77
77
  self.encryptKey = encryptKey
78
+ self.deleteWithInstance = deleteWithInstance
78
79
 
79
80
 
80
81
  class SecurityGroupRuleModel(object):
@@ -64,7 +64,7 @@ class UploadTaskHandle:
64
64
  handle to control multi upload file with multi-thread
65
65
  """
66
66
  def __init__(self):
67
- self.cancel_flag= False
67
+ self.cancel_flag = False
68
68
  self.cancel_lock = threading.Lock()
69
69
 
70
70
  def cancel(self):
@@ -956,12 +956,16 @@ class BosClient(BceBaseClient):
956
956
  return True
957
957
 
958
958
  @required(bucket_name=(bytes, str), key=(bytes, str))
959
- def get_object(self, bucket_name, key, range=None, traffic_limit=None, version_id=None, config=None):
959
+ def get_object(self, bucket_name, key, range=None, traffic_limit=None, version_id=None,
960
+ cond_read_write=None, config=None):
960
961
  """
961
962
 
962
963
  :param bucket_name:
963
964
  :param key:
964
965
  :param range:
966
+ :param traffic_limit:
967
+ :param version_id:
968
+ :param cond_read_write:
965
969
  :param config:
966
970
  :return:
967
971
  """
@@ -973,10 +977,17 @@ class BosClient(BceBaseClient):
973
977
  if len(key) == 0 or key.startswith(b"/"):
974
978
  raise BceClientError("Key can not be empty or start with '/' .")
975
979
  range_header = BosClient._get_range_header_dict(range)
980
+
976
981
  if traffic_limit is not None:
977
982
  if range_header is None:
978
983
  range_header = {}
979
984
  range_header[http_headers.BOS_TRAFFIC_LIMIT] = traffic_limit
985
+
986
+ if cond_read_write is not None:
987
+ if range_header is None:
988
+ range_header = {}
989
+ range_header = self._get_cond_read_write_headers(http_methods.GET, range_header, cond_read_write)
990
+
980
991
  return self._send_request(
981
992
  http_methods.GET,
982
993
  bucket_name,
@@ -985,7 +996,8 @@ class BosClient(BceBaseClient):
985
996
  params=query_params,
986
997
  config=config,
987
998
  body_parser=BosClient._parse_bos_object)
988
- # restore object
999
+
1000
+ # restore object
989
1001
  @required(bucket_name=(bytes, str), key=(bytes, str))
990
1002
  def restore_object(self, bucket_name, key, days=None, tier="Standard", config=None):
991
1003
  """
@@ -1035,7 +1047,7 @@ class BosClient(BceBaseClient):
1035
1047
  return True
1036
1048
 
1037
1049
  @required(bucket_name=(bytes, str), key=(bytes, str))
1038
- def get_object_as_string(self, bucket_name, key, range=None, version_id=None, config=None):
1050
+ def get_object_as_string(self, bucket_name, key, range=None, version_id=None, cond_read_write=None, config=None):
1039
1051
  """
1040
1052
 
1041
1053
  :param bucket_name:
@@ -1045,14 +1057,15 @@ class BosClient(BceBaseClient):
1045
1057
  :return:
1046
1058
  """
1047
1059
  key = compat.convert_to_bytes(key)
1048
- response = self.get_object(bucket_name, key, range=range, version_id = version_id, config=config)
1060
+ response = self.get_object(bucket_name, key, range=range, version_id = version_id,
1061
+ cond_read_write = cond_read_write, config=config)
1049
1062
  s = response.data.read()
1050
1063
  response.data.close()
1051
1064
  return s
1052
1065
 
1053
1066
  @required(bucket_name=(bytes, str), key=(bytes, str), file_name=(bytes, str))
1054
1067
  def get_object_to_file(self, bucket_name, key, file_name, range=None, config=None,
1055
- progress_callback=None, traffic_limit=None, version_id=None):
1068
+ progress_callback=None, traffic_limit=None, cond_read_write=None, version_id=None):
1056
1069
  """
1057
1070
  Get Content of Object and Put Content to File
1058
1071
 
@@ -1084,6 +1097,11 @@ class BosClient(BceBaseClient):
1084
1097
  range_header = {}
1085
1098
  range_header[http_headers.BOS_TRAFFIC_LIMIT] = traffic_limit
1086
1099
 
1100
+ if cond_read_write is not None:
1101
+ if range_header is None:
1102
+ range_header = {}
1103
+ range_header = self._get_cond_read_write_headers(http_methods.GET, range_header, cond_read_write)
1104
+
1087
1105
  return self._send_request(
1088
1106
  http_methods.GET,
1089
1107
  bucket_name,
@@ -1100,7 +1118,7 @@ class BosClient(BceBaseClient):
1100
1118
 
1101
1119
 
1102
1120
  @required(bucket_name=(bytes, str), key=(bytes, str))
1103
- def get_object_meta_data(self, bucket_name, key, version_id=None, config=None):
1121
+ def get_object_meta_data(self, bucket_name, key, version_id=None, cond_read_write=None, config=None):
1104
1122
  """
1105
1123
  Get head of object
1106
1124
 
@@ -1116,9 +1134,14 @@ class BosClient(BceBaseClient):
1116
1134
  if version_id is not None:
1117
1135
  version_id = compat.convert_to_bytes(version_id)
1118
1136
  query_params={b'versionId': version_id}
1137
+
1138
+ headers = {}
1139
+ if cond_read_write is not None:
1140
+ headers = self._get_cond_read_write_headers(http_methods.HEAD, headers, cond_read_write)
1141
+
1119
1142
  key = compat.convert_to_bytes(key)
1120
1143
  return self._send_request(http_methods.HEAD, bucket_name, key,
1121
- params=query_params, config=config)
1144
+ headers=headers, params=query_params, config=config)
1122
1145
 
1123
1146
  @required(bucket_name=(bytes, str),
1124
1147
  key=(bytes, str),
@@ -1251,6 +1274,7 @@ class BosClient(BceBaseClient):
1251
1274
  progress_callback=None,
1252
1275
  traffic_limit=None,
1253
1276
  object_tagging=None,
1277
+ cond_read_write=None,
1254
1278
  config=None):
1255
1279
  """
1256
1280
  Put object and put content of file to the object
@@ -1283,6 +1307,9 @@ class BosClient(BceBaseClient):
1283
1307
  traffic_limit=traffic_limit,
1284
1308
  object_tagging=object_tagging,)
1285
1309
 
1310
+ if cond_read_write is not None:
1311
+ headers = self._get_cond_read_write_headers(http_methods.PUT, headers, cond_read_write)
1312
+
1286
1313
  buf_size = self._get_config_parameter(config, 'recv_buf_size')
1287
1314
 
1288
1315
  if content_length > bos.MAX_PUT_OBJECT_LENGTH:
@@ -1314,6 +1341,7 @@ class BosClient(BceBaseClient):
1314
1341
  progress_callback=None,
1315
1342
  traffic_limit=None,
1316
1343
  object_tagging=None,
1344
+ cond_read_write=None,
1317
1345
  config=None):
1318
1346
  """
1319
1347
  Create object and put content of string to the object
@@ -1356,6 +1384,7 @@ class BosClient(BceBaseClient):
1356
1384
  progress_callback = progress_callback,
1357
1385
  traffic_limit=traffic_limit,
1358
1386
  object_tagging=object_tagging,
1387
+ cond_read_write=cond_read_write,
1359
1388
  config=config)
1360
1389
  finally:
1361
1390
  if fp is not None:
@@ -1376,6 +1405,7 @@ class BosClient(BceBaseClient):
1376
1405
  progress_callback=None,
1377
1406
  traffic_limit=None,
1378
1407
  object_tagging=None,
1408
+ cond_read_write=None,
1379
1409
  config=None,
1380
1410
  ):
1381
1411
 
@@ -1423,6 +1453,7 @@ class BosClient(BceBaseClient):
1423
1453
  progress_callback=progress_callback,
1424
1454
  traffic_limit=traffic_limit,
1425
1455
  object_tagging=object_tagging,
1456
+ cond_read_write=cond_read_write,
1426
1457
  config=config)
1427
1458
  finally:
1428
1459
  fp.close()
@@ -1805,8 +1836,9 @@ class BosClient(BceBaseClient):
1805
1836
  part_list=list)
1806
1837
  def complete_multipart_upload(self, bucket_name, key,
1807
1838
  upload_id, part_list,
1808
- user_metadata=None,
1809
1839
  user_headers=None,
1840
+ user_metadata=None,
1841
+ cond_read_write=None,
1810
1842
  config=None):
1811
1843
  """
1812
1844
  After finish all the task, complete multi_upload_file.
@@ -1832,6 +1864,9 @@ class BosClient(BceBaseClient):
1832
1864
  user_metadata=user_metadata,
1833
1865
  user_headers=user_headers)
1834
1866
 
1867
+ if cond_read_write is not None:
1868
+ headers = self._get_cond_read_write_headers(http_methods.POST, headers, cond_read_write)
1869
+
1835
1870
  return self._send_request(
1836
1871
  http_methods.POST,
1837
1872
  bucket_name,
@@ -2011,6 +2046,7 @@ class BosClient(BceBaseClient):
2011
2046
  user_headers=None,
2012
2047
  progress_callback=None,
2013
2048
  traffic_limit=None,
2049
+ cond_read_write=None,
2014
2050
  config=None):
2015
2051
  """
2016
2052
  Multipart Upload file to bos
@@ -2066,7 +2102,7 @@ class BosClient(BceBaseClient):
2066
2102
  # sort
2067
2103
  part_list.sort(key=lambda x: x["partNumber"])
2068
2104
  # complete_multipart_upload
2069
- self.complete_multipart_upload(bucket_name, key, upload_id, part_list)
2105
+ self.complete_multipart_upload(bucket_name, key, upload_id, part_list, cond_read_write)
2070
2106
  return True
2071
2107
 
2072
2108
  @required(bucket_name=(bytes, str), key=(bytes, str), acl=(list, dict))
@@ -2890,6 +2926,37 @@ class BosClient(BceBaseClient):
2890
2926
 
2891
2927
  if object_tagging is not None:
2892
2928
  headers[http_headers.BOS_TAGGING] = compat.convert_to_bytes(object_tagging)
2929
+
2930
+ return headers
2931
+
2932
+
2933
+ @staticmethod
2934
+ def _get_cond_read_write_headers(http_method, headers, cond_read_write):
2935
+ """
2936
+ get if condition headers
2937
+ :type http_method: string
2938
+ :param http_method: GET, HEAD, PUT, POST
2939
+
2940
+ :type cond_read_write: string
2941
+ :param cond_read_write: put_object, complete_multipart_upload, get_object, get_object_meta_data
2942
+
2943
+ :return: headers
2944
+ """
2945
+ cond_read_write_set = http_headers.BOS_COND_READ_WRITE_HEADERS
2946
+
2947
+ if http_method == http_methods.GET or http_method == http_methods.HEAD:
2948
+ cond_read_write_set = cond_read_write_set.union(set(
2949
+ [http_headers.BOS_IF_MODIFIED_SINCE,
2950
+ http_headers.BOS_IF_UNMODIFIED_SINCE,
2951
+ http_headers.BOS_IF_MATCH,
2952
+ http_headers.BOS_IF_NONE_MATCH]))
2953
+
2954
+ for k, v in iteritems(cond_read_write):
2955
+ k = utils.convert_to_standard_string(k)
2956
+ if k in cond_read_write_set:
2957
+ headers[k] = v
2958
+ else:
2959
+ raise ValueError('%s is not valid in %s' % (k, http_method))
2893
2960
  return headers
2894
2961
 
2895
2962
 
@@ -2995,6 +3062,19 @@ class BosClient(BceBaseClient):
2995
3062
 
2996
3063
  return config.endpoint
2997
3064
 
3065
+ @staticmethod
3066
+ def _need_retry_for_bos(config, error):
3067
+
3068
+ if not isinstance(error, BceServerError):
3069
+ return False
3070
+
3071
+ # if you need add more retry condition, please add it here
3072
+ if error.status_code == http.client.FORBIDDEN:
3073
+ _logger.debug('BOS retry condition matched: 403 Forbidden')
3074
+ return True
3075
+
3076
+ return False
3077
+
2998
3078
  @staticmethod
2999
3079
  def _need_retry_backup_endpoint(error):
3000
3080
  # always retry on IOError
@@ -3009,6 +3089,8 @@ class BosClient(BceBaseClient):
3009
3089
  return True
3010
3090
  if error.code == BceServerError.REQUEST_EXPIRED:
3011
3091
  return True
3092
+ if error.status_code == http.client.FORBIDDEN:
3093
+ return True
3012
3094
  return False
3013
3095
 
3014
3096
  def _send_request(
@@ -3026,23 +3108,42 @@ class BosClient(BceBaseClient):
3026
3108
  headers = headers or {}
3027
3109
  headers[http_headers.STS_SECURITY_TOKEN] = config.security_token
3028
3110
 
3111
+ last_exception = None
3112
+ e = None
3029
3113
  try:
3030
3114
  return bce_http_client.send_request(
3031
3115
  config, bce_v1_signer.sign, [handler.parse_error, body_parser],
3032
3116
  http_method, path, body, headers, params)
3033
- except BceHttpClientError as e:
3034
- # retry backup endpoint
3035
- if config.backup_endpoint is None:
3036
- raise e
3037
- if BosClient._need_retry_backup_endpoint(e.last_error):
3038
- _logger.debug(b'Retry for backup endpoint.')
3117
+ except BceHttpClientError as ex:
3118
+ last_exception = ex
3119
+ e = ex
3120
+
3121
+ # retry backup endpoint
3122
+ if e is not None and config.backup_endpoint is not None and BosClient._need_retry_backup_endpoint(e):
3123
+ try:
3124
+ _logger.debug(b'Retry for backup endpoint error code: %d.', e.status_code)
3039
3125
  path = BosClient._get_path(config, bucket_name, key, True)
3040
- return bce_http_client.send_request_no_underlined(
3126
+ return bce_http_client.send_request(
3041
3127
  config, bce_v1_signer.sign, [handler.parse_error, body_parser],
3042
3128
  http_method, path, body, headers, params, True)
3043
- else:
3044
- raise e
3129
+ except BceHttpClientError as ex:
3130
+ last_exception = ex
3131
+ e = ex
3132
+
3133
+ # retry for bos error
3134
+ if e is not None and BosClient._need_retry_for_bos(config, e.last_error):
3135
+ try:
3136
+ _logger.debug(b'Retry for BOS error code: %d.', e.status_code)
3137
+ return bce_http_client.send_request(
3138
+ config, bce_v1_signer.sign, [handler.parse_error, body_parser],
3139
+ http_method, path, body, headers, params)
3140
+ except BceHttpClientError as ex:
3141
+ last_exception = ex
3142
+ e = ex
3045
3143
 
3144
+ if last_exception is None:
3145
+ raise
3146
+ raise last_exception
3046
3147
 
3047
3148
  class SelectMessage(object):
3048
3149
  """
@@ -3137,7 +3238,7 @@ class SelectResponse(object):
3137
3238
  msg.set_end_message(headers_map, crc)
3138
3239
  self.finish = True
3139
3240
  yield msg
3140
- raise StopIteration
3241
+ return
3141
3242
  finally:
3142
3243
  self.http_response.close()
3143
3244
 
@@ -263,7 +263,6 @@ class EsgClient(bce_base_client.BceBaseClient):
263
263
  enterprise_security_group_rule_id = compat.convert_to_bytes(enterprise_security_group_rule_id)
264
264
  path = b'/enterprise/security/rule/%s' % enterprise_security_group_rule_id
265
265
  body = {
266
- 'enterpriseSecurityGroupRuleId': enterprise_security_group_rule_id,
267
266
  'remark': remark,
268
267
  'protocol': protocol,
269
268
  'portRange': portrange,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bce-python-sdk
3
- Version: 0.9.56
3
+ Version: 0.9.59
4
4
  Summary: BCE SDK for python
5
5
  Home-page: http://bce.baidu.com
6
6
  Author:
@@ -1,4 +1,4 @@
1
- baidubce/__init__.py,sha256=kixuhoe_lgi7nLAcTII5P-f4D7QkQq59WQ4cELdLVmw,813
1
+ baidubce/__init__.py,sha256=Wmf6zRPvFW3mCvc5ugWLBTT7TtY0e1HhvCK6EHJjJdg,813
2
2
  baidubce/bce_base_client.py,sha256=7gjkRy_YlTTb6TXHYHyZRYMjdVO7FTtHMdwXx8bPgsE,3428
3
3
  baidubce/bce_client_configuration.py,sha256=i9z5wVXaRSlJxE0LD1odexza35KQyFy7m1Az5XclD_I,3252
4
4
  baidubce/bce_response.py,sha256=gOj48U6iurYJsChzFdrB7Rj3RpkU-fUdhtftrIj9o8U,1985
@@ -11,10 +11,10 @@ baidubce/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  baidubce/auth/bce_credentials.py,sha256=thRajmOSShtI5z0VTGHj9FuZvWj65noolDQCanj_pzs,1157
12
12
  baidubce/auth/bce_v1_signer.py,sha256=7VX6XWrUg32mbNRHrIG7kJGanQ7kbsd7cXtOXTvTmIE,5017
13
13
  baidubce/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- baidubce/http/bce_http_client.py,sha256=Hs2F8N-U59Z8542NK-I-y5ue87QEb7GGe2CV6Re12RM,11470
14
+ baidubce/http/bce_http_client.py,sha256=HJuocNM3tpbaXSy80E5682jtLcMjtIxYhyhaQ-4NtXw,12044
15
15
  baidubce/http/handler.py,sha256=FGotEXyM24t93E2Z4n9dJV9XD34im-gdmq8JDyncZA8,2930
16
16
  baidubce/http/http_content_types.py,sha256=tHTGDR9nK5beD9HmJ4Iwj42fc9avsMpJELbb6UdKtkQ,722
17
- baidubce/http/http_headers.py,sha256=fHZUEbzvTW9-JUAhBXXeag4mj7NbvMnwnRkyrxiFBUA,2978
17
+ baidubce/http/http_headers.py,sha256=H3tZqErXpbDmYBm2Mzwe23TZcGpLGvrsLq3s_0NH4Bo,3235
18
18
  baidubce/http/http_methods.py,sha256=Hn-A2fKoZiqmrtWVlHhk1cGxEoGDrbLfNykZuo1zDZc,782
19
19
  baidubce/retry/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  baidubce/retry/retry_policy.py,sha256=A7cPvKxkVmd8PGA6_60sQU9hBzGbjXHVW0-QofP7-5E,4926
@@ -51,8 +51,8 @@ baidubce/services/bbc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
51
51
  baidubce/services/bbc/bbc_client.py,sha256=6x2fWmjyKSZ02WvsmQ1pryE0c_mtXHCjI0Ev80MfzbY,38951
52
52
  baidubce/services/bbc/bbc_model.py,sha256=Dy80LZ4ro_iS3UejJ_CL9kI7OyMSBoDitTE4J1XAC_g,1790
53
53
  baidubce/services/bcc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
- baidubce/services/bcc/bcc_client.py,sha256=cOC9ZC9sIjXyfmdBl7BAJGMPNjuVQjZak5x0uGybCv0,295590
55
- baidubce/services/bcc/bcc_model.py,sha256=iUDhNKMw0b_efjeIHEkvLMIph9MmVODOAdgmAzKL2ns,6710
54
+ baidubce/services/bcc/bcc_client.py,sha256=1XTHkkhgd59F6tEMNiniqTop0TytZiKW8lGsiTbdwlc,299976
55
+ baidubce/services/bcc/bcc_model.py,sha256=xKYC4Z-gxWjFhe8b1AmMBEN_wYhnwcqAmer29ysS17k,6788
56
56
  baidubce/services/bcc/fpga_card_type.py,sha256=n6goqnapIgAC9_sciA_2he5HFqPRbRv109qitO7qpd8,948
57
57
  baidubce/services/bcc/gpu_card_type.py,sha256=HEfMzne-UC5F295JPrPUu7V9F5g-hbXF2TNBontEFes,1054
58
58
  baidubce/services/bcm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -73,7 +73,7 @@ baidubce/services/bls/bls_model.py,sha256=A4kLRQo0aOlh2t4IFjd0aJbju-CmhZdryuXESu
73
73
  baidubce/services/bmr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  baidubce/services/bmr/bmr_client.py,sha256=ntJie-R6qFxdd6znpfCj25RSoJ6gOV0o2Tn9asJThQg,20565
75
75
  baidubce/services/bos/__init__.py,sha256=bRvJAiFjUIBF64HeoZ7bkTjGfqkKJAvxYWBSEvbUOIc,813
76
- baidubce/services/bos/bos_client.py,sha256=zGPec65M8oFCpHHIReWqcR4_iEx2RZuhaXYbg0hmlY8,110444
76
+ baidubce/services/bos/bos_client.py,sha256=jMyAVbrLZbhOhbpQK5fiUMZBNZ2qimWEaX_o8OgzDA8,114425
77
77
  baidubce/services/bos/bos_handler.py,sha256=ZWVjezraJsdNy0tsX8fZkWPmSBYLSlGolKqZ1CcWE7A,1832
78
78
  baidubce/services/bos/canned_acl.py,sha256=Y2qvU81OI_nT0uu96MyTemXyR2EnNVVYrJxfPS1rhBA,723
79
79
  baidubce/services/bos/common.py,sha256=X2_PDLRR3Lpr7i2mzzyMBI2jCQ779hIx3XwBDTQAXhE,138
@@ -122,7 +122,7 @@ baidubce/services/eni/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
122
122
  baidubce/services/eni/eni_client.py,sha256=6V7uKaJxO0oPXpOwPzJ2oR9J_6pP-PxfBMp5tB1tfpE,27573
123
123
  baidubce/services/eni/eni_model.py,sha256=YQzPCcUdf6AkAEkHwShC9lYC0uVRweC7_s5b6BVuySg,1165
124
124
  baidubce/services/esg/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
125
- baidubce/services/esg/esg_client.py,sha256=zzXu4g9Fk9Y5t4dgxKCYgR8oY_uyuOhhpOxcHQwr7Sg,13202
125
+ baidubce/services/esg/esg_client.py,sha256=3yZ2V98mc0QxTYRtmMxERl9NjmRilF8c3-feOfB3AGY,13122
126
126
  baidubce/services/esg/esg_model.py,sha256=TNf5J7ZdDBa4fKD40qA8mHewxXK6YvvPqYkZth4sEJw,3646
127
127
  baidubce/services/et/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  baidubce/services/et/et_client.py,sha256=skz620Hdk8c8mS1hkDbWAekvfWVytqkgb5AMeK0sDFw,34426
@@ -198,7 +198,7 @@ baidubce/services/vpc/vpc_client.py,sha256=Cdg009gZdI1gPgGy08-kIOxT3_VvuQoPqI_82
198
198
  baidubce/services/vpn/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
199
199
  baidubce/services/vpn/vpn_client.py,sha256=rrnQElD-LTttsqMbbIHoHK0Jdc7FrVVTZIdu-0Zthr8,31352
200
200
  baidubce/services/vpn/vpn_model.py,sha256=C9rEBYyFIDjrqvqJG4WEin6qVzEIvbhPvT5KwDYm1qA,3365
201
- bce_python_sdk-0.9.56.dist-info/METADATA,sha256=O-sRg16kAXYjNcbrqzGWDLFPifXYsBWdR5Szn0mBkRI,416
202
- bce_python_sdk-0.9.56.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
203
- bce_python_sdk-0.9.56.dist-info/top_level.txt,sha256=Oh6eo_-T_AuEDpIaR54biUUPThxsoQiYMVHLBTaweQs,9
204
- bce_python_sdk-0.9.56.dist-info/RECORD,,
201
+ bce_python_sdk-0.9.59.dist-info/METADATA,sha256=YLnTksp2a9qvV1bjePpdJi0X9Am4iqVn21gAeM0lZ_A,416
202
+ bce_python_sdk-0.9.59.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
203
+ bce_python_sdk-0.9.59.dist-info/top_level.txt,sha256=Oh6eo_-T_AuEDpIaR54biUUPThxsoQiYMVHLBTaweQs,9
204
+ bce_python_sdk-0.9.59.dist-info/RECORD,,