bce-python-sdk 0.9.7__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 CHANGED
@@ -18,7 +18,7 @@ from builtins import bytes
18
18
  from . import protocol
19
19
 
20
20
 
21
- SDK_VERSION = b'0.9.07'
21
+ SDK_VERSION = b'0.9.09'
22
22
  DEFAULT_SERVICE_DOMAIN = b'bcebos.com'
23
23
  URL_PREFIX = b'/v1'
24
24
  DEFAULT_ENCODING = 'UTF-8'
@@ -4388,6 +4388,52 @@ class BccClient(bce_base_client.BceBaseClient):
4388
4388
  }
4389
4389
  return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
4390
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
+
4391
4437
  @required(instance_type=str, cpu_count=int, memory_cap_in_gb=int) # ***Unicode***
4392
4438
  def get_bid_instance_price(self, instance_type, cpu_count, memory_cap_in_gb,
4393
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
@@ -0,0 +1,82 @@
1
+ # Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
2
+ # Copyright 2010 United States Government as represented by the
3
+ # Administrator of the National Aeronautics and Space Administration.
4
+ # Copyright 2011 Piston Cloud Computing, Inc.
5
+ # All Rights Reserved.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
8
+ # not use this file except in compliance with the License. You may obtain
9
+ # a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
+ # License for the specific language governing permissions and limitations
17
+ # under the License.
18
+ """
19
+ This module provides models for ESG-SDK.
20
+ """
21
+
22
+ class TagModel(object):
23
+ """
24
+ TAGModel
25
+ """
26
+
27
+ def __init__(self, tagKey=None, tagValue=None):
28
+ self.tagKey = tagKey
29
+ self.tagValue = tagValue
30
+
31
+
32
+ class EnterpriseSecurityGroupRuleModel(object):
33
+ """
34
+ This class define the rule of the securitygroup.
35
+ param: remark:
36
+ The remark for the rule.
37
+ param: direction:
38
+ The parameter to define the rule direction,available value are "ingress/egress".
39
+ param: ethertype:
40
+ The ethernet protocol.
41
+ param: portRange:
42
+ The port range to specify the port which the rule will work on.
43
+ Available range is rang [0, 65535], the fault value is "" for all port.
44
+ param: sourceportRange:
45
+ The source port range to specify the port which the rule will work on.
46
+ Available range is rang [0, 65535], the fault value is "" for all port.
47
+ param: protocol:
48
+ The parameter specify which protocol will the rule work on, the fault value is "" for all protocol.
49
+ Available protocol are tcp, udp and icmp.
50
+ param: sourceIp:
51
+ The source ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
52
+ other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
53
+ Only works for direction = "ingress".
54
+ param: destIp:
55
+ The destination ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
56
+ other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
57
+ Only works for direction = "egress".
58
+ param: EnterprisesecurityGroupId:
59
+ The id of the Enterprisesecuritygroup for the rule.
60
+ param: localIp:
61
+ The parameter specify the localIP (allow all ip address: all).
62
+ param: priority:
63
+ The parameter specify the priority of the rule(range 1-1000).
64
+ param: action:
65
+ The parameter specify the action of the rule, available value are "allow/deny".
66
+ """
67
+
68
+ def __init__(self, remark=None, direction=None, ethertype=None, portRange=None, sourcePortRange=None,
69
+ protocol=None, sourceIp=None, destIp=None,
70
+ enterpriseSecurityGroupId=None, action=None, localIp=None, priority=None):
71
+ self.remark = remark
72
+ self.direction = direction
73
+ self.ethertype = ethertype
74
+ self.portRange = portRange
75
+ self.sourcePortRange = sourcePortRange
76
+ self.protocol = protocol
77
+ self.sourceIp = sourceIp
78
+ self.destIp = destIp
79
+ self.enterpriseSecurityGroupId = enterpriseSecurityGroupId
80
+ self.action = action
81
+ self.localIp = localIp
82
+ self.priority = priority
File without changes