datacrunch 1.15.0__py3-none-any.whl → 1.17.1__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.
- datacrunch/__init__.py +53 -1
- datacrunch/datacrunch.py +44 -81
- datacrunch-1.17.1.dist-info/METADATA +30 -0
- datacrunch-1.17.1.dist-info/RECORD +5 -0
- datacrunch-1.17.1.dist-info/WHEEL +4 -0
- datacrunch/InferenceClient/__init__.py +0 -3
- datacrunch/InferenceClient/inference_client.py +0 -379
- datacrunch/__version__.py +0 -1
- datacrunch/authentication/__init__.py +0 -0
- datacrunch/authentication/authentication.py +0 -112
- datacrunch/balance/__init__.py +0 -0
- datacrunch/balance/balance.py +0 -52
- datacrunch/constants.py +0 -107
- datacrunch/containers/__init__.py +0 -33
- datacrunch/containers/containers.py +0 -1081
- datacrunch/exceptions.py +0 -29
- datacrunch/helpers.py +0 -13
- datacrunch/http_client/__init__.py +0 -0
- datacrunch/http_client/http_client.py +0 -241
- datacrunch/images/__init__.py +0 -0
- datacrunch/images/images.py +0 -87
- datacrunch/instance_types/__init__.py +0 -0
- datacrunch/instance_types/instance_types.py +0 -188
- datacrunch/instances/__init__.py +0 -0
- datacrunch/instances/instances.py +0 -247
- datacrunch/locations/__init__.py +0 -0
- datacrunch/locations/locations.py +0 -16
- datacrunch/ssh_keys/__init__.py +0 -0
- datacrunch/ssh_keys/ssh_keys.py +0 -112
- datacrunch/startup_scripts/__init__.py +0 -0
- datacrunch/startup_scripts/startup_scripts.py +0 -113
- datacrunch/volume_types/__init__.py +0 -0
- datacrunch/volume_types/volume_types.py +0 -66
- datacrunch/volumes/__init__.py +0 -0
- datacrunch/volumes/volumes.py +0 -398
- datacrunch-1.15.0.dist-info/METADATA +0 -208
- datacrunch-1.15.0.dist-info/RECORD +0 -69
- datacrunch-1.15.0.dist-info/WHEEL +0 -5
- datacrunch-1.15.0.dist-info/licenses/LICENSE +0 -21
- datacrunch-1.15.0.dist-info/top_level.txt +0 -2
- tests/__init__.py +0 -0
- tests/integration_tests/__init__.py +0 -0
- tests/integration_tests/conftest.py +0 -20
- tests/integration_tests/test_instances.py +0 -36
- tests/integration_tests/test_locations.py +0 -65
- tests/integration_tests/test_volumes.py +0 -94
- tests/unit_tests/__init__.py +0 -0
- tests/unit_tests/authentication/__init__.py +0 -0
- tests/unit_tests/authentication/test_authentication.py +0 -202
- tests/unit_tests/balance/__init__.py +0 -0
- tests/unit_tests/balance/test_balance.py +0 -25
- tests/unit_tests/conftest.py +0 -21
- tests/unit_tests/containers/__init__.py +0 -1
- tests/unit_tests/containers/test_containers.py +0 -959
- tests/unit_tests/http_client/__init__.py +0 -0
- tests/unit_tests/http_client/test_http_client.py +0 -193
- tests/unit_tests/images/__init__.py +0 -0
- tests/unit_tests/images/test_images.py +0 -41
- tests/unit_tests/instance_types/__init__.py +0 -0
- tests/unit_tests/instance_types/test_instance_types.py +0 -87
- tests/unit_tests/instances/__init__.py +0 -0
- tests/unit_tests/instances/test_instances.py +0 -483
- tests/unit_tests/ssh_keys/__init__.py +0 -0
- tests/unit_tests/ssh_keys/test_ssh_keys.py +0 -198
- tests/unit_tests/startup_scripts/__init__.py +0 -0
- tests/unit_tests/startup_scripts/test_startup_scripts.py +0 -196
- tests/unit_tests/test_datacrunch.py +0 -65
- tests/unit_tests/test_exceptions.py +0 -33
- tests/unit_tests/volume_types/__init__.py +0 -0
- tests/unit_tests/volume_types/test_volume_types.py +0 -50
- tests/unit_tests/volumes/__init__.py +0 -0
- tests/unit_tests/volumes/test_volumes.py +0 -641
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import time
|
|
3
|
-
|
|
4
|
-
from datacrunch.http_client.http_client import handle_error
|
|
5
|
-
|
|
6
|
-
TOKEN_ENDPOINT = '/oauth2/token'
|
|
7
|
-
|
|
8
|
-
CLIENT_CREDENTIALS = 'client_credentials'
|
|
9
|
-
REFRESH_TOKEN = 'refresh_token'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class AuthenticationService:
|
|
13
|
-
"""A service for client authentication"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, client_id: str, client_secret: str, base_url: str) -> None:
|
|
16
|
-
self._base_url = base_url
|
|
17
|
-
self._client_id = client_id
|
|
18
|
-
self._client_secret = client_secret
|
|
19
|
-
|
|
20
|
-
def authenticate(self) -> dict:
|
|
21
|
-
"""Authenticate the client and store the access & refresh tokens
|
|
22
|
-
|
|
23
|
-
returns an authentication data dictionary with the following schema:
|
|
24
|
-
{
|
|
25
|
-
"access_token": token str,
|
|
26
|
-
"refresh_token": token str,
|
|
27
|
-
"scope": scope str,
|
|
28
|
-
"token_type": token type str,
|
|
29
|
-
"expires_in": duration until expires in seconds
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
:return: authentication data (tokens, scope, token type, expires in)
|
|
33
|
-
:rtype: dict
|
|
34
|
-
"""
|
|
35
|
-
url = self._base_url + TOKEN_ENDPOINT
|
|
36
|
-
payload = {
|
|
37
|
-
"grant_type": CLIENT_CREDENTIALS,
|
|
38
|
-
"client_id": self._client_id,
|
|
39
|
-
"client_secret": self._client_secret
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
response = requests.post(
|
|
43
|
-
url, json=payload, headers=self._generate_headers())
|
|
44
|
-
handle_error(response)
|
|
45
|
-
|
|
46
|
-
auth_data = response.json()
|
|
47
|
-
|
|
48
|
-
self._access_token = auth_data['access_token']
|
|
49
|
-
self._refresh_token = auth_data['refresh_token']
|
|
50
|
-
self._scope = auth_data['scope']
|
|
51
|
-
self._token_type = auth_data['token_type']
|
|
52
|
-
self._expires_at = time.time() + auth_data['expires_in']
|
|
53
|
-
|
|
54
|
-
return auth_data
|
|
55
|
-
|
|
56
|
-
def refresh(self) -> dict:
|
|
57
|
-
"""Authenticate the client using the refresh token - refresh the access token.
|
|
58
|
-
|
|
59
|
-
updates the object's tokens, and:
|
|
60
|
-
returns an authentication data dictionary with the following schema:
|
|
61
|
-
{
|
|
62
|
-
"access_token": token str,
|
|
63
|
-
"refresh_token": token str,
|
|
64
|
-
"scope": scope str,
|
|
65
|
-
"token_type": token type str,
|
|
66
|
-
"expires_in": duration until expires in seconds
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
:return: authentication data (tokens, scope, token type, expires in)
|
|
70
|
-
:rtype: dict
|
|
71
|
-
"""
|
|
72
|
-
url = self._base_url + TOKEN_ENDPOINT
|
|
73
|
-
|
|
74
|
-
payload = {
|
|
75
|
-
"grant_type": REFRESH_TOKEN,
|
|
76
|
-
"refresh_token": self._refresh_token
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
response = requests.post(
|
|
80
|
-
url, json=payload, headers=self._generate_headers())
|
|
81
|
-
|
|
82
|
-
# if refresh token is also expired, authenticate again:
|
|
83
|
-
if response.status_code == 401 or response.status_code == 400:
|
|
84
|
-
return self.authenticate()
|
|
85
|
-
else:
|
|
86
|
-
handle_error(response)
|
|
87
|
-
|
|
88
|
-
auth_data = response.json()
|
|
89
|
-
|
|
90
|
-
self._access_token = auth_data['access_token']
|
|
91
|
-
self._refresh_token = auth_data['refresh_token']
|
|
92
|
-
self._scope = auth_data['scope']
|
|
93
|
-
self._token_type = auth_data['token_type']
|
|
94
|
-
self._expires_at = time.time() + auth_data['expires_in']
|
|
95
|
-
|
|
96
|
-
return auth_data
|
|
97
|
-
|
|
98
|
-
def _generate_headers(self):
|
|
99
|
-
# get the first 10 chars of the client id
|
|
100
|
-
client_id_truncated = self._client_id[:10]
|
|
101
|
-
headers = {
|
|
102
|
-
'User-Agent': 'datacrunch-python-' + client_id_truncated
|
|
103
|
-
}
|
|
104
|
-
return headers
|
|
105
|
-
|
|
106
|
-
def is_expired(self) -> bool:
|
|
107
|
-
"""Returns true if the access token is expired.
|
|
108
|
-
|
|
109
|
-
:return: True if the access token is expired, otherwise False.
|
|
110
|
-
:rtype: bool
|
|
111
|
-
"""
|
|
112
|
-
return time.time() >= self._expires_at
|
datacrunch/balance/__init__.py
DELETED
|
File without changes
|
datacrunch/balance/balance.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
from typing import Dict
|
|
2
|
-
|
|
3
|
-
BALANCE_ENDPOINT = '/balance'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Balance:
|
|
7
|
-
"""A balance model class"""
|
|
8
|
-
|
|
9
|
-
def __init__(self, amount: float, currency: str) -> None:
|
|
10
|
-
"""Initialize a new Balance object
|
|
11
|
-
|
|
12
|
-
:param amount: Balance amount
|
|
13
|
-
:type amount: float
|
|
14
|
-
:param currency: currency code
|
|
15
|
-
:type currency: str
|
|
16
|
-
"""
|
|
17
|
-
self._amount = amount
|
|
18
|
-
self._currency = currency
|
|
19
|
-
|
|
20
|
-
@property
|
|
21
|
-
def amount(self) -> float:
|
|
22
|
-
"""Get the balance amount
|
|
23
|
-
|
|
24
|
-
:return: amount
|
|
25
|
-
:rtype: float
|
|
26
|
-
"""
|
|
27
|
-
return self._amount
|
|
28
|
-
|
|
29
|
-
@property
|
|
30
|
-
def currency(self) -> str:
|
|
31
|
-
"""Get the currency code
|
|
32
|
-
|
|
33
|
-
:return: currency code
|
|
34
|
-
:rtype: str
|
|
35
|
-
"""
|
|
36
|
-
return self._currency
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class BalanceService:
|
|
40
|
-
"""A service for interacting with the balance endpoint"""
|
|
41
|
-
|
|
42
|
-
def __init__(self, http_client) -> None:
|
|
43
|
-
self._http_client = http_client
|
|
44
|
-
|
|
45
|
-
def get(self) -> Balance:
|
|
46
|
-
"""Get the client's current balance
|
|
47
|
-
|
|
48
|
-
:return: Balance object containing the amount and currency.
|
|
49
|
-
:rtype: Balance
|
|
50
|
-
"""
|
|
51
|
-
balance = self._http_client.get(BALANCE_ENDPOINT).json()
|
|
52
|
-
return Balance(balance["amount"], balance["currency"])
|
datacrunch/constants.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
class Actions:
|
|
2
|
-
START = 'start'
|
|
3
|
-
SHUTDOWN = 'shutdown'
|
|
4
|
-
DELETE = 'delete'
|
|
5
|
-
HIBERNATE = 'hibernate'
|
|
6
|
-
RESTORE = 'restore'
|
|
7
|
-
|
|
8
|
-
def __init__(self):
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class VolumeActions:
|
|
13
|
-
ATTACH = 'attach'
|
|
14
|
-
DETACH = 'detach'
|
|
15
|
-
RENAME = 'rename'
|
|
16
|
-
INCREASE_SIZE = 'resize'
|
|
17
|
-
DELETE = 'delete'
|
|
18
|
-
CLONE = 'clone'
|
|
19
|
-
|
|
20
|
-
def __init__(self):
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class InstanceStatus:
|
|
25
|
-
ORDERED = 'ordered'
|
|
26
|
-
RUNNING = 'running'
|
|
27
|
-
PROVISIONING = 'provisioning'
|
|
28
|
-
OFFLINE = 'offline'
|
|
29
|
-
STARTING_HIBERNATION = 'starting_hibernation'
|
|
30
|
-
HIBERNATING = 'hibernating'
|
|
31
|
-
RESTORING = 'restoring'
|
|
32
|
-
ERROR = 'error'
|
|
33
|
-
|
|
34
|
-
def __init__(self):
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class VolumeStatus:
|
|
39
|
-
ORDERED = "ordered"
|
|
40
|
-
CREATING = "creating"
|
|
41
|
-
ATTACHED = "attached"
|
|
42
|
-
DETACHED = "detached"
|
|
43
|
-
DELETING = "deleting"
|
|
44
|
-
DELETED = "deleted"
|
|
45
|
-
CLONING = 'cloning'
|
|
46
|
-
|
|
47
|
-
def __init__(self):
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class VolumeTypes:
|
|
52
|
-
NVMe = "NVMe"
|
|
53
|
-
HDD = "HDD"
|
|
54
|
-
|
|
55
|
-
def __init__(self):
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
class Locations:
|
|
60
|
-
FIN_01: str = "FIN-01"
|
|
61
|
-
ICE_01: str = "ICE-01"
|
|
62
|
-
|
|
63
|
-
def __init__(self):
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
class ErrorCodes:
|
|
68
|
-
INVALID_REQUEST = "invalid_request"
|
|
69
|
-
UNAUTHORIZED_REQUEST = "unauthorized_request"
|
|
70
|
-
INSUFFICIENT_FUNDS = "insufficient_funds"
|
|
71
|
-
FORBIDDEN_ACTION = "forbidden_action"
|
|
72
|
-
NOT_FOUND = "not_found"
|
|
73
|
-
SERVER_ERROR = "server_error"
|
|
74
|
-
SERVICE_UNAVAILABLE = "service_unavailable"
|
|
75
|
-
|
|
76
|
-
def __init__(self):
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class Constants:
|
|
81
|
-
def __init__(self, base_url, version):
|
|
82
|
-
self.instance_actions: Actions = Actions()
|
|
83
|
-
"""Available actions to perform on an instance"""
|
|
84
|
-
|
|
85
|
-
self.volume_actions: VolumeActions = VolumeActions()
|
|
86
|
-
"""Available actions to perform on a volume"""
|
|
87
|
-
|
|
88
|
-
self.instance_status: InstanceStatus = InstanceStatus()
|
|
89
|
-
"""Possible instance statuses"""
|
|
90
|
-
|
|
91
|
-
self.volume_status: VolumeStatus = VolumeStatus()
|
|
92
|
-
"""Possible volume statuses"""
|
|
93
|
-
|
|
94
|
-
self.volume_types: VolumeTypes = VolumeTypes()
|
|
95
|
-
"""Available volume types"""
|
|
96
|
-
|
|
97
|
-
self.locations: Locations = Locations()
|
|
98
|
-
"""Available locations"""
|
|
99
|
-
|
|
100
|
-
self.error_codes: ErrorCodes = ErrorCodes()
|
|
101
|
-
"""Available error codes"""
|
|
102
|
-
|
|
103
|
-
self.base_url: str = base_url
|
|
104
|
-
"""DataCrunch's Public API URL"""
|
|
105
|
-
|
|
106
|
-
self.version: str = version
|
|
107
|
-
"""Current SDK Version"""
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from .containers import (
|
|
2
|
-
EnvVar,
|
|
3
|
-
EnvVarType,
|
|
4
|
-
ContainerRegistryType,
|
|
5
|
-
ContainerDeploymentStatus,
|
|
6
|
-
HealthcheckSettings,
|
|
7
|
-
EntrypointOverridesSettings,
|
|
8
|
-
VolumeMount,
|
|
9
|
-
SecretMount,
|
|
10
|
-
SharedFileSystemMount,
|
|
11
|
-
GeneralStorageMount,
|
|
12
|
-
VolumeMountType,
|
|
13
|
-
Container,
|
|
14
|
-
ContainerRegistryCredentials,
|
|
15
|
-
ContainerRegistrySettings,
|
|
16
|
-
ComputeResource,
|
|
17
|
-
ScalingPolicy,
|
|
18
|
-
QueueLoadScalingTrigger,
|
|
19
|
-
UtilizationScalingTrigger,
|
|
20
|
-
ScalingTriggers,
|
|
21
|
-
ScalingOptions,
|
|
22
|
-
Deployment,
|
|
23
|
-
ReplicaInfo,
|
|
24
|
-
Secret,
|
|
25
|
-
RegistryCredential,
|
|
26
|
-
ContainersService,
|
|
27
|
-
BaseRegistryCredentials,
|
|
28
|
-
DockerHubCredentials,
|
|
29
|
-
GithubCredentials,
|
|
30
|
-
GCRCredentials,
|
|
31
|
-
AWSECRCredentials,
|
|
32
|
-
CustomRegistryCredentials,
|
|
33
|
-
)
|