sap-ai-sdk-core 2.9.9__py3-none-any.whl → 3.0.3__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.
- ai_core_sdk/ai_core_v2_client.py +157 -0
- ai_core_sdk/cli.py +172 -0
- ai_core_sdk/credentials.py +196 -0
- ai_core_sdk/exception.py +11 -0
- ai_core_sdk/helpers/__init__.py +39 -0
- ai_core_sdk/helpers/constants.py +18 -0
- ai_core_sdk/helpers/logging.py +23 -0
- ai_core_sdk/models/__init__.py +33 -0
- ai_core_sdk/models/application.py +37 -0
- ai_core_sdk/models/application_query_response.py +30 -0
- ai_core_sdk/models/application_resource_sync_status.py +34 -0
- ai_core_sdk/models/application_source.py +34 -0
- ai_core_sdk/models/application_status.py +66 -0
- ai_core_sdk/models/base_models.py +62 -0
- ai_core_sdk/models/docker_registry_secret.py +23 -0
- ai_core_sdk/models/docker_registry_secret_query_response.py +30 -0
- ai_core_sdk/models/kpi.py +25 -0
- ai_core_sdk/models/object_store_secret.py +32 -0
- ai_core_sdk/models/object_store_secret_query_response.py +30 -0
- ai_core_sdk/models/repository.py +36 -0
- ai_core_sdk/models/repository_query_response.py +30 -0
- ai_core_sdk/models/repository_status.py +9 -0
- ai_core_sdk/models/resource_group.py +50 -0
- ai_core_sdk/models/resource_group_query_response.py +31 -0
- ai_core_sdk/models/resource_group_status.py +9 -0
- ai_core_sdk/models/secret.py +30 -0
- ai_core_sdk/models/secret_query_response.py +30 -0
- ai_core_sdk/resource_clients/__init__.py +13 -0
- ai_core_sdk/resource_clients/applications_client.py +173 -0
- ai_core_sdk/resource_clients/docker_registry_secrets_client.py +117 -0
- ai_core_sdk/resource_clients/internal_rest_client.py +52 -0
- ai_core_sdk/resource_clients/kpi_client.py +26 -0
- ai_core_sdk/resource_clients/metrics_client.py +131 -0
- ai_core_sdk/resource_clients/object_store_secrets_client.py +215 -0
- ai_core_sdk/resource_clients/repositories_client.py +116 -0
- ai_core_sdk/resource_clients/secrets_client.py +148 -0
- ai_core_sdk/tracking/__init__.py +2 -0
- ai_core_sdk/tracking/tracking.py +215 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.ai_core_v2_client.html +127 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.cli.html +59 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.credentials.html +209 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.exception.html +161 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.helpers.constants.html +90 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.helpers.html +52 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.helpers.logging.html +41 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.html +29 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.application.html +79 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.application_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.application_resource_sync_status.html +77 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.application_source.html +77 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.application_status.html +90 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.base_models.html +120 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.docker_registry_secret.html +85 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.docker_registry_secret_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.html +40 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.kpi.html +73 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.object_store_secret.html +71 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.object_store_secret_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.repository.html +77 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.repository_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.repository_status.html +69 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.resource_group.html +85 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.resource_group_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.resource_group_status.html +69 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.secret.html +76 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.models.secret_query_response.html +86 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.applications_client.html +186 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.docker_registry_secrets_client.html +147 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.html +29 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.internal_rest_client.html +181 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.kpi_client.html +87 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.metrics_client.html +189 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.object_store_secrets_client.html +205 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.repositories_client.html +148 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.resource_groups_client.html +156 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.resource_clients.secrets_client.html +165 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.tracking.html +22 -0
- sap_ai_sdk_core-3.0.3.data/data/docs/ai_core_sdk.tracking.tracking.html +224 -0
- sap_ai_sdk_core-3.0.3.dist-info/METADATA +253 -0
- sap_ai_sdk_core-3.0.3.dist-info/RECORD +84 -0
- {sap_ai_sdk_core-2.9.9.dist-info → sap_ai_sdk_core-3.0.3.dist-info}/WHEEL +1 -1
- sap_ai_sdk_core-3.0.3.dist-info/top_level.txt +1 -0
- sap_ai_sdk_core-2.9.9.dist-info/METADATA +0 -43
- sap_ai_sdk_core-2.9.9.dist-info/RECORD +0 -6
- sap_ai_sdk_core-2.9.9.dist-info/top_level.txt +0 -1
- {sap-ai-sdk-core → ai_core_sdk}/__init__.py +0 -0
- {sap_ai_sdk_core-2.9.9.dist-info/licenses → sap_ai_sdk_core-3.0.3.dist-info}/LICENSE +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from ai_api_client_sdk.ai_api_v2_client import AIAPIV2Client
|
|
2
|
+
from ai_api_client_sdk.helpers.rest_client import RestClient
|
|
3
|
+
from ai_api_client_sdk.resource_clients.artifact_client import ArtifactClient
|
|
4
|
+
from ai_api_client_sdk.resource_clients.base_client import BaseClient
|
|
5
|
+
from ai_api_client_sdk.resource_clients.configuration_client import ConfigurationClient
|
|
6
|
+
from ai_api_client_sdk.resource_clients.deployment_client import DeploymentClient
|
|
7
|
+
from ai_api_client_sdk.resource_clients.executable_client import ExecutableClient
|
|
8
|
+
from ai_api_client_sdk.resource_clients.execution_client import ExecutionClient
|
|
9
|
+
from ai_api_client_sdk.resource_clients.meta_client import MetaClient
|
|
10
|
+
from ai_api_client_sdk.resource_clients.metrics_client import MetricsClient
|
|
11
|
+
from ai_api_client_sdk.resource_clients.model_client import ModelClient
|
|
12
|
+
from ai_api_client_sdk.resource_clients.resource_groups_client import ResourceGroupsClient
|
|
13
|
+
from ai_api_client_sdk.resource_clients.scenario_client import ScenarioClient
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from ai_core_sdk.exception import AICoreInvalidInputException
|
|
2
|
+
from ai_core_sdk.models import BasicResponse
|
|
3
|
+
from ai_core_sdk.models.application import Application
|
|
4
|
+
from ai_core_sdk.models.application_query_response import ApplicationQueryResponse
|
|
5
|
+
from ai_core_sdk.models.application_status import ApplicationStatus
|
|
6
|
+
from ai_core_sdk.resource_clients import BaseClient
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ApplicationsClient(BaseClient):
|
|
10
|
+
"""ApplicationsClient is a class implemented for interacting with the applications related
|
|
11
|
+
endpoints of the server. It implements the base class
|
|
12
|
+
:class:`ai_api_client_sdk.resource_clients.base_client.BaseClient`
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
__PATH = '/admin/applications'
|
|
16
|
+
|
|
17
|
+
def create(self, revision: str, path: str, application_name: str = None, repository_name: str = None,
|
|
18
|
+
repository_url: str = None) -> BasicResponse:
|
|
19
|
+
"""Creates an application.
|
|
20
|
+
|
|
21
|
+
:param revision: revision to synchronize
|
|
22
|
+
:type revision: str
|
|
23
|
+
:param path: within the repository to synchronize
|
|
24
|
+
:type path: str
|
|
25
|
+
:param application_name: Name of the application
|
|
26
|
+
:type application_name: str, optional
|
|
27
|
+
:param repository_name: Name of the repository to synchronize. Either this or the repository_url needs to be
|
|
28
|
+
provided
|
|
29
|
+
:type repository_name: str, optional
|
|
30
|
+
:param repository_url: URL of the repository to synchronize. Either this or the repository_name needs to be
|
|
31
|
+
provided
|
|
32
|
+
:type repository_url: str, optional
|
|
33
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
34
|
+
server
|
|
35
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
36
|
+
server
|
|
37
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
38
|
+
server
|
|
39
|
+
:return: An object representing the response from the server
|
|
40
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
41
|
+
"""
|
|
42
|
+
if (repository_url and repository_name) or (not repository_name and not repository_url):
|
|
43
|
+
raise AICoreInvalidInputException('Either repository_url or repository_name must be provided, not both')
|
|
44
|
+
body = {'revision': revision, 'path': path}
|
|
45
|
+
if repository_name:
|
|
46
|
+
body['repository_name'] = repository_name
|
|
47
|
+
elif repository_url:
|
|
48
|
+
body['repository_url'] = repository_url
|
|
49
|
+
if application_name:
|
|
50
|
+
body['application_name'] = application_name
|
|
51
|
+
response_dict = self.rest_client.post(path=self.__PATH, body=body)
|
|
52
|
+
return BasicResponse.from_dict(response_dict)
|
|
53
|
+
|
|
54
|
+
def delete(self, application_name: str) -> BasicResponse:
|
|
55
|
+
"""Deletes the application.
|
|
56
|
+
|
|
57
|
+
:param application_name: name of the application to be deleted
|
|
58
|
+
:type application_name: str
|
|
59
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
60
|
+
server
|
|
61
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
62
|
+
server
|
|
63
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
64
|
+
server
|
|
65
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
|
|
66
|
+
the server
|
|
67
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
68
|
+
server
|
|
69
|
+
:return: An object representing the response from the server
|
|
70
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
71
|
+
"""
|
|
72
|
+
response_dict = self.rest_client.delete(path=f'{self.__PATH}/{application_name}')
|
|
73
|
+
return BasicResponse.from_dict(response_dict)
|
|
74
|
+
|
|
75
|
+
def get(self, application_name: str) -> Application:
|
|
76
|
+
"""Retrieves the application from the server.
|
|
77
|
+
|
|
78
|
+
:param application_name: name of the application to be retrieved
|
|
79
|
+
:type application_name: str
|
|
80
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
81
|
+
server
|
|
82
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
83
|
+
server
|
|
84
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
85
|
+
server
|
|
86
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
87
|
+
server
|
|
88
|
+
:return: The retrieved application
|
|
89
|
+
:rtype: class:`ai_core_sdk.models.application.Application`
|
|
90
|
+
"""
|
|
91
|
+
response_dict = self.rest_client.get(path=f'{self.__PATH}/{application_name}')
|
|
92
|
+
return Application.from_dict(response_dict)
|
|
93
|
+
|
|
94
|
+
def get_status(self, application_name: str) -> ApplicationStatus:
|
|
95
|
+
"""Retrieves the application status from the server.
|
|
96
|
+
|
|
97
|
+
:param application_name: name of the application
|
|
98
|
+
:type application_name: str
|
|
99
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
100
|
+
server
|
|
101
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
102
|
+
server
|
|
103
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
104
|
+
server
|
|
105
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
106
|
+
server
|
|
107
|
+
:return: The retrieved application status
|
|
108
|
+
:rtype: class:`ai_core_sdk.models.application_status.ApplicationStatus`
|
|
109
|
+
"""
|
|
110
|
+
response_dict = self.rest_client.get(path=f'{self.__PATH}/{application_name}/status')
|
|
111
|
+
return ApplicationStatus.from_dict(response_dict)
|
|
112
|
+
|
|
113
|
+
def modify(self, application_name: str, repository_url: str, path: str, revision: str) -> BasicResponse:
|
|
114
|
+
"""Modifies the application
|
|
115
|
+
|
|
116
|
+
:param application_name: name of the application to be modified
|
|
117
|
+
:type name: str
|
|
118
|
+
:param repository_url:
|
|
119
|
+
:type repository_url: str
|
|
120
|
+
:param revision:
|
|
121
|
+
:type revision: str
|
|
122
|
+
:param path:
|
|
123
|
+
:type path: str
|
|
124
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
125
|
+
server
|
|
126
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
127
|
+
server
|
|
128
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
129
|
+
server
|
|
130
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
|
|
131
|
+
the server
|
|
132
|
+
:return: An object representing the response from the server
|
|
133
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
134
|
+
"""
|
|
135
|
+
body = {'path': path, 'revision': revision, 'repository_url': repository_url}
|
|
136
|
+
response_dict = self.rest_client.patch(path=f'{self.__PATH}/{application_name}', body=body)
|
|
137
|
+
return BasicResponse.from_dict(response_dict)
|
|
138
|
+
|
|
139
|
+
def query(self) -> ApplicationQueryResponse:
|
|
140
|
+
"""Returns the applications.
|
|
141
|
+
|
|
142
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
143
|
+
server
|
|
144
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
145
|
+
server
|
|
146
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
147
|
+
server
|
|
148
|
+
:return: The retrieved applications
|
|
149
|
+
:rtype: class:`ai_core_sdk.models.application_query_response.ApplicationQueryResponse`
|
|
150
|
+
"""
|
|
151
|
+
response_dict = self.rest_client.get(path=self.__PATH)
|
|
152
|
+
return ApplicationQueryResponse.from_dict(response_dict)
|
|
153
|
+
|
|
154
|
+
def refresh(self, application_name: str) -> BasicResponse:
|
|
155
|
+
"""Triggers synchronisation of the application.
|
|
156
|
+
|
|
157
|
+
:param application_name: name of the application to be refreshed
|
|
158
|
+
:type application_name: str
|
|
159
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
160
|
+
server
|
|
161
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
162
|
+
server
|
|
163
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
164
|
+
server
|
|
165
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
|
|
166
|
+
the server
|
|
167
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
168
|
+
server
|
|
169
|
+
:return: An object representing the response from the server
|
|
170
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
171
|
+
"""
|
|
172
|
+
response_dict = self.rest_client.post(path=f'{self.__PATH}/{application_name}/refresh')
|
|
173
|
+
return BasicResponse.from_dict(response_dict)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from ai_core_sdk.helpers import form_top_skip_params
|
|
2
|
+
from ai_core_sdk.models import BasicResponse
|
|
3
|
+
from ai_core_sdk.models.base_models import Message
|
|
4
|
+
from ai_core_sdk.models.docker_registry_secret import DockerRegistrySecret
|
|
5
|
+
from ai_core_sdk.models.docker_registry_secret_query_response import DockerRegistrySecretQueryResponse
|
|
6
|
+
from ai_core_sdk.resource_clients import BaseClient
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class DockerRegistrySecretsClient(BaseClient):
|
|
10
|
+
"""DockerRegistrySecretsClient is a class implemented for interacting with the docker registry secret related
|
|
11
|
+
endpoints of the server. It implements the base class
|
|
12
|
+
:class:`ai_api_client_sdk.resource_clients.base_client.BaseClient`
|
|
13
|
+
"""
|
|
14
|
+
__PATH = '/admin/dockerRegistrySecrets'
|
|
15
|
+
|
|
16
|
+
def create(self, name: str, data: dict) -> Message:
|
|
17
|
+
"""Creates a docker secret based on the configuration in the request body.
|
|
18
|
+
|
|
19
|
+
:param name: name of the docker registry secret
|
|
20
|
+
:type name: str
|
|
21
|
+
:param data: json dict, defining the docker registry secret
|
|
22
|
+
:type data: dict
|
|
23
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
24
|
+
server
|
|
25
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
26
|
+
server
|
|
27
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
28
|
+
server
|
|
29
|
+
:return: An object representing the response from the server
|
|
30
|
+
:rtype: class:`ai_core_sdk.models.base_models.Message`
|
|
31
|
+
"""
|
|
32
|
+
body = {'name': name, 'data': data}
|
|
33
|
+
response_dict = self.rest_client.post(path=f'{self.__PATH}', body=body)
|
|
34
|
+
return Message.from_dict(response_dict)
|
|
35
|
+
|
|
36
|
+
def delete(self, name: str) -> BasicResponse:
|
|
37
|
+
"""Deletes the docker registry secret with the given name if it exists.
|
|
38
|
+
|
|
39
|
+
:param name: name of the docker registry secret to be deleted
|
|
40
|
+
:type name: str
|
|
41
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
42
|
+
server
|
|
43
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
44
|
+
server
|
|
45
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
46
|
+
server
|
|
47
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
|
|
48
|
+
the server
|
|
49
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
50
|
+
server
|
|
51
|
+
:return: An object representing the response from the server
|
|
52
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
53
|
+
"""
|
|
54
|
+
response_dict = self.rest_client.delete(path=f'{self.__PATH}/{name}')
|
|
55
|
+
return BasicResponse.from_dict(response_dict)
|
|
56
|
+
|
|
57
|
+
def get(self, name: str) -> DockerRegistrySecret:
|
|
58
|
+
"""Returns the metadata of the docker registry secrets which matches the given name.
|
|
59
|
+
|
|
60
|
+
:param name: name of the docker registry secret to be retrieved
|
|
61
|
+
:type name: str
|
|
62
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
63
|
+
server
|
|
64
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
65
|
+
server
|
|
66
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
67
|
+
server
|
|
68
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
69
|
+
server
|
|
70
|
+
:return: The retrieved metadata of the docker registry secret
|
|
71
|
+
:rtype: class:`ai_core_sdk.models.docker_registry_secret.DockerRegistrySecret`
|
|
72
|
+
"""
|
|
73
|
+
response_dict = self.rest_client.get(path=f'{self.__PATH}/{name}')
|
|
74
|
+
return DockerRegistrySecret.from_dict(response_dict)
|
|
75
|
+
|
|
76
|
+
def modify(self, name: str, data: dict) -> BasicResponse:
|
|
77
|
+
"""Updates the docker registry secret
|
|
78
|
+
|
|
79
|
+
:param name: name of the docker registry secret to be modified
|
|
80
|
+
:type name: str
|
|
81
|
+
:param data: json dict, defining the docker registry secret
|
|
82
|
+
:type data: dict
|
|
83
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
84
|
+
server
|
|
85
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
86
|
+
server
|
|
87
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
88
|
+
server
|
|
89
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIPreconditionFailedException` if a 412 response is received from
|
|
90
|
+
the server
|
|
91
|
+
:return: An object representing the response from the server
|
|
92
|
+
:rtype: class:`ai_api_client_sdk.models.base_models.BasicResponse`
|
|
93
|
+
"""
|
|
94
|
+
body = {'data': data}
|
|
95
|
+
response_dict = self.rest_client.patch(path=f'{self.__PATH}/{name}', body=body)
|
|
96
|
+
return BasicResponse.from_dict(response_dict)
|
|
97
|
+
|
|
98
|
+
def query(self, top: int = None, skip: int = None) -> DockerRegistrySecretQueryResponse:
|
|
99
|
+
"""Gets a list of metadata of docker registry secrets.
|
|
100
|
+
|
|
101
|
+
:param top: Number of docker registry secrets to be retrieved, defaults to None
|
|
102
|
+
:type top: int, optional
|
|
103
|
+
:param skip: Number of docker registry secrets to be skipped, from the list of the queried docker registry
|
|
104
|
+
secrets, defaults to None
|
|
105
|
+
:type skip: int, optional
|
|
106
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
107
|
+
server
|
|
108
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
109
|
+
server
|
|
110
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
111
|
+
server
|
|
112
|
+
:return: A list of metadata of secrets
|
|
113
|
+
:rtype: class:`ai_core_sdk.models.docker_registry_secret_query_response.DockerRegistrySecretQueryResponse`
|
|
114
|
+
"""
|
|
115
|
+
params = form_top_skip_params(top, skip)
|
|
116
|
+
response_dict = self.rest_client.get(path=f'{self.__PATH}', params=params)
|
|
117
|
+
return DockerRegistrySecretQueryResponse.from_dict(response_dict)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from ai_api_client_sdk.ai_api_v2_client import RestClient
|
|
3
|
+
|
|
4
|
+
from ai_core_sdk.exception import AICoreSDKException
|
|
5
|
+
from ai_core_sdk.helpers import is_within_aicore
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InternalRestClient(RestClient):
|
|
9
|
+
"""InternalRestClient is a class implemented for sending requests to services within aicore. The InternalRestClient should only be used for services that do not require authentication when called within aicore.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
base_url=None,
|
|
15
|
+
get_token=None,
|
|
16
|
+
resource_group=None,
|
|
17
|
+
*args,
|
|
18
|
+
**kwargs,
|
|
19
|
+
):
|
|
20
|
+
# Disallows parameters set by this class. This way this class must not be adjusted as the signiture of its parent class changes.
|
|
21
|
+
if base_url or get_token or resource_group:
|
|
22
|
+
raise AICoreSDKException(
|
|
23
|
+
"InternalRestClient should must not be called with base_url, get_token or resource_group"
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
if not is_within_aicore():
|
|
27
|
+
raise AICoreSDKException(
|
|
28
|
+
"Attempted to skip authentication even though SDK is not used within aicore"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
api_base_url = os.getenv("AICORE_TRACKING_ENDPOINT")
|
|
32
|
+
|
|
33
|
+
# framing the base url of tracking endpoint
|
|
34
|
+
base_url = f"{api_base_url}/api/v1"
|
|
35
|
+
|
|
36
|
+
# dummy token creator function to be passed to rest client
|
|
37
|
+
def dummy_token_creator():
|
|
38
|
+
return ""
|
|
39
|
+
|
|
40
|
+
token_creator = dummy_token_creator
|
|
41
|
+
|
|
42
|
+
# resource group will be auto detected from the request going to tracking api from the training pod.
|
|
43
|
+
# Hence not passing the resource group id
|
|
44
|
+
resource_group = ""
|
|
45
|
+
|
|
46
|
+
super().__init__(
|
|
47
|
+
base_url=base_url,
|
|
48
|
+
get_token=token_creator,
|
|
49
|
+
resource_group=resource_group,
|
|
50
|
+
*args,
|
|
51
|
+
**kwargs,
|
|
52
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from ai_core_sdk.models.kpi import Kpi
|
|
2
|
+
from ai_core_sdk.resource_clients import BaseClient
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class KpiClient(BaseClient):
|
|
6
|
+
"""KpiClient is a class implemented for interacting with the analytics kpi
|
|
7
|
+
endpoint of the server. It implements the base class
|
|
8
|
+
:class:`ai_api_client_sdk.resource_clients.base_client.BaseClient`
|
|
9
|
+
"""
|
|
10
|
+
__PATH = '/analytics/kpis'
|
|
11
|
+
|
|
12
|
+
def query(self) -> Kpi:
|
|
13
|
+
"""Retrieves the number of executions, artifacts, and deployments
|
|
14
|
+
for each resource group, scenario, and executable.
|
|
15
|
+
|
|
16
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIAuthorizationException` if a 401 response is received from the
|
|
17
|
+
server
|
|
18
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPINotFoundException` if a 404 response is received from the
|
|
19
|
+
server
|
|
20
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
21
|
+
server
|
|
22
|
+
:return: The retrieved KPI data
|
|
23
|
+
:rtype: class:`ai_core_sdk.models.kpi.Kpi`
|
|
24
|
+
"""
|
|
25
|
+
response_dict = self.rest_client.get(path=f'{self.__PATH}')
|
|
26
|
+
return Kpi.from_dict(response_dict)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from ai_core_sdk.models import Metric, MetricCustomInfo, MetricTag, MetricLabel
|
|
4
|
+
from ai_core_sdk.resource_clients import MetricsClient
|
|
5
|
+
|
|
6
|
+
from ai_core_sdk.exception import AICoreSDKException
|
|
7
|
+
class MetricsCoreClient(MetricsClient):
|
|
8
|
+
"""MetricsCoreClient is a class implemented for interacting with the metrics related
|
|
9
|
+
endpoints of the server. It is inherited from the base class
|
|
10
|
+
:class:`ai_api_client_sdk.resource_clients.metrics_client.MetricsClient`
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, rest_client, execution_id: str = None) -> None:
|
|
14
|
+
super().__init__(rest_client)
|
|
15
|
+
self.execution_id = execution_id
|
|
16
|
+
self.rest_client = rest_client
|
|
17
|
+
self.metrics_path = '/metrics'
|
|
18
|
+
|
|
19
|
+
def modify(self, execution_id: str = '', metrics: List[Metric] = None, tags: List[MetricTag] = None,
|
|
20
|
+
custom_info: List[MetricCustomInfo] = None, resource_group: str = None) -> None:
|
|
21
|
+
"""Creates or updates the metrics for an execution.
|
|
22
|
+
|
|
23
|
+
:param execution_id: ID of the execution, of which the metrics should be modified.
|
|
24
|
+
:type execution_id: str
|
|
25
|
+
:param metrics: List of the metrics related to the execution, defaults to None
|
|
26
|
+
:type metrics: List[class:`ai_api_client_sdk.metric.Metric`], optional
|
|
27
|
+
:param tags: List of the tags related to the execution, defaults to None
|
|
28
|
+
:type tags: List[class:'ai_api_client_sdk.models.metric_tag.MetricTag'], optional
|
|
29
|
+
:param custom_info: List of custom info related to the execution, defaults to None
|
|
30
|
+
:type custom_info: List[class:`ai_api_client_sdk.models.metric_custom_info.MetricCustomInfo`], optional
|
|
31
|
+
:param resource_group: Resource Group which the request should be sent on behalf. Either this or a default
|
|
32
|
+
resource group in the :class:`ai_api_client_sdk.ai_api_v2_client.AIAPIV2Client` should be specified,
|
|
33
|
+
defaults to None
|
|
34
|
+
:type resource_group: str
|
|
35
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
36
|
+
server
|
|
37
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
38
|
+
server
|
|
39
|
+
"""
|
|
40
|
+
body = {'execution_id': self.execution_id if self.execution_id else execution_id}
|
|
41
|
+
if metrics:
|
|
42
|
+
body['metrics'] = [metric.to_dict() for metric in metrics]
|
|
43
|
+
if tags:
|
|
44
|
+
body['tags'] = [tag.__dict__ for tag in tags]
|
|
45
|
+
if custom_info:
|
|
46
|
+
body['custom_info'] = [c_info.__dict__ for c_info in custom_info]
|
|
47
|
+
|
|
48
|
+
self.rest_client.patch(path=self.metrics_path, body=body, resource_group=resource_group)
|
|
49
|
+
|
|
50
|
+
def log_metrics(self, metrics: List[Metric], execution_id: str = '', artifact_name: str = None,
|
|
51
|
+
resource_group: str = None) -> None:
|
|
52
|
+
"""Creates or updates the metrics for an execution.
|
|
53
|
+
|
|
54
|
+
:param metrics: List of the metrics related to the execution,
|
|
55
|
+
:type metrics: List[class:`ai_api_client_sdk.metric.Metric`]
|
|
56
|
+
:param execution_id: ID of the execution, of which the metrics should be modified.
|
|
57
|
+
:type execution_id: str
|
|
58
|
+
:param artifact_name: Name of the artifact to associate with a metric, defaults to None
|
|
59
|
+
:type artifact_name: str
|
|
60
|
+
:param resource_group: Resource Group which the request should be sent on behalf. Either this or a default
|
|
61
|
+
resource group in the :class:`ai_api_client_sdk.ai_api_v2_client.AIAPIV2Client` should be specified,
|
|
62
|
+
defaults to None
|
|
63
|
+
:type resource_group: str
|
|
64
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
65
|
+
server
|
|
66
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
67
|
+
server
|
|
68
|
+
"""
|
|
69
|
+
body = {'execution_id': self.execution_id if self.execution_id else execution_id}
|
|
70
|
+
if artifact_name is not None:
|
|
71
|
+
if not isinstance(artifact_name, str):
|
|
72
|
+
raise AICoreSDKException('Artifact name of type string is expected')
|
|
73
|
+
|
|
74
|
+
artifact_label = {
|
|
75
|
+
'name': "metrics.ai.sap.com/Artifact.name",
|
|
76
|
+
'value': artifact_name
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for metric in metrics:
|
|
80
|
+
if not metric.labels:
|
|
81
|
+
metric.labels = [MetricLabel.from_dict(artifact_label)]
|
|
82
|
+
else:
|
|
83
|
+
metric.labels.append(MetricLabel.from_dict(artifact_label))
|
|
84
|
+
if metrics:
|
|
85
|
+
body['metrics'] = [metric.to_dict() for metric in metrics]
|
|
86
|
+
self.rest_client.patch(path=self.metrics_path, body=body, resource_group=resource_group)
|
|
87
|
+
|
|
88
|
+
def set_custom_info(self, custom_info: List[MetricCustomInfo], execution_id: str = '',
|
|
89
|
+
resource_group: str = None) -> None:
|
|
90
|
+
"""log custom info against the given execution
|
|
91
|
+
captures consumption semantics for the metrics or complex metric in JSON format.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
:param custom_info: List of custom info related to the execution
|
|
95
|
+
:type custom_info: List[class:`ai_api_client_sdk.models.metric_custom_info.MetricCustomInfo`], optional
|
|
96
|
+
:param execution_id: ID of the execution, of which the metrics should be modified.
|
|
97
|
+
:type execution_id: str
|
|
98
|
+
:param resource_group: Resource Group which the request should be sent on behalf. Either this or a default
|
|
99
|
+
resource group in the :class:`ai_api_client_sdk.ai_api_v2_client.AIAPIV2Client` should be specified,
|
|
100
|
+
defaults to None
|
|
101
|
+
:type resource_group: str
|
|
102
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
103
|
+
server
|
|
104
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
105
|
+
server
|
|
106
|
+
"""
|
|
107
|
+
body = {'execution_id': self.execution_id if self.execution_id else execution_id}
|
|
108
|
+
if custom_info:
|
|
109
|
+
body['custom_info'] = [c_info.__dict__ for c_info in custom_info]
|
|
110
|
+
self.rest_client.patch(path=self.metrics_path, body=body, resource_group=resource_group)
|
|
111
|
+
|
|
112
|
+
def set_tags(self, tags: List[MetricTag], execution_id: str = '', resource_group: str = None) -> None:
|
|
113
|
+
"""log tags against the given execution
|
|
114
|
+
|
|
115
|
+
:param tags: List of the tags related to the execution, defaults to None
|
|
116
|
+
:type tags: List[class:'ai_api_client_sdk.models.metric_tag.MetricTag']
|
|
117
|
+
:param execution_id: ID of the execution, of which the metrics should be modified.
|
|
118
|
+
:type execution_id: str
|
|
119
|
+
:param resource_group: Resource Group which the request should be sent on behalf. Either this or a default
|
|
120
|
+
resource group in the :class:`ai_api_client_sdk.ai_api_v2_client.AIAPIV2Client` should be specified,
|
|
121
|
+
defaults to None
|
|
122
|
+
:type resource_group: str
|
|
123
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIInvalidRequestException` if a 400 response is received from the
|
|
124
|
+
server
|
|
125
|
+
:raises: class:`ai_api_client_sdk.exception.AIAPIServerException` if a non-2XX response is received from the
|
|
126
|
+
server
|
|
127
|
+
"""
|
|
128
|
+
body = {'execution_id': self.execution_id if self.execution_id else execution_id}
|
|
129
|
+
if tags:
|
|
130
|
+
body['tags'] = [tag.__dict__ for tag in tags]
|
|
131
|
+
self.rest_client.patch(path=self.metrics_path, body=body, resource_group=resource_group)
|