bce-python-sdk 0.9.6__py3-none-any.whl → 0.9.9__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 +1 -1
- baidubce/services/bbc/bbc_client.py +42 -0
- baidubce/services/bbc/bbc_model.py +14 -3
- baidubce/services/bcc/bcc_client.py +143 -1
- baidubce/services/bcm/bcm_client.py +76 -0
- baidubce/services/esg/__init__.py +0 -0
- baidubce/services/esg/esg_client.py +307 -0
- baidubce/services/esg/esg_model.py +82 -0
- baidubce/services/etGateway/__init__.py +0 -0
- baidubce/services/etGateway/et_gateway_client.py +466 -0
- baidubce/services/probe/__init__.py +0 -0
- baidubce/services/probe/probe_client.py +335 -0
- {bce_python_sdk-0.9.6.dist-info → bce_python_sdk-0.9.9.dist-info}/METADATA +1 -1
- {bce_python_sdk-0.9.6.dist-info → bce_python_sdk-0.9.9.dist-info}/RECORD +16 -9
- {bce_python_sdk-0.9.6.dist-info → bce_python_sdk-0.9.9.dist-info}/WHEEL +0 -0
- {bce_python_sdk-0.9.6.dist-info → bce_python_sdk-0.9.9.dist-info}/top_level.txt +0 -0
baidubce/__init__.py
CHANGED
|
@@ -41,6 +41,7 @@ class BbcClient(bce_base_client.BceBaseClient):
|
|
|
41
41
|
Bbc client sdk
|
|
42
42
|
"""
|
|
43
43
|
|
|
44
|
+
prefix_v2 = b'/v2'
|
|
44
45
|
def __init__(self, config=None):
|
|
45
46
|
bce_base_client.BceBaseClient.__init__(self, config)
|
|
46
47
|
|
|
@@ -685,6 +686,47 @@ class BbcClient(bce_base_client.BceBaseClient):
|
|
|
685
686
|
return self._send_request(http_methods.PUT, path, body=json.dumps(body),
|
|
686
687
|
params=params, config=config)
|
|
687
688
|
|
|
689
|
+
@required(reserved_instance_ids=list,
|
|
690
|
+
tags=list)
|
|
691
|
+
def bind_reserved_instance_to_tags(self, reserved_instance_ids, tags, config=None):
|
|
692
|
+
"""
|
|
693
|
+
:param reserved_instance_ids:
|
|
694
|
+
:param tags:
|
|
695
|
+
:param config:
|
|
696
|
+
:return:
|
|
697
|
+
"""
|
|
698
|
+
path = b'/bbc/reserved/tag'
|
|
699
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
700
|
+
body = {
|
|
701
|
+
'changeTags': tag_list,
|
|
702
|
+
'reservedInstanceIds': reserved_instance_ids
|
|
703
|
+
}
|
|
704
|
+
params = {
|
|
705
|
+
'bind': None
|
|
706
|
+
}
|
|
707
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body),
|
|
708
|
+
params=params, config=config, api_version=self.prefix_v2)
|
|
709
|
+
|
|
710
|
+
@required(reserved_instance_ids=list,
|
|
711
|
+
tags=list)
|
|
712
|
+
def unbind_reserved_instance_from_tags(self, reserved_instance_ids, tags, config=None):
|
|
713
|
+
"""
|
|
714
|
+
:param reserved_instance_ids:
|
|
715
|
+
:param tags:
|
|
716
|
+
:param config:
|
|
717
|
+
:return:
|
|
718
|
+
"""
|
|
719
|
+
path = b'/bbc/reserved/tag'
|
|
720
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
721
|
+
body = {
|
|
722
|
+
'changeTags': tag_list,
|
|
723
|
+
'reservedInstanceIds': reserved_instance_ids
|
|
724
|
+
}
|
|
725
|
+
params = {
|
|
726
|
+
'unbind': None
|
|
727
|
+
}
|
|
728
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body),
|
|
729
|
+
params=params, config=config, api_version=self.prefix_v2)
|
|
688
730
|
|
|
689
731
|
def list_flavors(self, config=None):
|
|
690
732
|
"""
|
|
@@ -32,10 +32,21 @@ class Billing(object):
|
|
|
32
32
|
param: reservationTimeUnit:
|
|
33
33
|
The time unit to specify the duration ,only "Month" can be used now.
|
|
34
34
|
"""
|
|
35
|
+
|
|
35
36
|
def __init__(self, paymentTiming=None, reservationLength=1, reservationTimeUnit='Month'):
|
|
36
37
|
if paymentTiming:
|
|
37
38
|
self.paymentTiming = paymentTiming
|
|
38
39
|
self.reservation = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
'reservationLength': reservationLength,
|
|
41
|
+
'reservationTimeUnit': reservationTimeUnit
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TagModel(object):
|
|
46
|
+
"""
|
|
47
|
+
TAGModel
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, tagKey=None, tagValue=None):
|
|
51
|
+
self.tagKey = tagKey
|
|
52
|
+
self.tagValue = tagValue
|
|
@@ -50,6 +50,7 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
50
50
|
"""
|
|
51
51
|
|
|
52
52
|
prefix = b'/v2'
|
|
53
|
+
prefix_v3 = b'/v3'
|
|
53
54
|
|
|
54
55
|
def __init__(self, config=None):
|
|
55
56
|
bce_base_client.BceBaseClient.__init__(self, config)
|
|
@@ -1065,7 +1066,7 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
1065
1066
|
def list_instances(self, marker=None, max_keys=None, internal_ip=None, dedicated_host_id=None,
|
|
1066
1067
|
zone_name=None, instance_ids=None, instance_names=None, cds_ids=None,
|
|
1067
1068
|
deployset_ids=None, security_group_ids=None, payment_timing=None, status=None, tags=None,
|
|
1068
|
-
vpc_id=None, private_ips=None, auto_renew=None, config=None):
|
|
1069
|
+
vpc_id=None, private_ips=None, ipv6_addresses=None, auto_renew=None, config=None):
|
|
1069
1070
|
"""
|
|
1070
1071
|
Return a list of instances owned by the authenticated user.
|
|
1071
1072
|
|
|
@@ -1135,6 +1136,11 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
1135
1136
|
vpc_id
|
|
1136
1137
|
:type private_ips: string
|
|
1137
1138
|
|
|
1139
|
+
:param ipv6_addresses:
|
|
1140
|
+
filter instance list with multiple ipv6 private ips join by ',', the parameter should be used with
|
|
1141
|
+
vpc_id
|
|
1142
|
+
:type ipv6_addresses: string
|
|
1143
|
+
|
|
1138
1144
|
:param auto_renew:
|
|
1139
1145
|
:type auto_renew: boolean
|
|
1140
1146
|
|
|
@@ -1174,6 +1180,8 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
1174
1180
|
params['vpcId'] = vpc_id
|
|
1175
1181
|
if private_ips is not None:
|
|
1176
1182
|
params['privateIps'] = private_ips
|
|
1183
|
+
if ipv6_addresses is not None:
|
|
1184
|
+
params['ipv6Addresses'] = ipv6_addresses
|
|
1177
1185
|
if auto_renew is not None:
|
|
1178
1186
|
params['autoRenew'] = auto_renew
|
|
1179
1187
|
return self._send_request(http_methods.GET, path, params=params, config=config)
|
|
@@ -1640,6 +1648,94 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
1640
1648
|
return self._send_request(http_methods.PUT, path, json.dumps(body),
|
|
1641
1649
|
params=params, config=config)
|
|
1642
1650
|
|
|
1651
|
+
@required(reserved_instance_ids=list,
|
|
1652
|
+
tags=list)
|
|
1653
|
+
def bind_reserved_instance_to_tags(self, reserved_instance_ids, tags, config=None):
|
|
1654
|
+
"""
|
|
1655
|
+
:param reserved_instance_ids:
|
|
1656
|
+
:param tags:
|
|
1657
|
+
:param config:
|
|
1658
|
+
:return:
|
|
1659
|
+
"""
|
|
1660
|
+
path = b'/bcc/reserved/tag'
|
|
1661
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
1662
|
+
body = {
|
|
1663
|
+
'changeTags': tag_list,
|
|
1664
|
+
'reservedInstanceIds': reserved_instance_ids
|
|
1665
|
+
}
|
|
1666
|
+
params = {
|
|
1667
|
+
'bind': None
|
|
1668
|
+
}
|
|
1669
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body),
|
|
1670
|
+
params=params, config=config)
|
|
1671
|
+
|
|
1672
|
+
@required(reserved_instance_ids=list,
|
|
1673
|
+
tags=list)
|
|
1674
|
+
def unbind_reserved_instance_from_tags(self, reserved_instance_ids, tags, config=None):
|
|
1675
|
+
"""
|
|
1676
|
+
:param reserved_instance_ids:
|
|
1677
|
+
:param tags:
|
|
1678
|
+
:param config:
|
|
1679
|
+
:return:
|
|
1680
|
+
"""
|
|
1681
|
+
path = b'/bcc/reserved/tag'
|
|
1682
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
1683
|
+
body = {
|
|
1684
|
+
'changeTags': tag_list,
|
|
1685
|
+
'reservedInstanceIds': reserved_instance_ids
|
|
1686
|
+
}
|
|
1687
|
+
params = {
|
|
1688
|
+
'unbind': None
|
|
1689
|
+
}
|
|
1690
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body),
|
|
1691
|
+
params=params, config=config)
|
|
1692
|
+
|
|
1693
|
+
def bind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
|
|
1694
|
+
"""
|
|
1695
|
+
:param resource_type:
|
|
1696
|
+
:param resource_ids:
|
|
1697
|
+
:param tags:
|
|
1698
|
+
:param is_relation_tag:
|
|
1699
|
+
:param config:
|
|
1700
|
+
:return:
|
|
1701
|
+
"""
|
|
1702
|
+
path = b'/bcc/tag'
|
|
1703
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
1704
|
+
body = {
|
|
1705
|
+
'resourceType': resource_type,
|
|
1706
|
+
'resourceIds': resource_ids,
|
|
1707
|
+
'tags': tag_list,
|
|
1708
|
+
'isRelationTag': is_relation_tag
|
|
1709
|
+
}
|
|
1710
|
+
params = {
|
|
1711
|
+
'action': 'AttachTags'
|
|
1712
|
+
}
|
|
1713
|
+
return self._send_request(http_methods.POST, path, json.dumps(body),
|
|
1714
|
+
params=params, config=config, prefix=self.prefix_v3)
|
|
1715
|
+
|
|
1716
|
+
def unbind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
|
|
1717
|
+
"""
|
|
1718
|
+
:param resource_type:
|
|
1719
|
+
:param resource_ids:
|
|
1720
|
+
:param tags:
|
|
1721
|
+
:param is_relation_tag:
|
|
1722
|
+
:param config:
|
|
1723
|
+
:return:
|
|
1724
|
+
"""
|
|
1725
|
+
path = b'/bcc/tag'
|
|
1726
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
1727
|
+
body = {
|
|
1728
|
+
'resourceType': resource_type,
|
|
1729
|
+
'resourceIds': resource_ids,
|
|
1730
|
+
'tags': tag_list,
|
|
1731
|
+
'isRelationTag': is_relation_tag
|
|
1732
|
+
}
|
|
1733
|
+
params = {
|
|
1734
|
+
'action': 'DetachTags'
|
|
1735
|
+
}
|
|
1736
|
+
return self._send_request(http_methods.POST, path, json.dumps(body),
|
|
1737
|
+
params=params, config=config, prefix=self.prefix_v3)
|
|
1738
|
+
|
|
1643
1739
|
@required(instance_id=(bytes, str),
|
|
1644
1740
|
tags=list)
|
|
1645
1741
|
def bind_instance_to_tags(self, instance_id, tags, config=None):
|
|
@@ -4292,6 +4388,52 @@ class BccClient(bce_base_client.BceBaseClient):
|
|
|
4292
4388
|
}
|
|
4293
4389
|
return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
|
|
4294
4390
|
|
|
4391
|
+
@required(instance_ids=(list))
|
|
4392
|
+
def batch_refund_resources(self, instance_ids, related_release_flag=None,
|
|
4393
|
+
delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
|
|
4394
|
+
client_token=None, config=None):
|
|
4395
|
+
"""
|
|
4396
|
+
Releasing the instance owned by the user.
|
|
4397
|
+
Only the Prepaid instance and the instance has not expired can be released.
|
|
4398
|
+
After releasing the instance, all of the data will be deleted.
|
|
4399
|
+
|
|
4400
|
+
:param instance_ids:
|
|
4401
|
+
The id list of instances.
|
|
4402
|
+
:type instance_ids: list of string
|
|
4403
|
+
|
|
4404
|
+
|
|
4405
|
+
:param related_release_flag:
|
|
4406
|
+
Release or not related resources.
|
|
4407
|
+
:type related_release_flag: bool
|
|
4408
|
+
|
|
4409
|
+
:param delete_cds_snapshot_flag:
|
|
4410
|
+
Delete or not cds snapshot.
|
|
4411
|
+
:type delete_cds_snapshot_flag: bool
|
|
4412
|
+
|
|
4413
|
+
:param delete_related_enis_flag:
|
|
4414
|
+
Delete or not related enis.
|
|
4415
|
+
:type delete_related_enis_flag: bool
|
|
4416
|
+
|
|
4417
|
+
:return:
|
|
4418
|
+
:rtype baidubce.bce_response.BceResponse
|
|
4419
|
+
"""
|
|
4420
|
+
params = {}
|
|
4421
|
+
if client_token is None:
|
|
4422
|
+
params['clientToken'] = generate_client_token()
|
|
4423
|
+
else:
|
|
4424
|
+
params['clientToken'] = client_token
|
|
4425
|
+
path = b'/instance/batchRefundResource'
|
|
4426
|
+
body = {
|
|
4427
|
+
"instanceIds": instance_ids
|
|
4428
|
+
}
|
|
4429
|
+
if related_release_flag is not None:
|
|
4430
|
+
body['relatedReleaseFlag'] = related_release_flag
|
|
4431
|
+
if delete_cds_snapshot_flag is not None:
|
|
4432
|
+
body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
|
|
4433
|
+
if delete_related_enis_flag is not None:
|
|
4434
|
+
body['deleteRelatedEnisFlag'] = delete_related_enis_flag
|
|
4435
|
+
return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
|
|
4436
|
+
|
|
4295
4437
|
@required(instance_type=str, cpu_count=int, memory_cap_in_gb=int) # ***Unicode***
|
|
4296
4438
|
def get_bid_instance_price(self, instance_type, cpu_count, memory_cap_in_gb,
|
|
4297
4439
|
root_disk_size_in_gb=None, root_disk_storage_type=None, create_cds_list=None,
|
|
@@ -5872,3 +5872,79 @@ class BcmClient(bce_base_client.BceBaseClient):
|
|
|
5872
5872
|
return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
|
|
5873
5873
|
|
|
5874
5874
|
|
|
5875
|
+
def get_metric_dimension_top(self, user_id, scope, region, dimensions, metric_name, statistics, labels,
|
|
5876
|
+
start_time, end_time, order="top", topNum=10):
|
|
5877
|
+
|
|
5878
|
+
"""
|
|
5879
|
+
:param user_id: user_id
|
|
5880
|
+
:type string
|
|
5881
|
+
|
|
5882
|
+
:param scope: scope
|
|
5883
|
+
:type string
|
|
5884
|
+
|
|
5885
|
+
:param region: region
|
|
5886
|
+
:type string
|
|
5887
|
+
|
|
5888
|
+
:param dimensions: dimensions
|
|
5889
|
+
:type map
|
|
5890
|
+
|
|
5891
|
+
:param metric_name: metric_name
|
|
5892
|
+
:type string
|
|
5893
|
+
|
|
5894
|
+
:param statistics: statistics
|
|
5895
|
+
:type string
|
|
5896
|
+
|
|
5897
|
+
:param labels: labels
|
|
5898
|
+
:type set
|
|
5899
|
+
|
|
5900
|
+
:param start_time: start_time
|
|
5901
|
+
:type string
|
|
5902
|
+
|
|
5903
|
+
:param end_time: end_time
|
|
5904
|
+
:type string
|
|
5905
|
+
|
|
5906
|
+
:param order: order default top
|
|
5907
|
+
:type string
|
|
5908
|
+
|
|
5909
|
+
:param topNum: topNum default 10
|
|
5910
|
+
:type int
|
|
5911
|
+
|
|
5912
|
+
:return:
|
|
5913
|
+
"""
|
|
5914
|
+
if len(user_id) <= 0:
|
|
5915
|
+
raise ValueError("user_id should not be null")
|
|
5916
|
+
if len(scope) <= 0:
|
|
5917
|
+
raise ValueError("scope should not be null")
|
|
5918
|
+
if len(region) <= 0:
|
|
5919
|
+
raise ValueError("region should not be null")
|
|
5920
|
+
if len(metric_name) <= 0:
|
|
5921
|
+
raise ValueError("metric_name should not be null")
|
|
5922
|
+
if len(dimensions) <= 0:
|
|
5923
|
+
raise ValueError("dimensions should not be null")
|
|
5924
|
+
if len(labels) <= 0:
|
|
5925
|
+
raise ValueError("lables should not be null")
|
|
5926
|
+
if len(statistics) <= 0:
|
|
5927
|
+
raise ValueError("statistics should not be null")
|
|
5928
|
+
if len(start_time) <= 0:
|
|
5929
|
+
raise ValueError("start_time should not be null")
|
|
5930
|
+
if len(end_time) <= 0:
|
|
5931
|
+
raise ValueError("end_time should not be null")
|
|
5932
|
+
|
|
5933
|
+
body = {
|
|
5934
|
+
"userId": user_id,
|
|
5935
|
+
"scope": scope,
|
|
5936
|
+
"region": region,
|
|
5937
|
+
"startTime": start_time,
|
|
5938
|
+
"endTime": end_time,
|
|
5939
|
+
"metricName": metric_name,
|
|
5940
|
+
"dimensions": dimensions,
|
|
5941
|
+
"statistics": statistics,
|
|
5942
|
+
"labels": labels,
|
|
5943
|
+
"order": order,
|
|
5944
|
+
"topNum": topNum,
|
|
5945
|
+
}
|
|
5946
|
+
|
|
5947
|
+
path = b'/dimensions/top'
|
|
5948
|
+
return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
|
|
5949
|
+
|
|
5950
|
+
|
|
File without changes
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
4
|
+
# except in compliance with the License. You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the
|
|
9
|
+
# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
10
|
+
# either express or implied. See the License for the specific language governing permissions
|
|
11
|
+
# and limitations under the License.
|
|
12
|
+
|
|
13
|
+
"""
|
|
14
|
+
This module provides a client class for esg.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import unicode_literals
|
|
17
|
+
|
|
18
|
+
import copy
|
|
19
|
+
import json
|
|
20
|
+
import uuid
|
|
21
|
+
|
|
22
|
+
from baidubce import bce_base_client
|
|
23
|
+
from baidubce import compat
|
|
24
|
+
from baidubce.auth import bce_v1_signer
|
|
25
|
+
from baidubce.http import bce_http_client
|
|
26
|
+
from baidubce.http import handler
|
|
27
|
+
from baidubce.http import http_methods
|
|
28
|
+
from baidubce.services.esg import esg_model
|
|
29
|
+
from baidubce.utils import required
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class EsgClient(bce_base_client.BceBaseClient):
|
|
33
|
+
"""
|
|
34
|
+
Bcc base sdk client
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
prefix = b'/v1'
|
|
38
|
+
|
|
39
|
+
def __init__(self, config=None):
|
|
40
|
+
bce_base_client.BceBaseClient.__init__(self, config)
|
|
41
|
+
|
|
42
|
+
def _merge_config(self, config=None):
|
|
43
|
+
if config is None:
|
|
44
|
+
return self.config
|
|
45
|
+
else:
|
|
46
|
+
new_config = copy.copy(self.config)
|
|
47
|
+
new_config.merge_non_none_values(config)
|
|
48
|
+
return new_config
|
|
49
|
+
|
|
50
|
+
def _send_request(self, http_method, path,
|
|
51
|
+
body=None, headers=None, params=None,
|
|
52
|
+
config=None, body_parser=None, prefix=None):
|
|
53
|
+
config = self._merge_config(config)
|
|
54
|
+
if body_parser is None:
|
|
55
|
+
body_parser = handler.parse_json
|
|
56
|
+
if prefix is None:
|
|
57
|
+
prefix = EsgClient.prefix
|
|
58
|
+
|
|
59
|
+
return bce_http_client.send_request(
|
|
60
|
+
config, bce_v1_signer.sign, [handler.parse_error, body_parser],
|
|
61
|
+
http_method, prefix + path, body, headers, params)
|
|
62
|
+
|
|
63
|
+
@required(name=(bytes, str), # ***Unicode***
|
|
64
|
+
rules=list)
|
|
65
|
+
def create_enterprise_security_group(self, name, rules=None,
|
|
66
|
+
desc=None,
|
|
67
|
+
tags=None,
|
|
68
|
+
client_token=None,
|
|
69
|
+
config=None):
|
|
70
|
+
"""
|
|
71
|
+
Creating a newly esg with specified rules.
|
|
72
|
+
|
|
73
|
+
:param name:
|
|
74
|
+
The name of esg that will be created.
|
|
75
|
+
:type name: string
|
|
76
|
+
|
|
77
|
+
:param rules:
|
|
78
|
+
The list of rules which define how the esg works.
|
|
79
|
+
:type rules: list<esg_model.EnterpriseSecurityGroupRuleModel>
|
|
80
|
+
|
|
81
|
+
:param desc:
|
|
82
|
+
The optional parameter to describe the esg that will be created.
|
|
83
|
+
:type desc: string
|
|
84
|
+
|
|
85
|
+
:param tags:
|
|
86
|
+
The optional list of tag to be bonded.
|
|
87
|
+
:type tags: list<esg_model.TagModel>
|
|
88
|
+
|
|
89
|
+
:param client_token:
|
|
90
|
+
An ASCII string whose length is less than 64.
|
|
91
|
+
The request will be idempotent if client token is provided.
|
|
92
|
+
If the clientToken is not specified by the user,
|
|
93
|
+
a random String generated by default algorithm will be used.
|
|
94
|
+
:type client_token: string
|
|
95
|
+
|
|
96
|
+
:param config:
|
|
97
|
+
:type config: baidubce.BceClientConfiguration
|
|
98
|
+
|
|
99
|
+
:return:
|
|
100
|
+
:rtype baidubce.bce_response.BceResponse
|
|
101
|
+
"""
|
|
102
|
+
path = b'/enterprise/security'
|
|
103
|
+
params = {
|
|
104
|
+
'clientToken': generate_client_token() if client_token is None else client_token
|
|
105
|
+
}
|
|
106
|
+
rule_list = [rule.__dict__ for rule in rules]
|
|
107
|
+
body = {
|
|
108
|
+
'name': name,
|
|
109
|
+
'desc': desc,
|
|
110
|
+
'rules': rule_list
|
|
111
|
+
}
|
|
112
|
+
if desc is not None:
|
|
113
|
+
body['desc'] = desc
|
|
114
|
+
if tags is not None:
|
|
115
|
+
tag_list = [tag.__dict__ for tag in tags]
|
|
116
|
+
body['tags'] = tag_list
|
|
117
|
+
return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
|
|
118
|
+
|
|
119
|
+
def list_enterprise_security_groups(self, instance_id=None, marker=None, max_keys=None, config=None):
|
|
120
|
+
"""
|
|
121
|
+
Listing EnterpriseSecurityGroup owned by the authenticated user.
|
|
122
|
+
|
|
123
|
+
:param instance_id:
|
|
124
|
+
The id of instance. The optional parameter to list the SecurityGroup.
|
|
125
|
+
If it's specified,only the SecurityGroup related to the specified instance will be listed
|
|
126
|
+
:type instance_id: string
|
|
127
|
+
|
|
128
|
+
:param marker:
|
|
129
|
+
The optional parameter marker specified in the original request to specify
|
|
130
|
+
where in the results to begin listing.
|
|
131
|
+
Together with the marker, specifies the list result which listing should begin.
|
|
132
|
+
If the marker is not specified, the list result will listing from the first one.
|
|
133
|
+
:type marker: string
|
|
134
|
+
|
|
135
|
+
:param max_keys:
|
|
136
|
+
The optional parameter to specifies the max number of list result to return.
|
|
137
|
+
The default value is 1000.
|
|
138
|
+
:type max_keys: int
|
|
139
|
+
|
|
140
|
+
:param config:
|
|
141
|
+
:type config: baidubce.BceClientConfiguration
|
|
142
|
+
|
|
143
|
+
:return:
|
|
144
|
+
:rtype baidubce.bce_response.BceResponse
|
|
145
|
+
"""
|
|
146
|
+
path = b'/enterprise/security'
|
|
147
|
+
params = {}
|
|
148
|
+
if instance_id is not None:
|
|
149
|
+
params['instanceId'] = instance_id
|
|
150
|
+
if marker is not None:
|
|
151
|
+
params['marker'] = marker
|
|
152
|
+
if max_keys is not None:
|
|
153
|
+
params['maxKeys'] = max_keys
|
|
154
|
+
|
|
155
|
+
return self._send_request(http_methods.GET, path, params=params, config=config)
|
|
156
|
+
|
|
157
|
+
@required(enterprise_security_group_id=(bytes, str)) # ***Unicode***
|
|
158
|
+
def delete_enterprise_security_group(self, enterprise_security_group_id, config=None):
|
|
159
|
+
"""
|
|
160
|
+
Deleting the specified EnterpriseSecurityGroup.
|
|
161
|
+
|
|
162
|
+
:param enterprise_security_group_id:
|
|
163
|
+
The id of SecurityGroup that will be deleted.
|
|
164
|
+
:type enterprise_security_group_id: string
|
|
165
|
+
|
|
166
|
+
:param config:
|
|
167
|
+
:type config: baidubce.BceClientConfiguration
|
|
168
|
+
:return:
|
|
169
|
+
:rtype baidubce.bce_response.BceResponse
|
|
170
|
+
"""
|
|
171
|
+
enterprise_security_group_id = compat.convert_to_bytes(enterprise_security_group_id)
|
|
172
|
+
path = b'/enterprise/security/%s' % enterprise_security_group_id
|
|
173
|
+
return self._send_request(http_methods.DELETE, path, config=config)
|
|
174
|
+
|
|
175
|
+
@required(enterprise_security_group_id=(bytes, str), # ***Unicode***
|
|
176
|
+
rule=esg_model.EnterpriseSecurityGroupRuleModel)
|
|
177
|
+
def authorize_enterprise_security_group_rule(self, enterprise_security_group_id, rules,
|
|
178
|
+
client_token=None,
|
|
179
|
+
config=None):
|
|
180
|
+
"""
|
|
181
|
+
authorize a security group rule to the specified security group
|
|
182
|
+
|
|
183
|
+
:param enterprise_security_group_id:
|
|
184
|
+
The id of EnterpriseSecurityGroup that will be authorized.
|
|
185
|
+
:type enterprise_security_group_id: string
|
|
186
|
+
|
|
187
|
+
:param rules:
|
|
188
|
+
The list of rules which define how the esg works.
|
|
189
|
+
:type rules: list<esg_model.EnterpriseSecurityGroupRuleModel>
|
|
190
|
+
|
|
191
|
+
:param client_token:
|
|
192
|
+
An ASCII string whose length is less than 64.
|
|
193
|
+
The request will be idempotent if client token is provided.
|
|
194
|
+
If the clientToken is not specified by the user,
|
|
195
|
+
a random String generated by default algorithm will be used.
|
|
196
|
+
:type client_token: string
|
|
197
|
+
|
|
198
|
+
:param config:
|
|
199
|
+
:type config: baidubce.BceClientConfiguration
|
|
200
|
+
|
|
201
|
+
:return:
|
|
202
|
+
:rtype baidubce.bce_response.BceResponse
|
|
203
|
+
"""
|
|
204
|
+
enterprise_security_group_id = compat.convert_to_bytes(enterprise_security_group_id)
|
|
205
|
+
path = b'/enterprise/security/%s' % enterprise_security_group_id
|
|
206
|
+
params = {'authorizeRule': ''}
|
|
207
|
+
if client_token is None:
|
|
208
|
+
params['clientToken'] = generate_client_token()
|
|
209
|
+
else:
|
|
210
|
+
params['clientToken'] = client_token
|
|
211
|
+
rule_list = [rule.__dict__ for rule in rules]
|
|
212
|
+
body = {
|
|
213
|
+
'rules': rule_list
|
|
214
|
+
}
|
|
215
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
|
|
216
|
+
|
|
217
|
+
@required(enterprise_security_group_rule_id=(bytes, str)) # ***Unicode***
|
|
218
|
+
def update_enterprise_security_group_rule(self, enterprise_security_group_rule_id,
|
|
219
|
+
remark=None,
|
|
220
|
+
protocol=None,
|
|
221
|
+
portrange=None,
|
|
222
|
+
source_ip=None,
|
|
223
|
+
dest_ip=None,
|
|
224
|
+
action=None,
|
|
225
|
+
local_ip=None,
|
|
226
|
+
priority=None,
|
|
227
|
+
source_portrange=None,
|
|
228
|
+
config=None):
|
|
229
|
+
"""
|
|
230
|
+
uodate a enterprise security group rule from the specified security group
|
|
231
|
+
:param enterprise_security_group_rule_id:
|
|
232
|
+
The id of EnterpriseSecurityGroupRule that will be updated.
|
|
233
|
+
:param: remark:
|
|
234
|
+
The remark for the rule.
|
|
235
|
+
:param: portrange:
|
|
236
|
+
The port range to specify the port which the rule will work on.
|
|
237
|
+
Available range is rang [0, 65535], the fault value is "" for all port.
|
|
238
|
+
:param: source_portrange:
|
|
239
|
+
The source port range to specify the port which the rule will work on.
|
|
240
|
+
Available range is rang [0, 65535], the fault value is "" for all port.
|
|
241
|
+
:param: protocol:
|
|
242
|
+
The parameter specify which protocol will the rule work on, the fault value is "" for all protocol.
|
|
243
|
+
Available protocol are tcp, udp and icmp.
|
|
244
|
+
:param: source_ip:
|
|
245
|
+
The source ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
|
|
246
|
+
other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
|
|
247
|
+
Only works for direction = "ingress".
|
|
248
|
+
:param: dest_ip:
|
|
249
|
+
The destination ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
|
|
250
|
+
other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
|
|
251
|
+
Only works for direction = "egress".
|
|
252
|
+
:param: local_ip:
|
|
253
|
+
The parameter specify the localIP (allow all ip address: all).
|
|
254
|
+
:param: priority:
|
|
255
|
+
The parameter specify the priority of the rule(range 1-1000).
|
|
256
|
+
:param: action:
|
|
257
|
+
The parameter specify the action of the rule, available value are "allow/deny".
|
|
258
|
+
:param config:
|
|
259
|
+
:type config: baidubce.BceClientConfiguration
|
|
260
|
+
:return:
|
|
261
|
+
:rtype baidubce.bce_response.BceResponse
|
|
262
|
+
"""
|
|
263
|
+
enterprise_security_group_rule_id = compat.convert_to_bytes(enterprise_security_group_rule_id)
|
|
264
|
+
path = b'/enterprise/security/rule/%s' % enterprise_security_group_rule_id
|
|
265
|
+
body = {
|
|
266
|
+
'enterpriseSecurityGroupRuleId': enterprise_security_group_rule_id,
|
|
267
|
+
'remark': remark,
|
|
268
|
+
'protocol': protocol,
|
|
269
|
+
'portRange': portrange,
|
|
270
|
+
'sourceIp': source_ip,
|
|
271
|
+
'destIp': dest_ip,
|
|
272
|
+
'action': action,
|
|
273
|
+
'localIp': local_ip,
|
|
274
|
+
'priority': priority,
|
|
275
|
+
'sourcePortRange': source_portrange
|
|
276
|
+
}
|
|
277
|
+
return self._send_request(http_methods.PUT, path, json.dumps(body), params=None, config=config)
|
|
278
|
+
|
|
279
|
+
@required(enterprise_security_group_rule_id=(bytes, str)) # ***Unicode***
|
|
280
|
+
def delete_enterprise_security_group_rule(self, enterprise_security_group_rule_id, config=None):
|
|
281
|
+
"""
|
|
282
|
+
delete a enterprise security group rule from the specified security group
|
|
283
|
+
:param enterprise_security_group_rule_id:
|
|
284
|
+
The id of EnterpriseSecurityGroupRule that will be deleted.
|
|
285
|
+
:type enterprise_security_group_id: string
|
|
286
|
+
|
|
287
|
+
:param config:
|
|
288
|
+
:type config: baidubce.BceClientConfiguration
|
|
289
|
+
:return:
|
|
290
|
+
:rtype baidubce.bce_response.BceResponse
|
|
291
|
+
"""
|
|
292
|
+
enterprise_security_group_rule_id = compat.convert_to_bytes(enterprise_security_group_rule_id)
|
|
293
|
+
path = b'/enterprise/security/rule/%s' % enterprise_security_group_rule_id
|
|
294
|
+
return self._send_request(http_methods.DELETE, path, params=None, config=config)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def generate_client_token_by_uuid():
|
|
298
|
+
"""
|
|
299
|
+
The default method to generate the random string for client_token
|
|
300
|
+
if the optional parameter client_token is not specified by the user.
|
|
301
|
+
:return:
|
|
302
|
+
:rtype string
|
|
303
|
+
"""
|
|
304
|
+
return str(uuid.uuid4())
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
generate_client_token = generate_client_token_by_uuid
|