pixelarraylib 1.1.8__tar.gz → 1.2.0__tar.gz

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.
Files changed (50) hide show
  1. {pixelarraylib-1.1.8/pixelarraylib.egg-info → pixelarraylib-1.2.0}/PKG-INFO +8 -1
  2. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/__init__.py +1 -1
  3. pixelarraylib-1.2.0/pixelarraylib/aliyun/polardb.py +950 -0
  4. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/__init__.py +1 -1
  5. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0/pixelarraylib.egg-info}/PKG-INFO +8 -1
  6. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib.egg-info/SOURCES.txt +1 -0
  7. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib.egg-info/requires.txt +8 -0
  8. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pyproject.toml +9 -1
  9. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/requirements.txt +1 -0
  10. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/LICENSE +0 -0
  11. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/MANIFEST.in +0 -0
  12. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/README.md +0 -0
  13. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/__main__.py +0 -0
  14. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/__init__.py +0 -0
  15. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/acr.py +0 -0
  16. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/aliyun_email.py +0 -0
  17. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/billing.py +0 -0
  18. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/content_scanner.py +0 -0
  19. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/domain.py +0 -0
  20. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/eci.py +0 -0
  21. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/ecs.py +0 -0
  22. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/eip.py +0 -0
  23. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/fc.py +0 -0
  24. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/oss.py +0 -0
  25. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/sms.py +0 -0
  26. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/aliyun/sts.py +0 -0
  27. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/db_utils/mysql.py +0 -0
  28. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/db_utils/redis.py +0 -0
  29. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/decorators/__init__.py +0 -0
  30. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/decorators/decorators.py +0 -0
  31. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/gitlab/__init__.py +0 -0
  32. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/gitlab/code_analyzer.py +0 -0
  33. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/gitlab/pypi_package_manager.py +0 -0
  34. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/monitor/__init__.py +0 -0
  35. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/monitor/feishu.py +0 -0
  36. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/build_website.py +0 -0
  37. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/collect_code_to_txt.py +0 -0
  38. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/create_test_case_files.py +0 -0
  39. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/nginx_proxy_to_ecs.py +0 -0
  40. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/remove_empty_lines.py +0 -0
  41. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/scripts/tson_convert.py +0 -0
  42. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/system/__init__.py +0 -0
  43. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/system/common.py +0 -0
  44. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/system/cron_manager.py +0 -0
  45. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/system/tson.py +0 -0
  46. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib/utils/name_generator.py +0 -0
  47. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib.egg-info/dependency_links.txt +0 -0
  48. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib.egg-info/entry_points.txt +0 -0
  49. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/pixelarraylib.egg-info/top_level.txt +0 -0
  50. {pixelarraylib-1.1.8 → pixelarraylib-1.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraylib
3
- Version: 1.1.8
3
+ Version: 1.2.0
4
4
  Summary: PixelArray Python开发工具库 - 包含阿里云服务、数据库工具、装饰器、监控等功能
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -111,6 +111,12 @@ Requires-Dist: alibabacloud_tea_util; extra == "aliyun-fc"
111
111
  Requires-Dist: requests; extra == "aliyun-fc"
112
112
  Requires-Dist: cryptography; extra == "aliyun-fc"
113
113
  Requires-Dist: paramiko; extra == "aliyun-fc"
114
+ Provides-Extra: aliyun-polardb
115
+ Requires-Dist: alibabacloud_polardb20170801; extra == "aliyun-polardb"
116
+ Requires-Dist: alibabacloud_credentials; extra == "aliyun-polardb"
117
+ Requires-Dist: alibabacloud_tea_openapi; extra == "aliyun-polardb"
118
+ Requires-Dist: alibabacloud_tea_util; extra == "aliyun-polardb"
119
+ Requires-Dist: requests; extra == "aliyun-polardb"
114
120
  Provides-Extra: aliyun
115
121
  Requires-Dist: alibabacloud_tea_util; extra == "aliyun"
116
122
  Requires-Dist: alibabacloud_cms20190101; extra == "aliyun"
@@ -151,6 +157,7 @@ Requires-Dist: alibabacloud_cr20181201; extra == "all"
151
157
  Requires-Dist: alibabacloud_vpc20160428; extra == "all"
152
158
  Requires-Dist: alibabacloud_tea_openapi; extra == "all"
153
159
  Requires-Dist: alibabacloud_credentials; extra == "all"
160
+ Requires-Dist: alibabacloud_polardb20170801; extra == "all"
154
161
  Requires-Dist: oss2; extra == "all"
155
162
  Requires-Dist: pymysql; extra == "all"
156
163
  Requires-Dist: aiomysql; extra == "all"
@@ -20,7 +20,7 @@ PixelArray Python开发工具库
20
20
  from pixelarraylib.gitlab import pypi_package_manager
21
21
  """
22
22
 
23
- __version__ = "1.1.8"
23
+ __version__ = "1.2.0"
24
24
  __author__ = "PixelArray"
25
25
  __email__ = "qi.lu@pixelarrayai.com"
26
26
 
@@ -0,0 +1,950 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ import os
4
+ import sys
5
+ import json
6
+
7
+ from typing import List
8
+
9
+ from alibabacloud_polardb20170801.client import Client as polardb20170801Client
10
+ from alibabacloud_tea_openapi import models as open_api_models
11
+ from alibabacloud_polardb20170801 import models as polardb_20170801_models
12
+ from alibabacloud_tea_util import models as util_models
13
+ from alibabacloud_tea_util.client import Client as UtilClient
14
+
15
+
16
+ class PolarDBUtils:
17
+ def __init__(self, region_id: str, access_key_id: str, access_key_secret: str):
18
+ """
19
+ description:
20
+ 初始化PolarDB工具类
21
+ parameters:
22
+ region_id(str): 阿里云区域ID
23
+ access_key_id(str): 阿里云访问密钥ID
24
+ access_key_secret(str): 阿里云访问密钥Secret
25
+ """
26
+ self.region_id = region_id
27
+ self.access_key_id = access_key_id
28
+ self.access_key_secret = access_key_secret
29
+ self.client = self._create_client()
30
+
31
+ def _create_client(self) -> polardb20170801Client:
32
+ """
33
+ description:
34
+ 创建PolarDB客户端
35
+ return:
36
+ polardb20170801Client: PolarDB客户端实例
37
+ """
38
+ config = open_api_models.Config(
39
+ access_key_id=self.access_key_id,
40
+ access_key_secret=self.access_key_secret,
41
+ region_id=self.region_id,
42
+ )
43
+ config.endpoint = f"polardb.aliyuncs.com"
44
+ return polardb20170801Client(config)
45
+
46
+ def list_clusters(
47
+ self,
48
+ ) -> tuple[dict, bool]:
49
+ describe_dbclusters_request = polardb_20170801_models.DescribeDBClustersRequest(
50
+ region_id=self.region_id
51
+ )
52
+ runtime = util_models.RuntimeOptions()
53
+ try:
54
+ resp = self.client.describe_dbclusters_with_options(
55
+ describe_dbclusters_request, runtime
56
+ )
57
+ return resp.body.to_map(), True
58
+ except Exception as error:
59
+ print("error", error)
60
+ return {}, False
61
+
62
+ def list_cluster_ids(
63
+ self,
64
+ ) -> tuple[list, bool]:
65
+ """
66
+ description:
67
+ 列出PolarDB集群ID
68
+ return:
69
+ cluster_ids: 集群ID列表
70
+ success: 操作是否成功
71
+ """
72
+ try:
73
+ resp, success = self.list_clusters()
74
+ if not success:
75
+ return [], False
76
+
77
+ clusters = resp.get("Items", {}).get("DBCluster", [])
78
+ return [cluster["DBClusterId"] for cluster in clusters], True
79
+ except Exception as error:
80
+ print("error", error)
81
+ return [], False
82
+
83
+ async def list_clusters_async(
84
+ self,
85
+ ) -> tuple[dict, bool]:
86
+ describe_dbclusters_request = polardb_20170801_models.DescribeDBClustersRequest(
87
+ region_id=self.region_id
88
+ )
89
+ runtime = util_models.RuntimeOptions()
90
+ try:
91
+ resp = await self.client.describe_dbclusters_with_options_async(
92
+ describe_dbclusters_request, runtime
93
+ )
94
+ return resp.body.to_map(), True
95
+ except Exception as error:
96
+ print("error", error)
97
+ return {}, False
98
+
99
+ async def list_cluster_ids_async(
100
+ self,
101
+ ) -> tuple[list, bool]:
102
+ """
103
+ description:
104
+ 列出PolarDB集群ID
105
+ return:
106
+ cluster_ids: 集群ID列表
107
+ success: 操作是否成功
108
+ """
109
+ try:
110
+ resp, success = await self.list_clusters_async()
111
+ if not success:
112
+ return [], False
113
+ clusters = resp.get("Items", {}).get("DBCluster", [])
114
+ return [cluster["DBClusterId"] for cluster in clusters], True
115
+ except Exception as error:
116
+ print("error", error)
117
+ return [], False
118
+
119
+ def list_character_set_names(
120
+ self,
121
+ cluster_id: str,
122
+ ) -> tuple[list, bool]:
123
+ """
124
+ description:
125
+ 列出PolarDB字符集名称
126
+ parameters:
127
+ cluster_id(str): 集群ID
128
+ return:
129
+ character_set_names: 字符集名称列表
130
+ success: 操作是否成功
131
+ """
132
+ describe_character_set_name_request = (
133
+ polardb_20170801_models.DescribeCharacterSetNameRequest(
134
+ region_id=self.region_id, dbcluster_id=cluster_id
135
+ )
136
+ )
137
+ runtime = util_models.RuntimeOptions()
138
+ try:
139
+ resp = self.client.describe_character_set_name_with_options(
140
+ describe_character_set_name_request, runtime
141
+ )
142
+ return (
143
+ resp.body.to_map()
144
+ .get("CharacterSetNameItems", {})
145
+ .get("CharacterSetName", []),
146
+ True,
147
+ )
148
+ except Exception as error:
149
+ print("error", error)
150
+ return [], False
151
+
152
+ async def list_character_set_names_async(
153
+ self,
154
+ cluster_id: str,
155
+ ) -> tuple[list, bool]:
156
+ """
157
+ description:
158
+ 异步列出PolarDB字符集名称
159
+ parameters:
160
+ cluster_id(str): 集群ID
161
+ return:
162
+ character_set_names: 字符集名称列表
163
+ success: 操作是否成功
164
+ """
165
+ describe_character_set_name_request = (
166
+ polardb_20170801_models.DescribeCharacterSetNameRequest(
167
+ region_id=self.region_id, dbcluster_id=cluster_id
168
+ )
169
+ )
170
+ runtime = util_models.RuntimeOptions()
171
+ try:
172
+ resp = await self.client.describe_character_set_name_with_options_async(
173
+ describe_character_set_name_request, runtime
174
+ )
175
+ return (
176
+ resp.body.to_map()
177
+ .get("CharacterSetNameItems", {})
178
+ .get("CharacterSetName", []),
179
+ True,
180
+ )
181
+ except Exception as error:
182
+ print("error", error)
183
+ return [], False
184
+
185
+ def create_database(
186
+ self,
187
+ cluster_id: str,
188
+ database_name: str,
189
+ character_set_name: str = "utf8mb4",
190
+ ) -> bool:
191
+ """
192
+ description:
193
+ 创建PolarDB数据库
194
+ parameters:
195
+ cluster_id(str): 集群ID
196
+ database_name(str): 数据库名称
197
+ character_set_name(str): 字符集名称
198
+ return:
199
+ bool: 创建结果
200
+ """
201
+ create_database_request = polardb_20170801_models.CreateDatabaseRequest(
202
+ character_set_name=character_set_name,
203
+ dbcluster_id=cluster_id,
204
+ dbname=database_name,
205
+ )
206
+ runtime = util_models.RuntimeOptions()
207
+ try:
208
+ resp = self.client.create_database_with_options(
209
+ create_database_request, runtime
210
+ )
211
+ return True if resp.body.to_map().get("RequestId") else False
212
+ except Exception as error:
213
+ print("error", error)
214
+ return False
215
+
216
+ async def create_database_async(
217
+ self,
218
+ cluster_id: str,
219
+ database_name: str,
220
+ character_set_name: str = "utf8mb4",
221
+ ) -> bool:
222
+ """
223
+ description:
224
+ 异步创建PolarDB数据库
225
+ parameters:
226
+ cluster_id(str): 集群ID
227
+ database_name(str): 数据库名称
228
+ character_set_name(str): 字符集名称
229
+ return:
230
+ bool: 创建结果
231
+ """
232
+ create_database_request = polardb_20170801_models.CreateDatabaseRequest(
233
+ character_set_name=character_set_name,
234
+ dbcluster_id=cluster_id,
235
+ dbname=database_name,
236
+ )
237
+ runtime = util_models.RuntimeOptions()
238
+ try:
239
+ resp = await self.client.create_database_with_options_async(
240
+ create_database_request, runtime
241
+ )
242
+ return True if resp.body.to_map().get("RequestId") else False
243
+ except Exception as error:
244
+ print("error", error)
245
+ return False
246
+
247
+ def delete_database(
248
+ self,
249
+ cluster_id: str,
250
+ database_name: str,
251
+ ) -> bool:
252
+ """
253
+ description:
254
+ 删除PolarDB数据库
255
+ parameters:
256
+ cluster_id(str): 集群ID
257
+ database_name(str): 数据库名称
258
+ return:
259
+ bool: 删除结果
260
+ """
261
+ delete_database_request = polardb_20170801_models.DeleteDatabaseRequest(
262
+ dbcluster_id=cluster_id,
263
+ dbname=database_name,
264
+ )
265
+ runtime = util_models.RuntimeOptions()
266
+ try:
267
+ resp = self.client.delete_database_with_options(
268
+ delete_database_request, runtime
269
+ )
270
+ return True if resp.body.to_map().get("RequestId") else False
271
+ except Exception as error:
272
+ return False
273
+
274
+ async def delete_database_async(
275
+ self,
276
+ cluster_id: str,
277
+ database_name: str,
278
+ ) -> bool:
279
+ """
280
+ description:
281
+ 异步删除PolarDB数据库
282
+ parameters:
283
+ cluster_id(str): 集群ID
284
+ database_name(str): 数据库名称
285
+ return:
286
+ bool: 删除结果
287
+ """
288
+ delete_database_request = polardb_20170801_models.DeleteDatabaseRequest(
289
+ dbcluster_id=cluster_id,
290
+ dbname=database_name,
291
+ )
292
+ runtime = util_models.RuntimeOptions()
293
+ try:
294
+ resp = await self.client.delete_database_with_options_async(
295
+ delete_database_request, runtime
296
+ )
297
+ return True if resp.body.to_map().get("RequestId") else False
298
+ except Exception as error:
299
+ print("error", error)
300
+ return False
301
+
302
+ def list_databases(
303
+ self,
304
+ cluster_id: str,
305
+ ) -> tuple[list, bool]:
306
+ """
307
+ description:
308
+ 列出PolarDB数据库
309
+ parameters:
310
+ cluster_id(str): 集群ID
311
+ return:
312
+ databases: 数据库列表
313
+ success: 操作是否成功
314
+ """
315
+ describe_databases_request = polardb_20170801_models.DescribeDatabasesRequest(
316
+ dbcluster_id=cluster_id
317
+ )
318
+ runtime = util_models.RuntimeOptions()
319
+ try:
320
+ resp = self.client.describe_databases_with_options(
321
+ describe_databases_request, runtime
322
+ )
323
+ return resp.body.to_map(), True
324
+ except Exception as error:
325
+ print("error", error)
326
+ return [], False
327
+
328
+ async def list_databases_async(
329
+ self,
330
+ cluster_id: str,
331
+ ) -> tuple[list, bool]:
332
+ """
333
+ description:
334
+ 异步列出PolarDB数据库
335
+ parameters:
336
+ cluster_id(str): 集群ID
337
+ return:
338
+ databases: 数据库列表
339
+ success: 操作是否成功
340
+ """
341
+ describe_databases_request = polardb_20170801_models.DescribeDatabasesRequest(
342
+ dbcluster_id=cluster_id
343
+ )
344
+ runtime = util_models.RuntimeOptions()
345
+ try:
346
+ resp = await self.client.describe_databases_with_options_async(
347
+ describe_databases_request, runtime
348
+ )
349
+ return resp.body.to_map(), True
350
+ except Exception as error:
351
+ print("error", error)
352
+ return [], False
353
+
354
+ def list_database_names(
355
+ self,
356
+ cluster_id: str,
357
+ ) -> tuple[list, bool]:
358
+ """
359
+ description:
360
+ 列出PolarDB数据库名称
361
+ parameters:
362
+ cluster_id(str): 集群ID
363
+ return:
364
+ database_names: 数据库名称列表
365
+ success: 操作是否成功
366
+ """
367
+ try:
368
+ resp, success = self.list_databases(cluster_id)
369
+ if not success:
370
+ return [], False
371
+
372
+ return [
373
+ database["DBName"]
374
+ for database in resp.get("Databases", {}).get("Database", [])
375
+ ], True
376
+ except Exception as error:
377
+ print("error", error)
378
+ return [], False
379
+
380
+ async def list_database_names_async(
381
+ self,
382
+ cluster_id: str,
383
+ ) -> tuple[list, bool]:
384
+ """
385
+ description:
386
+ 异步列出PolarDB数据库名称
387
+ parameters:
388
+ cluster_id(str): 集群ID
389
+ return:
390
+ database_names: 数据库名称列表
391
+ success: 操作是否成功
392
+ """
393
+ try:
394
+ resp, success = await self.list_databases_async(cluster_id)
395
+ if not success:
396
+ return [], False
397
+
398
+ return [
399
+ database["DBName"]
400
+ for database in resp.get("Databases", {}).get("Database", [])
401
+ ], True
402
+ except Exception as error:
403
+ print("error", error)
404
+ return [], False
405
+
406
+ def list_accounts(
407
+ self,
408
+ cluster_id: str,
409
+ account_name: str = None,
410
+ ) -> tuple[list, bool]:
411
+ """
412
+ description:
413
+ 列出PolarDB账号
414
+ parameters:
415
+ cluster_id(str): 集群ID
416
+ account_name(str): 账号名称
417
+ return:
418
+ accounts: 账号列表
419
+ success: 操作是否成功
420
+ """
421
+ describe_accounts_request = polardb_20170801_models.DescribeAccountsRequest(
422
+ dbcluster_id=cluster_id,
423
+ account_name=account_name,
424
+ )
425
+ runtime = util_models.RuntimeOptions()
426
+ try:
427
+ resp = self.client.describe_accounts_with_options(
428
+ describe_accounts_request, runtime
429
+ )
430
+ return resp.body.to_map(), True
431
+ except Exception as error:
432
+ return [], False
433
+
434
+ async def list_accounts_async(
435
+ self,
436
+ cluster_id: str,
437
+ account_name: str = None,
438
+ ) -> tuple[list, bool]:
439
+ """
440
+ description:
441
+ 异步列出PolarDB账号
442
+ parameters:
443
+ cluster_id(str): 集群ID
444
+ account_name(str): 账号名称
445
+ return:
446
+ accounts: 账号列表
447
+ success: 操作是否成功
448
+ """
449
+ describe_accounts_request = polardb_20170801_models.DescribeAccountsRequest(
450
+ dbcluster_id=cluster_id,
451
+ account_name=account_name,
452
+ )
453
+ runtime = util_models.RuntimeOptions()
454
+ try:
455
+ resp = await self.client.describe_accounts_with_options_async(
456
+ describe_accounts_request, runtime
457
+ )
458
+ return resp.body.to_map(), True
459
+ except Exception as error:
460
+ return [], False
461
+
462
+ def list_account_names(
463
+ self,
464
+ cluster_id: str,
465
+ ) -> tuple[list, bool]:
466
+ """
467
+ description:
468
+ 列出PolarDB账号名称
469
+ parameters:
470
+ cluster_id(str): 集群ID
471
+ return:
472
+ account_names: 账号名称列表
473
+ success: 操作是否成功
474
+ """
475
+ try:
476
+ resp, success = self.list_accounts(cluster_id)
477
+ if not success:
478
+ return [], False
479
+
480
+ return [
481
+ account["AccountName"] for account in resp.get("Accounts", [])
482
+ ], True
483
+ except Exception as error:
484
+ return [], False
485
+
486
+ async def list_account_names_async(
487
+ self,
488
+ cluster_id: str,
489
+ ) -> tuple[list, bool]:
490
+ """
491
+ description:
492
+ 异步列出PolarDB账号名称
493
+ parameters:
494
+ cluster_id(str): 集群ID
495
+ return:
496
+ account_names: 账号名称列表
497
+ success: 操作是否成功
498
+ """
499
+ try:
500
+ resp, success = await self.list_accounts_async(cluster_id)
501
+ if not success:
502
+ return [], False
503
+
504
+ return [
505
+ account["AccountName"] for account in resp.get("Accounts", [])
506
+ ], True
507
+ except Exception as error:
508
+ return [], False
509
+
510
+ def create_account(
511
+ self,
512
+ cluster_id: str,
513
+ account_name: str,
514
+ account_password: str,
515
+ account_type: str = "Normal",
516
+ ) -> bool:
517
+ """
518
+ description:
519
+ 创建PolarDB账号
520
+ parameters:
521
+ cluster_id(str): 集群ID
522
+ account_name(str): 账号名称
523
+ account_password(str): 账号密码
524
+ account_type(str): 账号类型
525
+ return:
526
+ bool: 创建结果
527
+ """
528
+ create_account_request = polardb_20170801_models.CreateAccountRequest(
529
+ dbcluster_id=cluster_id,
530
+ account_name=account_name,
531
+ account_password=account_password,
532
+ account_type=account_type,
533
+ )
534
+ runtime = util_models.RuntimeOptions()
535
+ try:
536
+ resp = self.client.create_account_with_options(
537
+ create_account_request, runtime
538
+ )
539
+ return True if resp.body.to_map().get("RequestId") else False
540
+ except Exception as error:
541
+ print("error", error)
542
+ return False
543
+
544
+ async def create_account_async(
545
+ self,
546
+ cluster_id: str,
547
+ account_name: str,
548
+ account_password: str,
549
+ account_type: str = "Normal",
550
+ ) -> bool:
551
+ """
552
+ description:
553
+ 异步创建PolarDB账号
554
+ parameters:
555
+ cluster_id(str): 集群ID
556
+ account_name(str): 账号名称
557
+ account_password(str): 账号密码
558
+ account_type(str): 账号类型
559
+ return:
560
+ bool: 创建结果
561
+ """
562
+ create_account_request = polardb_20170801_models.CreateAccountRequest(
563
+ dbcluster_id=cluster_id,
564
+ account_name=account_name,
565
+ account_password=account_password,
566
+ account_type=account_type,
567
+ )
568
+ runtime = util_models.RuntimeOptions()
569
+ try:
570
+ resp = await self.client.create_account_with_options_async(
571
+ create_account_request, runtime
572
+ )
573
+ return True if resp.body.to_map().get("RequestId") else False
574
+ except Exception as error:
575
+ print("error", error)
576
+ return False
577
+
578
+ def delete_account(
579
+ self,
580
+ cluster_id: str,
581
+ account_name: str,
582
+ ) -> bool:
583
+ """
584
+ description:
585
+ 删除PolarDB账号
586
+ parameters:
587
+ cluster_id(str): 集群ID
588
+ account_name(str): 账号名称
589
+ return:
590
+ bool: 删除结果
591
+ """
592
+ delete_account_request = polardb_20170801_models.DeleteAccountRequest(
593
+ dbcluster_id=cluster_id,
594
+ account_name=account_name,
595
+ )
596
+ runtime = util_models.RuntimeOptions()
597
+ try:
598
+ resp = self.client.delete_account_with_options(
599
+ delete_account_request, runtime
600
+ )
601
+ return True if resp.body.to_map().get("RequestId") else False
602
+ except Exception as error:
603
+ return False
604
+
605
+ async def delete_account_async(
606
+ self,
607
+ cluster_id: str,
608
+ account_name: str,
609
+ ) -> bool:
610
+ """
611
+ description:
612
+ 异步删除PolarDB账号
613
+ parameters:
614
+ cluster_id(str): 集群ID
615
+ account_name(str): 账号名称
616
+ return:
617
+ bool: 删除结果
618
+ """
619
+ delete_account_request = polardb_20170801_models.DeleteAccountRequest(
620
+ dbcluster_id=cluster_id,
621
+ account_name=account_name,
622
+ )
623
+ runtime = util_models.RuntimeOptions()
624
+ try:
625
+ resp = await self.client.delete_account_with_options_async(
626
+ delete_account_request, runtime
627
+ )
628
+ return True if resp.body.to_map().get("RequestId") else False
629
+ except Exception as error:
630
+ return False
631
+
632
+ def modify_account_password(
633
+ self,
634
+ cluster_id: str,
635
+ account_name: str,
636
+ new_account_password: str,
637
+ ) -> bool:
638
+ """
639
+ description:
640
+ 修改PolarDB账号密码
641
+ parameters:
642
+ cluster_id(str): 集群ID
643
+ account_name(str): 账号名称
644
+ new_account_password(str): 新账号密码
645
+ return:
646
+ bool: 修改结果
647
+ """
648
+ modify_account_password_request = (
649
+ polardb_20170801_models.ModifyAccountPasswordRequest(
650
+ dbcluster_id=cluster_id,
651
+ account_name=account_name,
652
+ new_account_password=new_account_password,
653
+ )
654
+ )
655
+ runtime = util_models.RuntimeOptions()
656
+ try:
657
+ resp = self.client.modify_account_password_with_options(
658
+ modify_account_password_request, runtime
659
+ )
660
+ return True if resp.body.to_map().get("RequestId") else False
661
+ except Exception as error:
662
+ print("error", error)
663
+ return False
664
+
665
+ async def modify_account_password_async(
666
+ self,
667
+ cluster_id: str,
668
+ account_name: str,
669
+ new_account_password: str,
670
+ ) -> bool:
671
+ """
672
+ description:
673
+ 异步修改PolarDB账号密码
674
+ parameters:
675
+ cluster_id(str): 集群ID
676
+ account_name(str): 账号名称
677
+ new_account_password(str): 新账号密码
678
+ return:
679
+ bool: 修改结果
680
+ """
681
+ modify_account_password_request = (
682
+ polardb_20170801_models.ModifyAccountPasswordRequest(
683
+ dbcluster_id=cluster_id,
684
+ account_name=account_name,
685
+ new_account_password=new_account_password,
686
+ )
687
+ )
688
+ runtime = util_models.RuntimeOptions()
689
+ try:
690
+ resp = await self.client.modify_account_password_with_options_async(
691
+ modify_account_password_request, runtime
692
+ )
693
+ return True if resp.body.to_map().get("RequestId") else False
694
+ except Exception as error:
695
+ print("error", error)
696
+ return False
697
+
698
+ def grant_account_privilege(
699
+ self,
700
+ cluster_id: str,
701
+ account_name: str,
702
+ database_name: str,
703
+ account_privilege: str = "ReadWrite",
704
+ ) -> bool:
705
+ """
706
+ description:
707
+ 授予PolarDB账号权限
708
+ parameters:
709
+ cluster_id(str): 集群ID
710
+ account_name(str): 账号名称
711
+ database_name(str): 数据库名称
712
+ account_privilege(str): 账号权限
713
+ return:
714
+ bool: 授予结果
715
+ """
716
+ grant_account_privilege_request = (
717
+ polardb_20170801_models.GrantAccountPrivilegeRequest(
718
+ account_privilege=account_privilege,
719
+ dbname=database_name,
720
+ account_name=account_name,
721
+ dbcluster_id=cluster_id,
722
+ )
723
+ )
724
+ runtime = util_models.RuntimeOptions()
725
+ try:
726
+ resp = self.client.grant_account_privilege_with_options(
727
+ grant_account_privilege_request, runtime
728
+ )
729
+ return True if resp.body.to_map().get("RequestId") else False
730
+ except Exception as error:
731
+ print("error", error)
732
+ return False
733
+
734
+ async def grant_account_privilege_async(
735
+ self,
736
+ cluster_id: str,
737
+ account_name: str,
738
+ database_name: str,
739
+ account_privilege: str = "ReadWrite",
740
+ ) -> bool:
741
+ """
742
+ description:
743
+ 异步授予PolarDB账号权限
744
+ parameters:
745
+ cluster_id(str): 集群ID
746
+ account_name(str): 账号名称
747
+ database_name(str): 数据库名称
748
+ account_privilege(str): 账号权限
749
+ return:
750
+ bool: 授予结果
751
+ """
752
+ grant_account_privilege_request = (
753
+ polardb_20170801_models.GrantAccountPrivilegeRequest(
754
+ account_privilege=account_privilege,
755
+ dbname=database_name,
756
+ account_name=account_name,
757
+ dbcluster_id=cluster_id,
758
+ )
759
+ )
760
+ runtime = util_models.RuntimeOptions()
761
+ try:
762
+ resp = await self.client.grant_account_privilege_with_options_async(
763
+ grant_account_privilege_request, runtime
764
+ )
765
+ return True if resp.body.to_map().get("RequestId") else False
766
+ except Exception as error:
767
+ print("error", error)
768
+ return False
769
+
770
+ def revoke_account_privilege(
771
+ self,
772
+ cluster_id: str,
773
+ account_name: str,
774
+ database_name: str,
775
+ ) -> bool:
776
+ """
777
+ description:
778
+ 撤销PolarDB账号权限
779
+ parameters:
780
+ cluster_id(str): 集群ID
781
+ account_name(str): 账号名称
782
+ database_name(str): 数据库名称
783
+ return:
784
+ bool: 撤销结果
785
+ """
786
+ revoke_account_privilege_request = (
787
+ polardb_20170801_models.RevokeAccountPrivilegeRequest(
788
+ dbcluster_id=cluster_id,
789
+ account_name=account_name,
790
+ dbname=database_name,
791
+ )
792
+ )
793
+ runtime = util_models.RuntimeOptions()
794
+ try:
795
+ resp = self.client.revoke_account_privilege_with_options(
796
+ revoke_account_privilege_request, runtime
797
+ )
798
+ return True if resp.body.to_map().get("RequestId") else False
799
+ except Exception as error:
800
+ print("error", error)
801
+ return False
802
+
803
+ async def revoke_account_privilege_async(
804
+ self,
805
+ cluster_id: str,
806
+ account_name: str,
807
+ database_name: str,
808
+ ) -> bool:
809
+ """
810
+ description:
811
+ 异步撤销PolarDB账号权限
812
+ parameters:
813
+ cluster_id(str): 集群ID
814
+ account_name(str): 账号名称
815
+ database_name(str): 数据库名称
816
+ return:
817
+ bool: 撤销结果
818
+ """
819
+ revoke_account_privilege_request = (
820
+ polardb_20170801_models.RevokeAccountPrivilegeRequest(
821
+ dbcluster_id=cluster_id,
822
+ account_name=account_name,
823
+ dbname=database_name,
824
+ )
825
+ )
826
+ runtime = util_models.RuntimeOptions()
827
+ try:
828
+ resp = await self.client.revoke_account_privilege_with_options_async(
829
+ revoke_account_privilege_request, runtime
830
+ )
831
+ return True if resp.body.to_map().get("RequestId") else False
832
+ except Exception as error:
833
+ print("error", error)
834
+ return False
835
+
836
+ def list_account_privileges(
837
+ self,
838
+ cluster_id: str,
839
+ account_name: str,
840
+ ) -> tuple[list, bool]:
841
+ """
842
+ description:
843
+ 列出PolarDB账号权限
844
+ parameters:
845
+ cluster_id(str): 集群ID
846
+ account_name(str): 账号名称
847
+ return:
848
+ list: 账号权限列表
849
+ success: 操作是否成功
850
+ """
851
+ resp, success = self.list_accounts(cluster_id, account_name)
852
+ if not success:
853
+ return [], False
854
+
855
+ database_privileges = resp.get("Accounts", [])[0].get("DatabasePrivileges", [])
856
+ database_privileges = [
857
+ {
858
+ "database_name": privilege.get("DBName"),
859
+ "account_privilege": privilege.get("AccountPrivilege"),
860
+ }
861
+ for privilege in database_privileges
862
+ ]
863
+ return database_privileges, True
864
+
865
+ async def list_account_privileges_async(
866
+ self,
867
+ cluster_id: str,
868
+ account_name: str,
869
+ ) -> tuple[list, bool]:
870
+ """
871
+ description:
872
+ 异步列出PolarDB账号权限
873
+ parameters:
874
+ cluster_id(str): 集群ID
875
+ account_name(str): 账号名称
876
+ return:
877
+ list: 账号权限列表
878
+ success: 操作是否成功
879
+ """
880
+ resp, success = await self.list_accounts_async(cluster_id, account_name)
881
+ if not success:
882
+ return [], False
883
+
884
+ database_privileges = resp.get("Accounts", [])[0].get("DatabasePrivileges", [])
885
+ database_privileges = [
886
+ {
887
+ "database_name": privilege.get("DBName"),
888
+ "account_privilege": privilege.get("AccountPrivilege"),
889
+ }
890
+ for privilege in database_privileges
891
+ ]
892
+ return database_privileges, True
893
+
894
+ def create_account_and_grant_privilege(
895
+ self,
896
+ cluster_id: str,
897
+ account_name: str,
898
+ account_password: str,
899
+ database_name: str,
900
+ account_privilege: str = "ReadWrite",
901
+ ) -> bool:
902
+ """
903
+ description:
904
+ 创建PolarDB账号并授予权限
905
+ parameters:
906
+ cluster_id(str): 集群ID
907
+ account_name(str): 账号名称
908
+ account_password(str): 账号密码
909
+ database_name(str): 数据库名称
910
+ account_privilege(str): 账号权限
911
+ return:
912
+ bool: 创建结果
913
+ """
914
+ resp, success = self.create_account(cluster_id, account_name, account_password)
915
+ if not success:
916
+ return False
917
+ success = self.grant_account_privilege(
918
+ cluster_id, account_name, database_name, account_privilege
919
+ )
920
+ return success
921
+
922
+ async def create_account_and_grant_privilege_async(
923
+ self,
924
+ cluster_id: str,
925
+ account_name: str,
926
+ account_password: str,
927
+ database_name: str,
928
+ account_privilege: str = "ReadWrite",
929
+ ) -> bool:
930
+ """
931
+ description:
932
+ 异步创建PolarDB账号并授予权限
933
+ parameters:
934
+ cluster_id(str): 集群ID
935
+ account_name(str): 账号名称
936
+ account_password(str): 账号密码
937
+ database_name(str): 数据库名称
938
+ account_privilege(str): 账号权限
939
+ return:
940
+ bool: 创建结果
941
+ """
942
+ success = await self.create_account_async(
943
+ cluster_id, account_name, account_password
944
+ )
945
+ if not success:
946
+ return False
947
+ success = await self.grant_account_privilege_async(
948
+ cluster_id, account_name, database_name, account_privilege
949
+ )
950
+ return success
@@ -3,7 +3,7 @@ PixelArrayLib 脚本工具包
3
3
  包含各种实用的命令行工具和脚本
4
4
  """
5
5
 
6
- __version__ = "1.1.8"
6
+ __version__ = "1.2.0"
7
7
  __author__ = "Lu qi"
8
8
 
9
9
  # 导出主要的脚本函数
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraylib
3
- Version: 1.1.8
3
+ Version: 1.2.0
4
4
  Summary: PixelArray Python开发工具库 - 包含阿里云服务、数据库工具、装饰器、监控等功能
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -111,6 +111,12 @@ Requires-Dist: alibabacloud_tea_util; extra == "aliyun-fc"
111
111
  Requires-Dist: requests; extra == "aliyun-fc"
112
112
  Requires-Dist: cryptography; extra == "aliyun-fc"
113
113
  Requires-Dist: paramiko; extra == "aliyun-fc"
114
+ Provides-Extra: aliyun-polardb
115
+ Requires-Dist: alibabacloud_polardb20170801; extra == "aliyun-polardb"
116
+ Requires-Dist: alibabacloud_credentials; extra == "aliyun-polardb"
117
+ Requires-Dist: alibabacloud_tea_openapi; extra == "aliyun-polardb"
118
+ Requires-Dist: alibabacloud_tea_util; extra == "aliyun-polardb"
119
+ Requires-Dist: requests; extra == "aliyun-polardb"
114
120
  Provides-Extra: aliyun
115
121
  Requires-Dist: alibabacloud_tea_util; extra == "aliyun"
116
122
  Requires-Dist: alibabacloud_cms20190101; extra == "aliyun"
@@ -151,6 +157,7 @@ Requires-Dist: alibabacloud_cr20181201; extra == "all"
151
157
  Requires-Dist: alibabacloud_vpc20160428; extra == "all"
152
158
  Requires-Dist: alibabacloud_tea_openapi; extra == "all"
153
159
  Requires-Dist: alibabacloud_credentials; extra == "all"
160
+ Requires-Dist: alibabacloud_polardb20170801; extra == "all"
154
161
  Requires-Dist: oss2; extra == "all"
155
162
  Requires-Dist: pymysql; extra == "all"
156
163
  Requires-Dist: aiomysql; extra == "all"
@@ -22,6 +22,7 @@ pixelarraylib/aliyun/ecs.py
22
22
  pixelarraylib/aliyun/eip.py
23
23
  pixelarraylib/aliyun/fc.py
24
24
  pixelarraylib/aliyun/oss.py
25
+ pixelarraylib/aliyun/polardb.py
25
26
  pixelarraylib/aliyun/sms.py
26
27
  pixelarraylib/aliyun/sts.py
27
28
  pixelarraylib/db_utils/mysql.py
@@ -90,6 +90,13 @@ requests
90
90
  cryptography
91
91
  paramiko
92
92
 
93
+ [aliyun-polardb]
94
+ alibabacloud_polardb20170801
95
+ alibabacloud_credentials
96
+ alibabacloud_tea_openapi
97
+ alibabacloud_tea_util
98
+ requests
99
+
93
100
  [aliyun-sms]
94
101
  alibabacloud_dysmsapi20170525
95
102
  alibabacloud_tea_openapi
@@ -120,6 +127,7 @@ alibabacloud_cr20181201
120
127
  alibabacloud_vpc20160428
121
128
  alibabacloud_tea_openapi
122
129
  alibabacloud_credentials
130
+ alibabacloud_polardb20170801
123
131
  oss2
124
132
  pymysql
125
133
  aiomysql
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pixelarraylib"
7
- version = "1.1.8"
7
+ version = "1.2.0"
8
8
  authors = [
9
9
  {name = "Lu qi", email = "qi.lu@pixelarrayai.com"},
10
10
  ]
@@ -141,6 +141,13 @@ aliyun-fc = [
141
141
  "cryptography",
142
142
  "paramiko",
143
143
  ]
144
+ aliyun-polardb = [
145
+ "alibabacloud_polardb20170801",
146
+ "alibabacloud_credentials",
147
+ "alibabacloud_tea_openapi",
148
+ "alibabacloud_tea_util",
149
+ "requests",
150
+ ]
144
151
 
145
152
  # 阿里云服务完整依赖(包含所有子模块)
146
153
  aliyun = [
@@ -184,6 +191,7 @@ all = [
184
191
  "alibabacloud_vpc20160428",
185
192
  "alibabacloud_tea_openapi",
186
193
  "alibabacloud_credentials",
194
+ "alibabacloud_polardb20170801",
187
195
  "oss2",
188
196
  "pymysql",
189
197
  "aiomysql",
@@ -11,6 +11,7 @@ alibabacloud_eci20180808
11
11
  alibabacloud_bssopenapi20171214
12
12
  alibabacloud_cr20181201
13
13
  alibabacloud_vpc20160428
14
+ alibabacloud_polardb20170801
14
15
  oss2
15
16
  pymysql
16
17
  aiomysql
File without changes
File without changes
File without changes
File without changes