tccli 3.0.1208.1__py2.py3-none-any.whl → 3.0.1209.1__py2.py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. tccli/__init__.py +1 -1
  2. tccli/services/__init__.py +3 -0
  3. tccli/services/batch/v20170312/api.json +20 -2
  4. tccli/services/bma/v20221115/examples.json +1 -1
  5. tccli/services/ccc/v20200210/api.json +28 -1
  6. tccli/services/cls/cls_client.py +216 -4
  7. tccli/services/cls/v20201016/api.json +425 -0
  8. tccli/services/cls/v20201016/examples.json +32 -0
  9. tccli/services/cynosdb/v20190107/api.json +11 -0
  10. tccli/services/dc/dc_client.py +126 -73
  11. tccli/services/dc/v20180410/api.json +300 -0
  12. tccli/services/dc/v20180410/examples.json +8 -0
  13. tccli/services/emr/v20190103/api.json +1 -1
  14. tccli/services/ess/v20201111/api.json +2 -2
  15. tccli/services/ess/v20201111/examples.json +8 -8
  16. tccli/services/essbasic/v20210526/api.json +2 -2
  17. tccli/services/faceid/v20180301/api.json +10 -0
  18. tccli/services/gwlb/__init__.py +4 -0
  19. tccli/services/gwlb/gwlb_client.py +1096 -0
  20. tccli/services/gwlb/v20240906/api.json +1807 -0
  21. tccli/services/gwlb/v20240906/examples.json +155 -0
  22. tccli/services/oceanus/v20190422/api.json +4 -4
  23. tccli/services/privatedns/privatedns_client.py +57 -4
  24. tccli/services/privatedns/v20201028/api.json +101 -0
  25. tccli/services/privatedns/v20201028/examples.json +8 -0
  26. tccli/services/teo/v20220901/api.json +4 -4
  27. tccli/services/tke/v20180525/api.json +2 -2
  28. tccli/services/vclm/v20240523/api.json +9 -0
  29. tccli/services/vtc/v20240223/api.json +9 -0
  30. {tccli-3.0.1208.1.dist-info → tccli-3.0.1209.1.dist-info}/METADATA +2 -2
  31. {tccli-3.0.1208.1.dist-info → tccli-3.0.1209.1.dist-info}/RECORD +34 -30
  32. {tccli-3.0.1208.1.dist-info → tccli-3.0.1209.1.dist-info}/WHEEL +0 -0
  33. {tccli-3.0.1208.1.dist-info → tccli-3.0.1209.1.dist-info}/entry_points.txt +0 -0
  34. {tccli-3.0.1208.1.dist-info → tccli-3.0.1209.1.dist-info}/license_files/LICENSE +0 -0
@@ -0,0 +1,1096 @@
1
+ # -*- coding: utf-8 -*-
2
+ import os
3
+ import sys
4
+ import six
5
+ import json
6
+ import tccli.options_define as OptionsDefine
7
+ import tccli.format_output as FormatOutput
8
+ from tccli import __version__
9
+ from tccli.utils import Utils
10
+ from tccli.exceptions import ConfigurationError, ClientError, ParamError
11
+ from tencentcloud.common import credential
12
+ from tencentcloud.common.profile.http_profile import HttpProfile
13
+ from tencentcloud.common.profile.client_profile import ClientProfile
14
+ from tencentcloud.gwlb.v20240906 import gwlb_client as gwlb_client_v20240906
15
+ from tencentcloud.gwlb.v20240906 import models as models_v20240906
16
+
17
+ from jmespath import search
18
+ import time
19
+
20
+ def doDeleteTargetGroups(args, parsed_globals):
21
+ g_param = parse_global_arg(parsed_globals)
22
+
23
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
24
+ cred = credential.CVMRoleCredential()
25
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
26
+ cred = credential.STSAssumeRoleCredential(
27
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
28
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
29
+ )
30
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
31
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
32
+ else:
33
+ cred = credential.Credential(
34
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
35
+ )
36
+ http_profile = HttpProfile(
37
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
38
+ reqMethod="POST",
39
+ endpoint=g_param[OptionsDefine.Endpoint],
40
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
41
+ )
42
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
43
+ if g_param[OptionsDefine.Language]:
44
+ profile.language = g_param[OptionsDefine.Language]
45
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
46
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
47
+ client._sdkVersion += ("_CLI_" + __version__)
48
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
49
+ model = models.DeleteTargetGroupsRequest()
50
+ model.from_json_string(json.dumps(args))
51
+ start_time = time.time()
52
+ while True:
53
+ rsp = client.DeleteTargetGroups(model)
54
+ result = rsp.to_json_string()
55
+ try:
56
+ json_obj = json.loads(result)
57
+ except TypeError as e:
58
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
59
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
60
+ break
61
+ cur_time = time.time()
62
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
63
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
64
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
65
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
66
+ else:
67
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
68
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
69
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
70
+
71
+
72
+ def doDeleteGatewayLoadBalancer(args, parsed_globals):
73
+ g_param = parse_global_arg(parsed_globals)
74
+
75
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
76
+ cred = credential.CVMRoleCredential()
77
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
78
+ cred = credential.STSAssumeRoleCredential(
79
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
80
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
81
+ )
82
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
83
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
84
+ else:
85
+ cred = credential.Credential(
86
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
87
+ )
88
+ http_profile = HttpProfile(
89
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
90
+ reqMethod="POST",
91
+ endpoint=g_param[OptionsDefine.Endpoint],
92
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
93
+ )
94
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
95
+ if g_param[OptionsDefine.Language]:
96
+ profile.language = g_param[OptionsDefine.Language]
97
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
98
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
99
+ client._sdkVersion += ("_CLI_" + __version__)
100
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
101
+ model = models.DeleteGatewayLoadBalancerRequest()
102
+ model.from_json_string(json.dumps(args))
103
+ start_time = time.time()
104
+ while True:
105
+ rsp = client.DeleteGatewayLoadBalancer(model)
106
+ result = rsp.to_json_string()
107
+ try:
108
+ json_obj = json.loads(result)
109
+ except TypeError as e:
110
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
111
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
112
+ break
113
+ cur_time = time.time()
114
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
115
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
116
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
117
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
118
+ else:
119
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
120
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
121
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
122
+
123
+
124
+ def doDescribeTargetGroupInstanceStatus(args, parsed_globals):
125
+ g_param = parse_global_arg(parsed_globals)
126
+
127
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
128
+ cred = credential.CVMRoleCredential()
129
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
130
+ cred = credential.STSAssumeRoleCredential(
131
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
132
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
133
+ )
134
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
135
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
136
+ else:
137
+ cred = credential.Credential(
138
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
139
+ )
140
+ http_profile = HttpProfile(
141
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
142
+ reqMethod="POST",
143
+ endpoint=g_param[OptionsDefine.Endpoint],
144
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
145
+ )
146
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
147
+ if g_param[OptionsDefine.Language]:
148
+ profile.language = g_param[OptionsDefine.Language]
149
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
150
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
151
+ client._sdkVersion += ("_CLI_" + __version__)
152
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
153
+ model = models.DescribeTargetGroupInstanceStatusRequest()
154
+ model.from_json_string(json.dumps(args))
155
+ start_time = time.time()
156
+ while True:
157
+ rsp = client.DescribeTargetGroupInstanceStatus(model)
158
+ result = rsp.to_json_string()
159
+ try:
160
+ json_obj = json.loads(result)
161
+ except TypeError as e:
162
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
163
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
164
+ break
165
+ cur_time = time.time()
166
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
167
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
168
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
169
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
170
+ else:
171
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
172
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
173
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
174
+
175
+
176
+ def doDescribeTargetGroups(args, parsed_globals):
177
+ g_param = parse_global_arg(parsed_globals)
178
+
179
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
180
+ cred = credential.CVMRoleCredential()
181
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
182
+ cred = credential.STSAssumeRoleCredential(
183
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
184
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
185
+ )
186
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
187
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
188
+ else:
189
+ cred = credential.Credential(
190
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
191
+ )
192
+ http_profile = HttpProfile(
193
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
194
+ reqMethod="POST",
195
+ endpoint=g_param[OptionsDefine.Endpoint],
196
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
197
+ )
198
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
199
+ if g_param[OptionsDefine.Language]:
200
+ profile.language = g_param[OptionsDefine.Language]
201
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
202
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
203
+ client._sdkVersion += ("_CLI_" + __version__)
204
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
205
+ model = models.DescribeTargetGroupsRequest()
206
+ model.from_json_string(json.dumps(args))
207
+ start_time = time.time()
208
+ while True:
209
+ rsp = client.DescribeTargetGroups(model)
210
+ result = rsp.to_json_string()
211
+ try:
212
+ json_obj = json.loads(result)
213
+ except TypeError as e:
214
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
215
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
216
+ break
217
+ cur_time = time.time()
218
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
219
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
220
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
221
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
222
+ else:
223
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
224
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
225
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
226
+
227
+
228
+ def doDeregisterTargetGroupInstances(args, parsed_globals):
229
+ g_param = parse_global_arg(parsed_globals)
230
+
231
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
232
+ cred = credential.CVMRoleCredential()
233
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
234
+ cred = credential.STSAssumeRoleCredential(
235
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
236
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
237
+ )
238
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
239
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
240
+ else:
241
+ cred = credential.Credential(
242
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
243
+ )
244
+ http_profile = HttpProfile(
245
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
246
+ reqMethod="POST",
247
+ endpoint=g_param[OptionsDefine.Endpoint],
248
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
249
+ )
250
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
251
+ if g_param[OptionsDefine.Language]:
252
+ profile.language = g_param[OptionsDefine.Language]
253
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
254
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
255
+ client._sdkVersion += ("_CLI_" + __version__)
256
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
257
+ model = models.DeregisterTargetGroupInstancesRequest()
258
+ model.from_json_string(json.dumps(args))
259
+ start_time = time.time()
260
+ while True:
261
+ rsp = client.DeregisterTargetGroupInstances(model)
262
+ result = rsp.to_json_string()
263
+ try:
264
+ json_obj = json.loads(result)
265
+ except TypeError as e:
266
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
267
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
268
+ break
269
+ cur_time = time.time()
270
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
271
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
272
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
273
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
274
+ else:
275
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
276
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
277
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
278
+
279
+
280
+ def doCreateTargetGroup(args, parsed_globals):
281
+ g_param = parse_global_arg(parsed_globals)
282
+
283
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
284
+ cred = credential.CVMRoleCredential()
285
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
286
+ cred = credential.STSAssumeRoleCredential(
287
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
288
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
289
+ )
290
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
291
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
292
+ else:
293
+ cred = credential.Credential(
294
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
295
+ )
296
+ http_profile = HttpProfile(
297
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
298
+ reqMethod="POST",
299
+ endpoint=g_param[OptionsDefine.Endpoint],
300
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
301
+ )
302
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
303
+ if g_param[OptionsDefine.Language]:
304
+ profile.language = g_param[OptionsDefine.Language]
305
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
306
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
307
+ client._sdkVersion += ("_CLI_" + __version__)
308
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
309
+ model = models.CreateTargetGroupRequest()
310
+ model.from_json_string(json.dumps(args))
311
+ start_time = time.time()
312
+ while True:
313
+ rsp = client.CreateTargetGroup(model)
314
+ result = rsp.to_json_string()
315
+ try:
316
+ json_obj = json.loads(result)
317
+ except TypeError as e:
318
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
319
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
320
+ break
321
+ cur_time = time.time()
322
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
323
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
324
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
325
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
326
+ else:
327
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
328
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
329
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
330
+
331
+
332
+ def doDescribeTaskStatus(args, parsed_globals):
333
+ g_param = parse_global_arg(parsed_globals)
334
+
335
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
336
+ cred = credential.CVMRoleCredential()
337
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
338
+ cred = credential.STSAssumeRoleCredential(
339
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
340
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
341
+ )
342
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
343
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
344
+ else:
345
+ cred = credential.Credential(
346
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
347
+ )
348
+ http_profile = HttpProfile(
349
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
350
+ reqMethod="POST",
351
+ endpoint=g_param[OptionsDefine.Endpoint],
352
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
353
+ )
354
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
355
+ if g_param[OptionsDefine.Language]:
356
+ profile.language = g_param[OptionsDefine.Language]
357
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
358
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
359
+ client._sdkVersion += ("_CLI_" + __version__)
360
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
361
+ model = models.DescribeTaskStatusRequest()
362
+ model.from_json_string(json.dumps(args))
363
+ start_time = time.time()
364
+ while True:
365
+ rsp = client.DescribeTaskStatus(model)
366
+ result = rsp.to_json_string()
367
+ try:
368
+ json_obj = json.loads(result)
369
+ except TypeError as e:
370
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
371
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
372
+ break
373
+ cur_time = time.time()
374
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
375
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
376
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
377
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
378
+ else:
379
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
380
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
381
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
382
+
383
+
384
+ def doCreateGatewayLoadBalancer(args, parsed_globals):
385
+ g_param = parse_global_arg(parsed_globals)
386
+
387
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
388
+ cred = credential.CVMRoleCredential()
389
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
390
+ cred = credential.STSAssumeRoleCredential(
391
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
392
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
393
+ )
394
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
395
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
396
+ else:
397
+ cred = credential.Credential(
398
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
399
+ )
400
+ http_profile = HttpProfile(
401
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
402
+ reqMethod="POST",
403
+ endpoint=g_param[OptionsDefine.Endpoint],
404
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
405
+ )
406
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
407
+ if g_param[OptionsDefine.Language]:
408
+ profile.language = g_param[OptionsDefine.Language]
409
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
410
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
411
+ client._sdkVersion += ("_CLI_" + __version__)
412
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
413
+ model = models.CreateGatewayLoadBalancerRequest()
414
+ model.from_json_string(json.dumps(args))
415
+ start_time = time.time()
416
+ while True:
417
+ rsp = client.CreateGatewayLoadBalancer(model)
418
+ result = rsp.to_json_string()
419
+ try:
420
+ json_obj = json.loads(result)
421
+ except TypeError as e:
422
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
423
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
424
+ break
425
+ cur_time = time.time()
426
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
427
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
428
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
429
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
430
+ else:
431
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
432
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
433
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
434
+
435
+
436
+ def doDisassociateTargetGroups(args, parsed_globals):
437
+ g_param = parse_global_arg(parsed_globals)
438
+
439
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
440
+ cred = credential.CVMRoleCredential()
441
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
442
+ cred = credential.STSAssumeRoleCredential(
443
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
444
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
445
+ )
446
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
447
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
448
+ else:
449
+ cred = credential.Credential(
450
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
451
+ )
452
+ http_profile = HttpProfile(
453
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
454
+ reqMethod="POST",
455
+ endpoint=g_param[OptionsDefine.Endpoint],
456
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
457
+ )
458
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
459
+ if g_param[OptionsDefine.Language]:
460
+ profile.language = g_param[OptionsDefine.Language]
461
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
462
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
463
+ client._sdkVersion += ("_CLI_" + __version__)
464
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
465
+ model = models.DisassociateTargetGroupsRequest()
466
+ model.from_json_string(json.dumps(args))
467
+ start_time = time.time()
468
+ while True:
469
+ rsp = client.DisassociateTargetGroups(model)
470
+ result = rsp.to_json_string()
471
+ try:
472
+ json_obj = json.loads(result)
473
+ except TypeError as e:
474
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
475
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
476
+ break
477
+ cur_time = time.time()
478
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
479
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
480
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
481
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
482
+ else:
483
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
484
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
485
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
486
+
487
+
488
+ def doRegisterTargetGroupInstances(args, parsed_globals):
489
+ g_param = parse_global_arg(parsed_globals)
490
+
491
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
492
+ cred = credential.CVMRoleCredential()
493
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
494
+ cred = credential.STSAssumeRoleCredential(
495
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
496
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
497
+ )
498
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
499
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
500
+ else:
501
+ cred = credential.Credential(
502
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
503
+ )
504
+ http_profile = HttpProfile(
505
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
506
+ reqMethod="POST",
507
+ endpoint=g_param[OptionsDefine.Endpoint],
508
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
509
+ )
510
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
511
+ if g_param[OptionsDefine.Language]:
512
+ profile.language = g_param[OptionsDefine.Language]
513
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
514
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
515
+ client._sdkVersion += ("_CLI_" + __version__)
516
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
517
+ model = models.RegisterTargetGroupInstancesRequest()
518
+ model.from_json_string(json.dumps(args))
519
+ start_time = time.time()
520
+ while True:
521
+ rsp = client.RegisterTargetGroupInstances(model)
522
+ result = rsp.to_json_string()
523
+ try:
524
+ json_obj = json.loads(result)
525
+ except TypeError as e:
526
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
527
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
528
+ break
529
+ cur_time = time.time()
530
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
531
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
532
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
533
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
534
+ else:
535
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
536
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
537
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
538
+
539
+
540
+ def doAssociateTargetGroups(args, parsed_globals):
541
+ g_param = parse_global_arg(parsed_globals)
542
+
543
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
544
+ cred = credential.CVMRoleCredential()
545
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
546
+ cred = credential.STSAssumeRoleCredential(
547
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
548
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
549
+ )
550
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
551
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
552
+ else:
553
+ cred = credential.Credential(
554
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
555
+ )
556
+ http_profile = HttpProfile(
557
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
558
+ reqMethod="POST",
559
+ endpoint=g_param[OptionsDefine.Endpoint],
560
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
561
+ )
562
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
563
+ if g_param[OptionsDefine.Language]:
564
+ profile.language = g_param[OptionsDefine.Language]
565
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
566
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
567
+ client._sdkVersion += ("_CLI_" + __version__)
568
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
569
+ model = models.AssociateTargetGroupsRequest()
570
+ model.from_json_string(json.dumps(args))
571
+ start_time = time.time()
572
+ while True:
573
+ rsp = client.AssociateTargetGroups(model)
574
+ result = rsp.to_json_string()
575
+ try:
576
+ json_obj = json.loads(result)
577
+ except TypeError as e:
578
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
579
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
580
+ break
581
+ cur_time = time.time()
582
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
583
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
584
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
585
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
586
+ else:
587
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
588
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
589
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
590
+
591
+
592
+ def doDescribeGatewayLoadBalancers(args, parsed_globals):
593
+ g_param = parse_global_arg(parsed_globals)
594
+
595
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
596
+ cred = credential.CVMRoleCredential()
597
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
598
+ cred = credential.STSAssumeRoleCredential(
599
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
600
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
601
+ )
602
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
603
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
604
+ else:
605
+ cred = credential.Credential(
606
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
607
+ )
608
+ http_profile = HttpProfile(
609
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
610
+ reqMethod="POST",
611
+ endpoint=g_param[OptionsDefine.Endpoint],
612
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
613
+ )
614
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
615
+ if g_param[OptionsDefine.Language]:
616
+ profile.language = g_param[OptionsDefine.Language]
617
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
618
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
619
+ client._sdkVersion += ("_CLI_" + __version__)
620
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
621
+ model = models.DescribeGatewayLoadBalancersRequest()
622
+ model.from_json_string(json.dumps(args))
623
+ start_time = time.time()
624
+ while True:
625
+ rsp = client.DescribeGatewayLoadBalancers(model)
626
+ result = rsp.to_json_string()
627
+ try:
628
+ json_obj = json.loads(result)
629
+ except TypeError as e:
630
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
631
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
632
+ break
633
+ cur_time = time.time()
634
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
635
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
636
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
637
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
638
+ else:
639
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
640
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
641
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
642
+
643
+
644
+ def doModifyGatewayLoadBalancerAttribute(args, parsed_globals):
645
+ g_param = parse_global_arg(parsed_globals)
646
+
647
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
648
+ cred = credential.CVMRoleCredential()
649
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
650
+ cred = credential.STSAssumeRoleCredential(
651
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
652
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
653
+ )
654
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
655
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
656
+ else:
657
+ cred = credential.Credential(
658
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
659
+ )
660
+ http_profile = HttpProfile(
661
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
662
+ reqMethod="POST",
663
+ endpoint=g_param[OptionsDefine.Endpoint],
664
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
665
+ )
666
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
667
+ if g_param[OptionsDefine.Language]:
668
+ profile.language = g_param[OptionsDefine.Language]
669
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
670
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
671
+ client._sdkVersion += ("_CLI_" + __version__)
672
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
673
+ model = models.ModifyGatewayLoadBalancerAttributeRequest()
674
+ model.from_json_string(json.dumps(args))
675
+ start_time = time.time()
676
+ while True:
677
+ rsp = client.ModifyGatewayLoadBalancerAttribute(model)
678
+ result = rsp.to_json_string()
679
+ try:
680
+ json_obj = json.loads(result)
681
+ except TypeError as e:
682
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
683
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
684
+ break
685
+ cur_time = time.time()
686
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
687
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
688
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
689
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
690
+ else:
691
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
692
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
693
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
694
+
695
+
696
+ def doModifyTargetGroupInstancesWeight(args, parsed_globals):
697
+ g_param = parse_global_arg(parsed_globals)
698
+
699
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
700
+ cred = credential.CVMRoleCredential()
701
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
702
+ cred = credential.STSAssumeRoleCredential(
703
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
704
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
705
+ )
706
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
707
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
708
+ else:
709
+ cred = credential.Credential(
710
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
711
+ )
712
+ http_profile = HttpProfile(
713
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
714
+ reqMethod="POST",
715
+ endpoint=g_param[OptionsDefine.Endpoint],
716
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
717
+ )
718
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
719
+ if g_param[OptionsDefine.Language]:
720
+ profile.language = g_param[OptionsDefine.Language]
721
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
722
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
723
+ client._sdkVersion += ("_CLI_" + __version__)
724
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
725
+ model = models.ModifyTargetGroupInstancesWeightRequest()
726
+ model.from_json_string(json.dumps(args))
727
+ start_time = time.time()
728
+ while True:
729
+ rsp = client.ModifyTargetGroupInstancesWeight(model)
730
+ result = rsp.to_json_string()
731
+ try:
732
+ json_obj = json.loads(result)
733
+ except TypeError as e:
734
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
735
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
736
+ break
737
+ cur_time = time.time()
738
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
739
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
740
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
741
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
742
+ else:
743
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
744
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
745
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
746
+
747
+
748
+ def doModifyTargetGroupAttribute(args, parsed_globals):
749
+ g_param = parse_global_arg(parsed_globals)
750
+
751
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
752
+ cred = credential.CVMRoleCredential()
753
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
754
+ cred = credential.STSAssumeRoleCredential(
755
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
756
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
757
+ )
758
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
759
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
760
+ else:
761
+ cred = credential.Credential(
762
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
763
+ )
764
+ http_profile = HttpProfile(
765
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
766
+ reqMethod="POST",
767
+ endpoint=g_param[OptionsDefine.Endpoint],
768
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
769
+ )
770
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
771
+ if g_param[OptionsDefine.Language]:
772
+ profile.language = g_param[OptionsDefine.Language]
773
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
774
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
775
+ client._sdkVersion += ("_CLI_" + __version__)
776
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
777
+ model = models.ModifyTargetGroupAttributeRequest()
778
+ model.from_json_string(json.dumps(args))
779
+ start_time = time.time()
780
+ while True:
781
+ rsp = client.ModifyTargetGroupAttribute(model)
782
+ result = rsp.to_json_string()
783
+ try:
784
+ json_obj = json.loads(result)
785
+ except TypeError as e:
786
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
787
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
788
+ break
789
+ cur_time = time.time()
790
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
791
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
792
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
793
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
794
+ else:
795
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
796
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
797
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
798
+
799
+
800
+ def doDescribeTargetGroupList(args, parsed_globals):
801
+ g_param = parse_global_arg(parsed_globals)
802
+
803
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
804
+ cred = credential.CVMRoleCredential()
805
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
806
+ cred = credential.STSAssumeRoleCredential(
807
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
808
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
809
+ )
810
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
811
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
812
+ else:
813
+ cred = credential.Credential(
814
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
815
+ )
816
+ http_profile = HttpProfile(
817
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
818
+ reqMethod="POST",
819
+ endpoint=g_param[OptionsDefine.Endpoint],
820
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
821
+ )
822
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
823
+ if g_param[OptionsDefine.Language]:
824
+ profile.language = g_param[OptionsDefine.Language]
825
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
826
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
827
+ client._sdkVersion += ("_CLI_" + __version__)
828
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
829
+ model = models.DescribeTargetGroupListRequest()
830
+ model.from_json_string(json.dumps(args))
831
+ start_time = time.time()
832
+ while True:
833
+ rsp = client.DescribeTargetGroupList(model)
834
+ result = rsp.to_json_string()
835
+ try:
836
+ json_obj = json.loads(result)
837
+ except TypeError as e:
838
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
839
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
840
+ break
841
+ cur_time = time.time()
842
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
843
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
844
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
845
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
846
+ else:
847
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
848
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
849
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
850
+
851
+
852
+ def doDescribeTargetGroupInstances(args, parsed_globals):
853
+ g_param = parse_global_arg(parsed_globals)
854
+
855
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
856
+ cred = credential.CVMRoleCredential()
857
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
858
+ cred = credential.STSAssumeRoleCredential(
859
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
860
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
861
+ )
862
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
863
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
864
+ else:
865
+ cred = credential.Credential(
866
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
867
+ )
868
+ http_profile = HttpProfile(
869
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
870
+ reqMethod="POST",
871
+ endpoint=g_param[OptionsDefine.Endpoint],
872
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
873
+ )
874
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
875
+ if g_param[OptionsDefine.Language]:
876
+ profile.language = g_param[OptionsDefine.Language]
877
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
878
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
879
+ client._sdkVersion += ("_CLI_" + __version__)
880
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
881
+ model = models.DescribeTargetGroupInstancesRequest()
882
+ model.from_json_string(json.dumps(args))
883
+ start_time = time.time()
884
+ while True:
885
+ rsp = client.DescribeTargetGroupInstances(model)
886
+ result = rsp.to_json_string()
887
+ try:
888
+ json_obj = json.loads(result)
889
+ except TypeError as e:
890
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
891
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
892
+ break
893
+ cur_time = time.time()
894
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
895
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
896
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
897
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
898
+ else:
899
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
900
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
901
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
902
+
903
+
904
+ def doInquirePriceCreateGatewayLoadBalancer(args, parsed_globals):
905
+ g_param = parse_global_arg(parsed_globals)
906
+
907
+ if g_param[OptionsDefine.UseCVMRole.replace('-', '_')]:
908
+ cred = credential.CVMRoleCredential()
909
+ elif g_param[OptionsDefine.RoleArn.replace('-', '_')] and g_param[OptionsDefine.RoleSessionName.replace('-', '_')]:
910
+ cred = credential.STSAssumeRoleCredential(
911
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.RoleArn.replace('-', '_')],
912
+ g_param[OptionsDefine.RoleSessionName.replace('-', '_')], endpoint=g_param["sts_cred_endpoint"]
913
+ )
914
+ elif os.getenv(OptionsDefine.ENV_TKE_REGION) and os.getenv(OptionsDefine.ENV_TKE_PROVIDER_ID) and os.getenv(OptionsDefine.ENV_TKE_WEB_IDENTITY_TOKEN_FILE) and os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN):
915
+ cred = credential.DefaultTkeOIDCRoleArnProvider().get_credentials()
916
+ else:
917
+ cred = credential.Credential(
918
+ g_param[OptionsDefine.SecretId], g_param[OptionsDefine.SecretKey], g_param[OptionsDefine.Token]
919
+ )
920
+ http_profile = HttpProfile(
921
+ reqTimeout=60 if g_param[OptionsDefine.Timeout] is None else int(g_param[OptionsDefine.Timeout]),
922
+ reqMethod="POST",
923
+ endpoint=g_param[OptionsDefine.Endpoint],
924
+ proxy=g_param[OptionsDefine.HttpsProxy.replace('-', '_')]
925
+ )
926
+ profile = ClientProfile(httpProfile=http_profile, signMethod="HmacSHA256")
927
+ if g_param[OptionsDefine.Language]:
928
+ profile.language = g_param[OptionsDefine.Language]
929
+ mod = CLIENT_MAP[g_param[OptionsDefine.Version]]
930
+ client = mod.GwlbClient(cred, g_param[OptionsDefine.Region], profile)
931
+ client._sdkVersion += ("_CLI_" + __version__)
932
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
933
+ model = models.InquirePriceCreateGatewayLoadBalancerRequest()
934
+ model.from_json_string(json.dumps(args))
935
+ start_time = time.time()
936
+ while True:
937
+ rsp = client.InquirePriceCreateGatewayLoadBalancer(model)
938
+ result = rsp.to_json_string()
939
+ try:
940
+ json_obj = json.loads(result)
941
+ except TypeError as e:
942
+ json_obj = json.loads(result.decode('utf-8')) # python3.3
943
+ if not g_param[OptionsDefine.Waiter] or search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj) == g_param['OptionsDefine.WaiterInfo']['to']:
944
+ break
945
+ cur_time = time.time()
946
+ if cur_time - start_time >= g_param['OptionsDefine.WaiterInfo']['timeout']:
947
+ raise ClientError('Request timeout, wait `%s` to `%s` timeout, last request is %s' %
948
+ (g_param['OptionsDefine.WaiterInfo']['expr'], g_param['OptionsDefine.WaiterInfo']['to'],
949
+ search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj)))
950
+ else:
951
+ print('Inquiry result is %s.' % search(g_param['OptionsDefine.WaiterInfo']['expr'], json_obj))
952
+ time.sleep(g_param['OptionsDefine.WaiterInfo']['interval'])
953
+ FormatOutput.output("action", json_obj, g_param[OptionsDefine.Output], g_param[OptionsDefine.Filter])
954
+
955
+
956
+ CLIENT_MAP = {
957
+ "v20240906": gwlb_client_v20240906,
958
+
959
+ }
960
+
961
+ MODELS_MAP = {
962
+ "v20240906": models_v20240906,
963
+
964
+ }
965
+
966
+ ACTION_MAP = {
967
+ "DeleteTargetGroups": doDeleteTargetGroups,
968
+ "DeleteGatewayLoadBalancer": doDeleteGatewayLoadBalancer,
969
+ "DescribeTargetGroupInstanceStatus": doDescribeTargetGroupInstanceStatus,
970
+ "DescribeTargetGroups": doDescribeTargetGroups,
971
+ "DeregisterTargetGroupInstances": doDeregisterTargetGroupInstances,
972
+ "CreateTargetGroup": doCreateTargetGroup,
973
+ "DescribeTaskStatus": doDescribeTaskStatus,
974
+ "CreateGatewayLoadBalancer": doCreateGatewayLoadBalancer,
975
+ "DisassociateTargetGroups": doDisassociateTargetGroups,
976
+ "RegisterTargetGroupInstances": doRegisterTargetGroupInstances,
977
+ "AssociateTargetGroups": doAssociateTargetGroups,
978
+ "DescribeGatewayLoadBalancers": doDescribeGatewayLoadBalancers,
979
+ "ModifyGatewayLoadBalancerAttribute": doModifyGatewayLoadBalancerAttribute,
980
+ "ModifyTargetGroupInstancesWeight": doModifyTargetGroupInstancesWeight,
981
+ "ModifyTargetGroupAttribute": doModifyTargetGroupAttribute,
982
+ "DescribeTargetGroupList": doDescribeTargetGroupList,
983
+ "DescribeTargetGroupInstances": doDescribeTargetGroupInstances,
984
+ "InquirePriceCreateGatewayLoadBalancer": doInquirePriceCreateGatewayLoadBalancer,
985
+
986
+ }
987
+
988
+ AVAILABLE_VERSION_LIST = [
989
+ "v20240906",
990
+
991
+ ]
992
+
993
+
994
+ def action_caller():
995
+ return ACTION_MAP
996
+
997
+
998
+ def parse_global_arg(parsed_globals):
999
+ g_param = parsed_globals
1000
+
1001
+ is_exist_profile = True
1002
+ if not parsed_globals["profile"]:
1003
+ is_exist_profile = False
1004
+ g_param["profile"] = os.environ.get("TCCLI_PROFILE", "default")
1005
+
1006
+ configure_path = os.path.join(os.path.expanduser("~"), ".tccli")
1007
+ is_conf_exist, conf_path = Utils.file_existed(configure_path, g_param["profile"] + ".configure")
1008
+ is_cred_exist, cred_path = Utils.file_existed(configure_path, g_param["profile"] + ".credential")
1009
+
1010
+ conf = {}
1011
+ cred = {}
1012
+
1013
+ if is_conf_exist:
1014
+ conf = Utils.load_json_msg(conf_path)
1015
+ if is_cred_exist:
1016
+ cred = Utils.load_json_msg(cred_path)
1017
+
1018
+ if not (isinstance(conf, dict) and isinstance(cred, dict)):
1019
+ raise ConfigurationError(
1020
+ "file: %s or %s is not json format"
1021
+ % (g_param["profile"] + ".configure", g_param["profile"] + ".credential"))
1022
+
1023
+ if OptionsDefine.Token not in cred:
1024
+ cred[OptionsDefine.Token] = None
1025
+
1026
+ if not is_exist_profile:
1027
+ if os.environ.get(OptionsDefine.ENV_SECRET_ID) and os.environ.get(OptionsDefine.ENV_SECRET_KEY):
1028
+ cred[OptionsDefine.SecretId] = os.environ.get(OptionsDefine.ENV_SECRET_ID)
1029
+ cred[OptionsDefine.SecretKey] = os.environ.get(OptionsDefine.ENV_SECRET_KEY)
1030
+ cred[OptionsDefine.Token] = os.environ.get(OptionsDefine.ENV_TOKEN)
1031
+
1032
+ if os.environ.get(OptionsDefine.ENV_REGION):
1033
+ conf[OptionsDefine.SysParam][OptionsDefine.Region] = os.environ.get(OptionsDefine.ENV_REGION)
1034
+
1035
+ if os.environ.get(OptionsDefine.ENV_ROLE_ARN) and os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME):
1036
+ cred[OptionsDefine.RoleArn] = os.environ.get(OptionsDefine.ENV_ROLE_ARN)
1037
+ cred[OptionsDefine.RoleSessionName] = os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME)
1038
+
1039
+ for param in g_param.keys():
1040
+ if g_param[param] is None:
1041
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.Token]:
1042
+ if param in cred:
1043
+ g_param[param] = cred[param]
1044
+ elif not (g_param[OptionsDefine.UseCVMRole.replace('-', '_')]
1045
+ or os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN)):
1046
+ raise ConfigurationError("%s is invalid" % param)
1047
+ elif param in [OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.Language]:
1048
+ if param in conf[OptionsDefine.SysParam]:
1049
+ g_param[param] = conf[OptionsDefine.SysParam][param]
1050
+ elif param != OptionsDefine.Language:
1051
+ raise ConfigurationError("%s is invalid" % param)
1052
+ elif param.replace('_', '-') in [OptionsDefine.RoleArn, OptionsDefine.RoleSessionName]:
1053
+ if param.replace('_', '-') in cred:
1054
+ g_param[param] = cred[param.replace('_', '-')]
1055
+
1056
+ try:
1057
+ if g_param[OptionsDefine.ServiceVersion]:
1058
+ g_param[OptionsDefine.Version] = "v" + g_param[OptionsDefine.ServiceVersion].replace('-', '')
1059
+ else:
1060
+ version = conf["gwlb"][OptionsDefine.Version]
1061
+ g_param[OptionsDefine.Version] = "v" + version.replace('-', '')
1062
+
1063
+ if g_param[OptionsDefine.Endpoint] is None:
1064
+ g_param[OptionsDefine.Endpoint] = conf["gwlb"][OptionsDefine.Endpoint]
1065
+ g_param["sts_cred_endpoint"] = conf.get("sts", {}).get("endpoint")
1066
+ except Exception as err:
1067
+ raise ConfigurationError("config file:%s error, %s" % (conf_path, str(err)))
1068
+
1069
+ if g_param[OptionsDefine.Version] not in AVAILABLE_VERSION_LIST:
1070
+ raise Exception("available versions: %s" % " ".join(AVAILABLE_VERSION_LIST))
1071
+
1072
+ if g_param[OptionsDefine.Waiter]:
1073
+ param = eval(g_param[OptionsDefine.Waiter])
1074
+ if 'expr' not in param:
1075
+ raise Exception('`expr` in `--waiter` must be defined')
1076
+ if 'to' not in param:
1077
+ raise Exception('`to` in `--waiter` must be defined')
1078
+ if 'timeout' not in param:
1079
+ if 'waiter' in conf and 'timeout' in conf['waiter']:
1080
+ param['timeout'] = conf['waiter']['timeout']
1081
+ else:
1082
+ param['timeout'] = 180
1083
+ if 'interval' not in param:
1084
+ if 'waiter' in conf and 'interval' in conf['waiter']:
1085
+ param['interval'] = conf['waiter']['interval']
1086
+ else:
1087
+ param['interval'] = 5
1088
+ param['interval'] = min(param['interval'], param['timeout'])
1089
+ g_param['OptionsDefine.WaiterInfo'] = param
1090
+
1091
+ if six.PY2:
1092
+ for key, value in g_param.items():
1093
+ if isinstance(value, six.text_type):
1094
+ g_param[key] = value.encode('utf-8')
1095
+ return g_param
1096
+