tccli-intl-en 3.0.1258.1__py2.py3-none-any.whl → 3.0.1259.1__py2.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.
tccli/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '3.0.1258.1'
1
+ __version__ = '3.0.1259.1'
@@ -361,6 +361,9 @@ SERVICE_VERSIONS = {
361
361
  "2022-09-01",
362
362
  "2022-01-06"
363
363
  ],
364
+ "tione": [
365
+ "2021-11-11"
366
+ ],
364
367
  "tiw": [
365
368
  "2019-09-19"
366
369
  ],
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from tccli.services.tione.tione_client import action_caller
4
+
@@ -0,0 +1,207 @@
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.tione.v20211111 import tione_client as tione_client_v20211111
15
+ from tencentcloud.tione.v20211111 import models as models_v20211111
16
+
17
+ from jmespath import search
18
+ import time
19
+
20
+ def doDescribeModelServiceGroups(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.TioneClient(cred, g_param[OptionsDefine.Region], profile)
47
+ client._sdkVersion += ("_CLI_" + __version__)
48
+ models = MODELS_MAP[g_param[OptionsDefine.Version]]
49
+ model = models.DescribeModelServiceGroupsRequest()
50
+ model.from_json_string(json.dumps(args))
51
+ start_time = time.time()
52
+ while True:
53
+ rsp = client.DescribeModelServiceGroups(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
+ CLIENT_MAP = {
73
+ "v20211111": tione_client_v20211111,
74
+
75
+ }
76
+
77
+ MODELS_MAP = {
78
+ "v20211111": models_v20211111,
79
+
80
+ }
81
+
82
+ ACTION_MAP = {
83
+ "DescribeModelServiceGroups": doDescribeModelServiceGroups,
84
+
85
+ }
86
+
87
+ AVAILABLE_VERSION_LIST = [
88
+ "v20211111",
89
+
90
+ ]
91
+
92
+
93
+ def action_caller():
94
+ return ACTION_MAP
95
+
96
+
97
+ def parse_global_arg(parsed_globals):
98
+ g_param = parsed_globals
99
+ cvm_role_flag = True
100
+ for param in parsed_globals.keys():
101
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.RoleArn,
102
+ OptionsDefine.RoleSessionName]:
103
+ if parsed_globals[param] is not None:
104
+ cvm_role_flag = False
105
+ break
106
+ is_exist_profile = True
107
+ if not parsed_globals["profile"]:
108
+ is_exist_profile = False
109
+ g_param["profile"] = os.environ.get("TCCLI_PROFILE", "default")
110
+
111
+ configure_path = os.path.join(os.path.expanduser("~"), ".tccli")
112
+ is_conf_exist, conf_path = Utils.file_existed(configure_path, g_param["profile"] + ".configure")
113
+ is_cred_exist, cred_path = Utils.file_existed(configure_path, g_param["profile"] + ".credential")
114
+
115
+ conf = {}
116
+ cred = {}
117
+
118
+ if is_conf_exist:
119
+ conf = Utils.load_json_msg(conf_path)
120
+ if is_cred_exist:
121
+ cred = Utils.load_json_msg(cred_path)
122
+
123
+ if not (isinstance(conf, dict) and isinstance(cred, dict)):
124
+ raise ConfigurationError(
125
+ "file: %s or %s is not json format"
126
+ % (g_param["profile"] + ".configure", g_param["profile"] + ".credential"))
127
+
128
+ if OptionsDefine.Token not in cred:
129
+ cred[OptionsDefine.Token] = None
130
+
131
+ if not is_exist_profile:
132
+ if os.environ.get(OptionsDefine.ENV_SECRET_ID) and os.environ.get(OptionsDefine.ENV_SECRET_KEY):
133
+ cred[OptionsDefine.SecretId] = os.environ.get(OptionsDefine.ENV_SECRET_ID)
134
+ cred[OptionsDefine.SecretKey] = os.environ.get(OptionsDefine.ENV_SECRET_KEY)
135
+ cred[OptionsDefine.Token] = os.environ.get(OptionsDefine.ENV_TOKEN)
136
+ cvm_role_flag = False
137
+
138
+ if os.environ.get(OptionsDefine.ENV_REGION):
139
+ conf[OptionsDefine.SysParam][OptionsDefine.Region] = os.environ.get(OptionsDefine.ENV_REGION)
140
+
141
+ if os.environ.get(OptionsDefine.ENV_ROLE_ARN) and os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME):
142
+ cred[OptionsDefine.RoleArn] = os.environ.get(OptionsDefine.ENV_ROLE_ARN)
143
+ cred[OptionsDefine.RoleSessionName] = os.environ.get(OptionsDefine.ENV_ROLE_SESSION_NAME)
144
+ cvm_role_flag = False
145
+
146
+ if cvm_role_flag:
147
+ if "type" in cred and cred["type"] == "cvm-role":
148
+ g_param[OptionsDefine.UseCVMRole.replace('-', '_')] = True
149
+
150
+ for param in g_param.keys():
151
+ if g_param[param] is None:
152
+ if param in [OptionsDefine.SecretKey, OptionsDefine.SecretId, OptionsDefine.Token]:
153
+ if param in cred:
154
+ g_param[param] = cred[param]
155
+ elif not (g_param[OptionsDefine.UseCVMRole.replace('-', '_')]
156
+ or os.getenv(OptionsDefine.ENV_TKE_ROLE_ARN)):
157
+ raise ConfigurationError("%s is invalid" % param)
158
+ elif param in [OptionsDefine.Region, OptionsDefine.Output, OptionsDefine.Language]:
159
+ if param in conf[OptionsDefine.SysParam]:
160
+ g_param[param] = conf[OptionsDefine.SysParam][param]
161
+ elif param != OptionsDefine.Language:
162
+ raise ConfigurationError("%s is invalid" % param)
163
+ elif param.replace('_', '-') in [OptionsDefine.RoleArn, OptionsDefine.RoleSessionName]:
164
+ if param.replace('_', '-') in cred:
165
+ g_param[param] = cred[param.replace('_', '-')]
166
+
167
+ try:
168
+ if g_param[OptionsDefine.ServiceVersion]:
169
+ g_param[OptionsDefine.Version] = "v" + g_param[OptionsDefine.ServiceVersion].replace('-', '')
170
+ else:
171
+ version = conf["tione"][OptionsDefine.Version]
172
+ g_param[OptionsDefine.Version] = "v" + version.replace('-', '')
173
+
174
+ if g_param[OptionsDefine.Endpoint] is None:
175
+ g_param[OptionsDefine.Endpoint] = conf["tione"][OptionsDefine.Endpoint]
176
+ g_param["sts_cred_endpoint"] = conf.get("sts", {}).get("endpoint")
177
+ except Exception as err:
178
+ raise ConfigurationError("config file:%s error, %s" % (conf_path, str(err)))
179
+
180
+ if g_param[OptionsDefine.Version] not in AVAILABLE_VERSION_LIST:
181
+ raise Exception("available versions: %s" % " ".join(AVAILABLE_VERSION_LIST))
182
+
183
+ if g_param[OptionsDefine.Waiter]:
184
+ param = eval(g_param[OptionsDefine.Waiter])
185
+ if 'expr' not in param:
186
+ raise Exception('`expr` in `--waiter` must be defined')
187
+ if 'to' not in param:
188
+ raise Exception('`to` in `--waiter` must be defined')
189
+ if 'timeout' not in param:
190
+ if 'waiter' in conf and 'timeout' in conf['waiter']:
191
+ param['timeout'] = conf['waiter']['timeout']
192
+ else:
193
+ param['timeout'] = 180
194
+ if 'interval' not in param:
195
+ if 'waiter' in conf and 'interval' in conf['waiter']:
196
+ param['interval'] = conf['waiter']['interval']
197
+ else:
198
+ param['interval'] = 5
199
+ param['interval'] = min(param['interval'], param['timeout'])
200
+ g_param['OptionsDefine.WaiterInfo'] = param
201
+
202
+ if six.PY2:
203
+ for key, value in g_param.items():
204
+ if isinstance(value, six.text_type):
205
+ g_param[key] = value.encode('utf-8')
206
+ return g_param
207
+