cgcsdk 1.0.7__py3-none-any.whl → 1.0.10__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.
- cgc/.env +1 -1
- cgc/CHANGELOG.md +29 -0
- cgc/cgc.py +4 -0
- cgc/commands/auth/__init__.py +2 -2
- cgc/commands/auth/auth_cmd.py +14 -2
- cgc/commands/auth/auth_responses.py +9 -2
- cgc/commands/auth/auth_utils.py +6 -5
- cgc/commands/cgc_models.py +9 -0
- cgc/commands/compute/compute_cmd.py +1 -1
- cgc/commands/compute/compute_models.py +1 -23
- cgc/commands/compute/compute_responses.py +1 -1
- cgc/commands/db/db_cmd.py +8 -2
- cgc/commands/db/db_models.py +37 -0
- cgc/commands/exceptions.py +8 -0
- cgc/commands/jobs/job_utils.py +37 -32
- cgc/commands/jobs/jobs_responses.py +1 -1
- cgc/commands/resource/resource_cmd.py +3 -2
- cgc/commands/user/__init__.py +14 -0
- cgc/commands/user/keys_cmd.py +179 -0
- cgc/commands/user/keys_models.py +16 -0
- cgc/commands/user/keys_responses.py +44 -0
- cgc/commands/user/keys_utils.py +79 -0
- cgc/commands/user/secret_cmd.py +154 -0
- cgc/commands/user/secret_responses.py +44 -0
- cgc/commands/user/secret_utils.py +60 -0
- cgc/sdk/__init__.py +0 -2
- cgc/sdk/job.py +1 -1
- cgc/sdk/resource.py +6 -6
- cgc/tests/responses_tests.py +1 -1
- cgc/utils/__init__.py +8 -0
- cgc/utils/config_utils.py +5 -1
- cgc/utils/consts/env_consts.py +1 -1
- cgc/utils/custom_exceptions.py +3 -0
- cgc/utils/message_utils.py +1 -1
- cgc/utils/prepare_headers.py +22 -13
- cgc/utils/requests_helper.py +2 -2
- cgcsdk-1.0.10.dist-info/LICENSE +0 -0
- {cgcsdk-1.0.7.dist-info → cgcsdk-1.0.10.dist-info}/METADATA +3 -7
- {cgcsdk-1.0.7.dist-info → cgcsdk-1.0.10.dist-info}/RECORD +44 -36
- cgc/sdk/handlers.py +0 -24
- cgc/sdk/mongodb.py +0 -204
- cgc/sdk/redis.py +0 -91
- /cgc/commands/compute/{compute_utills.py → compute_utils.py} +0 -0
- /cgcsdk-1.0.7.dist-info/LICENSE → /cgc/commands/user/secret_models.py +0 -0
- {cgcsdk-1.0.7.dist-info → cgcsdk-1.0.10.dist-info}/WHEEL +0 -0
- {cgcsdk-1.0.7.dist-info → cgcsdk-1.0.10.dist-info}/entry_points.txt +0 -0
- {cgcsdk-1.0.7.dist-info → cgcsdk-1.0.10.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: cgcsdk
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.10
|
4
4
|
Summary: Comtegra GPU Cloud REST API client
|
5
5
|
Author: Comtegra AI Team
|
6
6
|
Author-email: ai@comtegra.pl
|
@@ -30,8 +30,6 @@ Requires-Dist: statsd
|
|
30
30
|
Requires-Dist: requests
|
31
31
|
Requires-Dist: setuptools
|
32
32
|
Requires-Dist: colorama
|
33
|
-
Requires-Dist: redis
|
34
|
-
Requires-Dist: pymongo
|
35
33
|
Requires-Dist: psycopg2-binary
|
36
34
|
|
37
35
|
# Comtegra GPU Cloud CLI Client
|
@@ -54,10 +52,8 @@ For now, we provide the ability to spawn compute resources like:
|
|
54
52
|
Notebooks are equiped with all CUDA libraries and GPU drivers which enables the usage of GPU for accelerated computations.
|
55
53
|
Apart from compute resources, we provide the database engines accessible from within your namespace:
|
56
54
|
|
57
|
-
1. [
|
58
|
-
2. [
|
59
|
-
3. [Redis](https://redis.io/)
|
60
|
-
4. [Weaviate](https://weaviate.io/)
|
55
|
+
1. [PostgreSQL](https://www.postgresql.org/)
|
56
|
+
2. [Weaviate](https://weaviate.io/)
|
61
57
|
|
62
58
|
More are coming!
|
63
59
|
Please follow instructions to get started.
|
@@ -1,54 +1,62 @@
|
|
1
|
-
cgc/.env,sha256=
|
2
|
-
cgc/CHANGELOG.md,sha256=
|
1
|
+
cgc/.env,sha256=I-5qrmy3GL9dhkX_k4UN59twXdPL_Tu_Emwf-ZU6-hg,210
|
2
|
+
cgc/CHANGELOG.md,sha256=3eTeQjVZkrfGb5Ld-YUIfM9dios7vOZp3cc2xVILfFQ,8532
|
3
3
|
cgc/__init__.py,sha256=d03Xv8Pw4ktNyUHfmicP6XfxYPXnVYLaCZPyUlg_RNQ,326
|
4
|
-
cgc/cgc.py,sha256=
|
4
|
+
cgc/cgc.py,sha256=SaZIGvZpA25OBx2KnQlZVjWNY2ejCyPU5KEkwqh7sh0,1655
|
5
5
|
cgc/config.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
cgc/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
cgc/commands/cgc_cmd.py,sha256=QwqjZl9FmAMOvuUQMJm-wOV88OxbdwK5UIS0zkg-mAo,4956
|
8
8
|
cgc/commands/cgc_cmd_responses.py,sha256=wO9Hf5_4jaw1ZRhQvh9Za0S_vhc22t-0_CoEGz5ndNE,2245
|
9
9
|
cgc/commands/cgc_helpers.py,sha256=ngArFjVw-8P_2g7J8k3b9xgDxfJw7JeaOtkhTySMSGU,1174
|
10
|
-
cgc/commands/
|
11
|
-
cgc/commands/
|
12
|
-
cgc/commands/auth/
|
13
|
-
cgc/commands/auth/
|
14
|
-
cgc/commands/auth/
|
10
|
+
cgc/commands/cgc_models.py,sha256=T4eCMO5AO2kZpIRqpZ7ZfgO9gxCo_MLlY33msCzrLvA,182
|
11
|
+
cgc/commands/exceptions.py,sha256=kVCWEdcqmkLO5QVIINdEXQw29_glyX2C11ZMFgT7b8E,155
|
12
|
+
cgc/commands/auth/__init__.py,sha256=JnqNezSEUEVVPQIymya4llXr8LIug2vymQSAGBr4Ovg,397
|
13
|
+
cgc/commands/auth/auth_cmd.py,sha256=FiRM16RGtP1zoJ9InbFAa-3W-EkJQbzBDxF0AmZa1JA,4196
|
14
|
+
cgc/commands/auth/auth_responses.py,sha256=oZ1aC7tyrT43imF2iMaL0u1jTJzuGLEmCN8RBeMxpf4,1959
|
15
|
+
cgc/commands/auth/auth_utils.py,sha256=-diCsKuF5UcQZoq962RuLktrG6sRmipJrDkm9Sf3wbg,5507
|
15
16
|
cgc/commands/billing/__init__.py,sha256=0arQm0R3Ouw7tXPooJsvWd_pGeHhzaVwQCbWMKQPT9A,753
|
16
17
|
cgc/commands/billing/billing_cmd.py,sha256=T1E5WW5Z-RlzddaotimTuvLvIbGihNpStIBETnlUznM,4140
|
17
18
|
cgc/commands/billing/billing_responses.py,sha256=HAD5N-Odx3Jz1OmhO4v66rHoXpTYIOGlXDsrs0da9dk,1949
|
18
19
|
cgc/commands/billing/billing_utils.py,sha256=zXLbBBcWeOgur-r0OKiIjaKeaxMNxASXWzCTeTsyC6o,4711
|
19
20
|
cgc/commands/compute/__init__.py,sha256=lCdLfZ0ECSHtXEUSwq5YRHH85yXHchSsz8ZJvmClPtI,239
|
20
|
-
cgc/commands/compute/compute_cmd.py,sha256=
|
21
|
-
cgc/commands/compute/compute_models.py,sha256=
|
22
|
-
cgc/commands/compute/compute_responses.py,sha256=
|
23
|
-
cgc/commands/compute/
|
21
|
+
cgc/commands/compute/compute_cmd.py,sha256=eXKeoOV3DsOypuxzKMa3MpITOKKbF2cZjy30iofHHG8,15489
|
22
|
+
cgc/commands/compute/compute_models.py,sha256=yse6mCEhhE2RdWIO7EHx4r5Y-350gWWy4UWFsdltNNg,778
|
23
|
+
cgc/commands/compute/compute_responses.py,sha256=DnRIZC_F1ZE887fMOXXYGYuYmB9n5x63sf8Ga_TL4Ww,5806
|
24
|
+
cgc/commands/compute/compute_utils.py,sha256=XXnd_EuF9vCmW14r0ThlN98ScKSx3KAeqFbWy2g2mlk,8812
|
24
25
|
cgc/commands/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
|
-
cgc/commands/db/db_cmd.py,sha256=
|
26
|
+
cgc/commands/db/db_cmd.py,sha256=4iamsHTy68YjrKztyRGz2PqQgo54Q_rURgm2zpp_hL8,3512
|
27
|
+
cgc/commands/db/db_models.py,sha256=oJUAF23nb_r8fSyhLHMJrRbRzLY_vpJQu6Vy4WRa0cg,1036
|
26
28
|
cgc/commands/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
27
29
|
cgc/commands/debug/debug_cmd.py,sha256=kuAuh5YOqzGFjoiYZwfM9FJ1z5OeSpC0JAIUEzS83lM,412
|
28
30
|
cgc/commands/jobs/__init__.py,sha256=E-438wgIzlnGmXs5jgmWAhJ1KNV6UXF2gz8SXu3UxA0,231
|
29
|
-
cgc/commands/jobs/job_utils.py,sha256=
|
31
|
+
cgc/commands/jobs/job_utils.py,sha256=_WffuTWYZamaXmrkRQIRmQzFsrvNbWzSwXlVLqLbmis,6194
|
30
32
|
cgc/commands/jobs/jobs_cmd.py,sha256=Q-orK6B9Zk1zAf8sOM6QqF9Eeu092P-UEg4GRA-zX-s,6555
|
31
|
-
cgc/commands/jobs/jobs_responses.py,sha256=
|
33
|
+
cgc/commands/jobs/jobs_responses.py,sha256=QXFXA4zwQOo5Gvq5rEc7J_cxxsYqkdU19X9MCcZetUM,1771
|
32
34
|
cgc/commands/resource/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
cgc/commands/resource/resource_cmd.py,sha256=
|
35
|
+
cgc/commands/resource/resource_cmd.py,sha256=y2R6ZF0jFhTppD9JUpwLIcEdFRXg82Xw_5yrNIfG4mI,4089
|
34
36
|
cgc/commands/resource/resource_responses.py,sha256=sES7mAi_Cv5B6Z3I_6eUOqVwOr2HgMO45cz8MiNZetQ,197
|
37
|
+
cgc/commands/user/__init__.py,sha256=Rhaa2SDXQsJVJnTX0oFyZ90tAuiAUBeRy3Bd415S4os,382
|
38
|
+
cgc/commands/user/keys_cmd.py,sha256=dfHnhHmEwRH1xl_wRNQcpCT-THJTBYPHMTJSI2AsDXE,4509
|
39
|
+
cgc/commands/user/keys_models.py,sha256=IYojnAu3aTGJ7qHIYvZy-0YFzXRmueZNplS4RqdfJfw,378
|
40
|
+
cgc/commands/user/keys_responses.py,sha256=TBHFWAVN1kEgP6sudbMwfpiZOcfTr0a0SD-f-Wn-ed8,1389
|
41
|
+
cgc/commands/user/keys_utils.py,sha256=w1TcMTlKJNxXjnj-XsiUU8N__-l1TsWqfPPjGpRqtI0,2285
|
42
|
+
cgc/commands/user/secret_cmd.py,sha256=_b9ewJlEE4gMCrgdyycpO5MOdJvibeHObAiPE-mWIgA,4165
|
43
|
+
cgc/commands/user/secret_models.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
|
+
cgc/commands/user/secret_responses.py,sha256=sg7HP5a0LnUvlo9w8oOcYASwI2cPeRnecjTVMa5yk7Y,1600
|
45
|
+
cgc/commands/user/secret_utils.py,sha256=70dn937rzecQ0eE-8zb9fLnBDWtjWjdQY1LJvHv3NzM,1623
|
35
46
|
cgc/commands/volume/__init__.py,sha256=Ou3kyb72aaXkrVCfQCVdniA65R2xHsRFgebooG1gflA,384
|
36
47
|
cgc/commands/volume/data_model.py,sha256=meprXdaXLo3mMTZta1ks1-BJ7G0rO16qi_ycH-sXJpY,1295
|
37
48
|
cgc/commands/volume/volume_cmd.py,sha256=5bd0vq5--Y7IfniO33tGBYH0Z67Le2s_AMTiwJcPBA4,7673
|
38
49
|
cgc/commands/volume/volume_responses.py,sha256=WefUohXxXZ9Znfc6P2XjoAM2RlA19hMKcVaW-xG9HWs,3199
|
39
50
|
cgc/commands/volume/volume_utils.py,sha256=n6s0FgpsYyxFMp_JdMRCzRi5Ar3_Svg9JDvWSdX4lhk,1919
|
40
|
-
cgc/sdk/__init__.py,sha256=
|
51
|
+
cgc/sdk/__init__.py,sha256=m8uAD2e_ADbHC4_kaOpLrUk_bHy7wC56rPjhcttclCs,177
|
41
52
|
cgc/sdk/exceptions.py,sha256=99XIzDO6LYKjex715troH-MkGUN7hi2Bit4KHfSHDis,214
|
42
|
-
cgc/sdk/
|
43
|
-
cgc/sdk/job.py,sha256=SclaqhY0rDACT_yg9e9AiYTsmXglIt6iTharwUPSAa4,5332
|
44
|
-
cgc/sdk/mongodb.py,sha256=TJ2XU7nilNRXLOIpQQPrRiVxHN2TaVM5QOSuMRtNDVs,7221
|
53
|
+
cgc/sdk/job.py,sha256=q9Vsarc3rKzurM4AOmbQDsQUVdyRqx0UzJVe_uO8xCU,5318
|
45
54
|
cgc/sdk/postgresql.py,sha256=ziXaMMwjSF3k1OAID3F9npqWVxreQaoZ8wn7X8x1FZw,1637
|
46
|
-
cgc/sdk/
|
47
|
-
cgc/sdk/resource.py,sha256=Wodt8pe15zg1uuclfV4Qxntffph70ULhNig_gOgMKz8,13544
|
55
|
+
cgc/sdk/resource.py,sha256=w8SVRqrx0Mj1FS91Bt0oaMAfC4CDEcomgqzFCNgGaPc,13537
|
48
56
|
cgc/telemetry/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
49
57
|
cgc/telemetry/basic.py,sha256=XagCcyH4QSEPmfiQ1WCjqXslnJO6IaJCY0AMPySd5rc,3175
|
50
58
|
cgc/tests/__init__.py,sha256=8aI3MVpkzaj0_UX02kZCtY5vmGO0rnq0mw2H04-OHf8,102743
|
51
|
-
cgc/tests/responses_tests.py,sha256=
|
59
|
+
cgc/tests/responses_tests.py,sha256=TtTwMZFo-nqJ-gHRmObYZsVKFdaEpT0JovMynmcxxfQ,9180
|
52
60
|
cgc/tests/desired_responses/test_billing_invoice.txt,sha256=KR5m2gamn_bgfBdBmWDH2sPRJIPOw1u8kdH-gYE8jow,1579
|
53
61
|
cgc/tests/desired_responses/test_billing_status.txt,sha256=2KSUixFOrhXI5ON6qtsIUmzFye5LBZB1xneY8ST0MqE,2381
|
54
62
|
cgc/tests/desired_responses/test_billing_stop_events_compute.txt,sha256=nHdixgLhAXDMeoDvjk9Mwv6b0JIAsW8j7Z6SS5scjSs,234
|
@@ -57,26 +65,26 @@ cgc/tests/desired_responses/test_compute_list.txt,sha256=3CDAuILJdwBmX6-GLj3zDbn
|
|
57
65
|
cgc/tests/desired_responses/test_compute_list_no_labels.txt,sha256=-OeQIaEHHsHZ81tCOI5j6VQYUMlj8VYcyyOU_DhPOpU,155
|
58
66
|
cgc/tests/desired_responses/test_tabulate_response.txt,sha256=beNyCTS9fwrHn4ueEOVk2BpOeSYZWumIa3H5EUGnW1I,789
|
59
67
|
cgc/tests/desired_responses/test_volume_list.txt,sha256=vYB1p50BBHD801q7LUdDc_aca4ezQ8CFLWw7I-b4Uao,309
|
60
|
-
cgc/utils/__init__.py,sha256=
|
68
|
+
cgc/utils/__init__.py,sha256=o3YYCh02WiAvmHw-8Hy3FJA4LjGWwPkaLTur6tEvsbE,3669
|
61
69
|
cgc/utils/click_group.py,sha256=Scfw8eMIyt2dE1ezUq2JuiI-E_LklqXQXJEr7L-EG6A,633
|
62
|
-
cgc/utils/config_utils.py,sha256=
|
63
|
-
cgc/utils/custom_exceptions.py,sha256=
|
64
|
-
cgc/utils/message_utils.py,sha256=
|
65
|
-
cgc/utils/prepare_headers.py,sha256=
|
66
|
-
cgc/utils/requests_helper.py,sha256=
|
70
|
+
cgc/utils/config_utils.py,sha256=NlPs334y6BSNGoYbFjrB5cKc9trTWIXOn8UN6O4ztNU,2884
|
71
|
+
cgc/utils/custom_exceptions.py,sha256=qvHdzaunZswZgN96iOHZIfLjehlJ79mcjqoMoW-tqEM,2628
|
72
|
+
cgc/utils/message_utils.py,sha256=FAiUC-0zJiMhfPQAQC0ki1ZUs1vI_QqHwLmfoCDbLeU,1790
|
73
|
+
cgc/utils/prepare_headers.py,sha256=67YMPogNoGbKnHQmGFc3iJCbsDZbRVjAIe3kBY-Dq98,2838
|
74
|
+
cgc/utils/requests_helper.py,sha256=qhSTfOb0o-luHLAeIuiHTOl0R_ykkdQldQZz3D6Sr6s,2062
|
67
75
|
cgc/utils/response_utils.py,sha256=9vJqAt2UFJ1n-oesFPe6CB_ooGoStjl-twY_31Jt4_I,7374
|
68
76
|
cgc/utils/update.py,sha256=AsQwhcBqsjgNPKn6AN6ojt0Ew5otvJXyshys6bjr7DQ,413
|
69
77
|
cgc/utils/version_control.py,sha256=VsqNzNYWDvU3VsoPuYIaZV7Img-K2_DmEOHd7rZlRxk,3267
|
70
78
|
cgc/utils/consts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
71
|
-
cgc/utils/consts/env_consts.py,sha256=
|
79
|
+
cgc/utils/consts/env_consts.py,sha256=8huPDBkbNEXoPHskFhYwiRi6TTw0_e9ylClpgh1NF2E,1290
|
72
80
|
cgc/utils/consts/message_consts.py,sha256=8CIe3N_HL6Pj-gSArkPkpegsvm-QMWxqqnSgtzG08Qw,1218
|
73
81
|
cgc/utils/cryptography/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
74
82
|
cgc/utils/cryptography/aes_crypto.py,sha256=S0rKg38oy7rM5lTrP6DDpjLA-XRxuZggAXyxMFHtyzY,3333
|
75
83
|
cgc/utils/cryptography/encryption_module.py,sha256=rbblBBorHYPGl-iKblyZX3_NuPEvUTpnH1l_RgNGCbA,1958
|
76
84
|
cgc/utils/cryptography/rsa_crypto.py,sha256=h3jU5qPpj9uVjP1rTqZJTdYB5yjhD9HZpr_nD439h9Q,4180
|
77
|
-
cgcsdk-1.0.
|
78
|
-
cgcsdk-1.0.
|
79
|
-
cgcsdk-1.0.
|
80
|
-
cgcsdk-1.0.
|
81
|
-
cgcsdk-1.0.
|
82
|
-
cgcsdk-1.0.
|
85
|
+
cgcsdk-1.0.10.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
86
|
+
cgcsdk-1.0.10.dist-info/METADATA,sha256=R_I_GsefZji2cCg2zbrk90fXOyWg5MDE0rWJmwiFjQU,3058
|
87
|
+
cgcsdk-1.0.10.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
88
|
+
cgcsdk-1.0.10.dist-info/entry_points.txt,sha256=bdfIHeJ6Y-BBr5yupCVoK7SUrJj1yNdew8OtIOg_3No,36
|
89
|
+
cgcsdk-1.0.10.dist-info/top_level.txt,sha256=nqW9tqcIcCXFigQT69AuOk7XHKc4pCuv4HGJQGXb6iA,12
|
90
|
+
cgcsdk-1.0.10.dist-info/RECORD,,
|
cgc/sdk/handlers.py
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
from pymongo.errors import OperationFailure, ConnectionFailure
|
2
|
-
# TODO: redis, postgres
|
3
|
-
# TODO: print -> click.echo ?
|
4
|
-
|
5
|
-
def exception_handler(func):
|
6
|
-
def inner_function(*args, **kwargs):
|
7
|
-
err_count = 0
|
8
|
-
err_limit = 3
|
9
|
-
while True and err_count < err_limit:
|
10
|
-
try:
|
11
|
-
err_count += 1
|
12
|
-
return func(*args, **kwargs)
|
13
|
-
except (ConnectionFailure,) as e:
|
14
|
-
print(f"MongoDB connection error: {e}")
|
15
|
-
print(f"retrying {err_count}/{err_limit} ...")
|
16
|
-
# args[0]._reset_connection()
|
17
|
-
except OperationFailure as e:
|
18
|
-
print(f"MongoDB OperationFailure: {e}")
|
19
|
-
raise e
|
20
|
-
else:
|
21
|
-
print(f"MongoDB exception for customer")
|
22
|
-
# TODO: HTTP EXCEPTION FOR CUSTOMER, but keep thread alive
|
23
|
-
|
24
|
-
return inner_function
|
cgc/sdk/mongodb.py
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
from pymongo.errors import ConnectionFailure
|
2
|
-
from pymongo import MongoClient, DESCENDING, ASCENDING
|
3
|
-
from cgc.sdk.handlers import exception_handler
|
4
|
-
|
5
|
-
|
6
|
-
class MongoConnector:
|
7
|
-
"""
|
8
|
-
:param database_name: Database name
|
9
|
-
:type database_name: str
|
10
|
-
:param hosts: Host address defined as IP or DNS Name with port ex. db.example.com:27017
|
11
|
-
:type hosts: list
|
12
|
-
:param username: Username used for connection, not required, defaults to None
|
13
|
-
:type username: str | None
|
14
|
-
:param password: Password for Username, used with Username, defaults to None
|
15
|
-
:type password: str | None
|
16
|
-
:param authsource: Database to authenticate user with, defaults to admin
|
17
|
-
:type authsource: str
|
18
|
-
"""
|
19
|
-
|
20
|
-
def __init__(
|
21
|
-
self,
|
22
|
-
database_name: str,
|
23
|
-
hosts: str,
|
24
|
-
username: str = None,
|
25
|
-
password: str = None,
|
26
|
-
authsource: str = "admin",
|
27
|
-
replica_set: str = None,
|
28
|
-
) -> None:
|
29
|
-
self._database_name = database_name
|
30
|
-
self._hosts = hosts
|
31
|
-
assert type(hosts) is str
|
32
|
-
'hosts must be a str of host addresses ex. "db.example.com:27017,db2.example.com:27017"'
|
33
|
-
self._username = username
|
34
|
-
self._password = password
|
35
|
-
self._authsource = authsource
|
36
|
-
_extra_args = []
|
37
|
-
if replica_set:
|
38
|
-
_extra_args.append(f"replicaSet={replica_set}")
|
39
|
-
if authsource:
|
40
|
-
_extra_args.append(f"authSource={authsource}")
|
41
|
-
_extra_args.append("readPreference=primaryPreferred")
|
42
|
-
_extra_args.append("ssl=false")
|
43
|
-
self._extra_args = "&".join(_extra_args)
|
44
|
-
print(self._extra_args)
|
45
|
-
self.connect()
|
46
|
-
|
47
|
-
def disconnect(self):
|
48
|
-
print(f"Disconnecting from MongoDB: {self._hosts}")
|
49
|
-
self._mongo_client.close()
|
50
|
-
print(f"Disconnected from MongoDB")
|
51
|
-
|
52
|
-
def connect(self):
|
53
|
-
_credentials = (
|
54
|
-
":".join([self._username, self._password]) if self._username else ""
|
55
|
-
)
|
56
|
-
_host_connection_string = (
|
57
|
-
"@".join([_credentials, self._hosts]) if _credentials else self._hosts
|
58
|
-
)
|
59
|
-
while True:
|
60
|
-
try:
|
61
|
-
self._mongo_client = MongoClient(
|
62
|
-
"mongodb://{}/{}?{}".format(
|
63
|
-
_host_connection_string, self._database_name, self._extra_args
|
64
|
-
)
|
65
|
-
)
|
66
|
-
self._mongo_client_server_info = self._mongo_client.server_info()
|
67
|
-
print(f"Connected to MongoDB ({self._database_name}): {self._hosts}")
|
68
|
-
self._db = self._mongo_client[self._database_name]
|
69
|
-
break
|
70
|
-
except (ConnectionFailure,) as e:
|
71
|
-
print(f"MongoDB connection error: {e}")
|
72
|
-
print(f"retrying to connect...")
|
73
|
-
|
74
|
-
def _select_collection(self, collection_name: str):
|
75
|
-
return self._db[collection_name]
|
76
|
-
|
77
|
-
def get_pymongo_client(self):
|
78
|
-
return self._mongo_client
|
79
|
-
|
80
|
-
@staticmethod
|
81
|
-
def _ascending():
|
82
|
-
return ASCENDING
|
83
|
-
|
84
|
-
@staticmethod
|
85
|
-
def _descending():
|
86
|
-
return DESCENDING
|
87
|
-
|
88
|
-
@exception_handler
|
89
|
-
def find(self, collection_name: str, query: dict, session=None):
|
90
|
-
collection = self._select_collection(collection_name)
|
91
|
-
return collection.find(query, session=session)
|
92
|
-
|
93
|
-
@exception_handler
|
94
|
-
def find_one(self, collection_name: str, query: dict, session=None):
|
95
|
-
collection = self._select_collection(collection_name)
|
96
|
-
return collection.find_one(query, session=session)
|
97
|
-
|
98
|
-
@exception_handler
|
99
|
-
def insert_one(self, collection_name: str, query: dict, session=None):
|
100
|
-
collection = self._select_collection(collection_name)
|
101
|
-
return collection.insert_one(query, session=session)
|
102
|
-
|
103
|
-
@exception_handler
|
104
|
-
def delete_one(self, collection_name: str, query: dict, session=None):
|
105
|
-
collection = self._select_collection(collection_name)
|
106
|
-
return collection.delete_one(query, session=session)
|
107
|
-
|
108
|
-
@exception_handler
|
109
|
-
def aggregate(self, collection_name: str, pipeline, session=None):
|
110
|
-
collection = self._select_collection(collection_name)
|
111
|
-
return collection.aggregate(pipeline=pipeline, session=session)
|
112
|
-
|
113
|
-
@exception_handler
|
114
|
-
def count_documents(self, collection_name: str, query: dict, session=None):
|
115
|
-
collection = self._select_collection(collection_name)
|
116
|
-
return collection.count_documents(query, session=session)
|
117
|
-
|
118
|
-
@exception_handler
|
119
|
-
def update_one(
|
120
|
-
self,
|
121
|
-
collection_name: str,
|
122
|
-
query: dict,
|
123
|
-
update: dict,
|
124
|
-
upsert: bool = False,
|
125
|
-
session=None,
|
126
|
-
):
|
127
|
-
collection = self._select_collection(collection_name)
|
128
|
-
return collection.update_one(query, update, upsert=upsert, session=session)
|
129
|
-
|
130
|
-
@exception_handler
|
131
|
-
def watch(
|
132
|
-
self,
|
133
|
-
collection_name: str,
|
134
|
-
operation_before_watch,
|
135
|
-
operation_on_event,
|
136
|
-
first_operation_kwargs={},
|
137
|
-
second_operation_kwargs={},
|
138
|
-
):
|
139
|
-
"""Function to watch for changes in a collection. Preferred to run over threading as daemon.
|
140
|
-
|
141
|
-
:param collection_name: Name of the collection to watch
|
142
|
-
:type collection_name: str
|
143
|
-
:param operation_on_event: Function to run on event
|
144
|
-
:type operation_on_event: function
|
145
|
-
"""
|
146
|
-
operation_before_watch(**first_operation_kwargs)
|
147
|
-
while True:
|
148
|
-
print("Creating new watch cursor")
|
149
|
-
watch_cursor = self._select_collection(
|
150
|
-
collection_name=collection_name
|
151
|
-
).watch()
|
152
|
-
print("Watching: {}.{}\n".format(self._database_name, collection_name))
|
153
|
-
for d in watch_cursor:
|
154
|
-
if d["operationType"] == "invalidate":
|
155
|
-
print(
|
156
|
-
"Watch cursor invalidated (deleted collection: {}?)".format(
|
157
|
-
collection_name
|
158
|
-
)
|
159
|
-
)
|
160
|
-
print("Closing watch cursor")
|
161
|
-
watch_cursor.close()
|
162
|
-
break
|
163
|
-
else:
|
164
|
-
operation_on_event(d, **second_operation_kwargs)
|
165
|
-
watch_cursor.close()
|
166
|
-
return d
|
167
|
-
else:
|
168
|
-
continue
|
169
|
-
break
|
170
|
-
|
171
|
-
@staticmethod
|
172
|
-
def example_operation_for_watch(d):
|
173
|
-
print(d)
|
174
|
-
# del d["fullDocument"]["_id"]
|
175
|
-
# print("local time : {}".format(datetime.utcnow()))
|
176
|
-
# print("cluster time : {}".format(d["clusterTime"].as_datetime()))
|
177
|
-
# print("collection : {}.{}".format(d["ns"]["db"], d["ns"]["coll"]))
|
178
|
-
# try:
|
179
|
-
# print("doc : {}".format(d["fullDocument"]))
|
180
|
-
# except KeyError:
|
181
|
-
# pass
|
182
|
-
|
183
|
-
|
184
|
-
def get_mongo_access(
|
185
|
-
app_name: str, password: str, database: str = "db", restart: bool = False
|
186
|
-
):
|
187
|
-
global _mongo_access
|
188
|
-
|
189
|
-
def init_access():
|
190
|
-
global _mongo_access
|
191
|
-
_mongo_access = MongoConnector(
|
192
|
-
database_name=database,
|
193
|
-
hosts=f"{app_name}:27017",
|
194
|
-
username="admin",
|
195
|
-
password=password,
|
196
|
-
)
|
197
|
-
|
198
|
-
try:
|
199
|
-
if not isinstance(_mongo_access, MongoConnector) or restart:
|
200
|
-
init_access()
|
201
|
-
except NameError:
|
202
|
-
init_access()
|
203
|
-
pass
|
204
|
-
return _mongo_access
|
cgc/sdk/redis.py
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
import redis.asyncio as redis_async
|
2
|
-
import redis
|
3
|
-
|
4
|
-
|
5
|
-
class RedisConnector:
|
6
|
-
redis_client_async = None
|
7
|
-
redis_client = None
|
8
|
-
|
9
|
-
def __init__(
|
10
|
-
self, host: str, password: str = None, decode_responses: bool = False
|
11
|
-
) -> None:
|
12
|
-
self._host = host
|
13
|
-
assert type(host) is str
|
14
|
-
"host must be a str containing redis app name"
|
15
|
-
self._password = password
|
16
|
-
self._decode_responses = decode_responses
|
17
|
-
|
18
|
-
def connect(self, async_client: bool = False):
|
19
|
-
while True:
|
20
|
-
try:
|
21
|
-
if not async_client:
|
22
|
-
self.redis_client = redis.Redis(
|
23
|
-
host=self._host,
|
24
|
-
port=6379,
|
25
|
-
password=self._password,
|
26
|
-
decode_responses=self._decode_responses,
|
27
|
-
)
|
28
|
-
else:
|
29
|
-
self.redis_client_async = redis_async.Redis(
|
30
|
-
host=self._host,
|
31
|
-
port=6379,
|
32
|
-
password=self._password,
|
33
|
-
decode_responses=self._decode_responses,
|
34
|
-
)
|
35
|
-
print(f"Connected to Redis: {self._host}")
|
36
|
-
break
|
37
|
-
except (redis.ConnectionError,) as e:
|
38
|
-
print(f"Redis connection error: {e}")
|
39
|
-
print(f"retrying to connect...")
|
40
|
-
|
41
|
-
def get_redis_client(self):
|
42
|
-
if self.redis_client is None:
|
43
|
-
self.connect()
|
44
|
-
return self.redis_client
|
45
|
-
|
46
|
-
def get_redis_client_async(self):
|
47
|
-
if self.redis_client_async is None:
|
48
|
-
self.connect(async_client=True)
|
49
|
-
return self.redis_client_async
|
50
|
-
|
51
|
-
|
52
|
-
def get_redis_access(
|
53
|
-
app_name: str,
|
54
|
-
password: str,
|
55
|
-
decode_responses: bool = False,
|
56
|
-
restart: bool = False,
|
57
|
-
async_client=False,
|
58
|
-
):
|
59
|
-
global _redis_access
|
60
|
-
global _redis_access_async
|
61
|
-
|
62
|
-
def init_access(async_client=False):
|
63
|
-
global _redis_access
|
64
|
-
global _redis_access_async
|
65
|
-
|
66
|
-
_redis_access = None
|
67
|
-
_redis_access_async = None
|
68
|
-
|
69
|
-
if not async_client:
|
70
|
-
_redis_access = RedisConnector(
|
71
|
-
host=app_name, password=password, decode_responses=decode_responses
|
72
|
-
)
|
73
|
-
else:
|
74
|
-
_redis_access_async = RedisConnector(
|
75
|
-
host=app_name, password=password, decode_responses=decode_responses
|
76
|
-
)
|
77
|
-
|
78
|
-
try:
|
79
|
-
if not async_client:
|
80
|
-
if not isinstance(_redis_access, RedisConnector) or restart:
|
81
|
-
init_access()
|
82
|
-
else:
|
83
|
-
if not isinstance(_redis_access_async, RedisConnector) or restart:
|
84
|
-
init_access(True)
|
85
|
-
except NameError:
|
86
|
-
if not async_client:
|
87
|
-
init_access()
|
88
|
-
else:
|
89
|
-
init_access(True)
|
90
|
-
pass
|
91
|
-
return _redis_access if not async_client else _redis_access_async
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|