-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathapinode_admin_client.py
126 lines (102 loc) · 4.29 KB
/
apinode_admin_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import json
import warnings
from .apinode_admin.service import APINodeService
from .apinode_admin.auth import APINodeAuth
from .utils import DataikuException
from .base_client import DSSBaseClient
class APINodeAdminClient(DSSBaseClient):
"""Entry point for the DSS APINode admin client"""
def __init__(self, uri, api_key, no_check_certificate=False, **kwargs):
"""
Instantiate a new DSS API client on the given base uri with the given API key.
"""
if "insecure_tls" in kwargs:
# Backward compatibility before removing insecure_tls option
warnings.warn("insecure_tls field is now deprecated. It has been replaced by no_check_certificate.", DeprecationWarning)
no_check_certificate = kwargs.get("insecure_tls") or no_check_certificate
DSSBaseClient.__init__(self, "%s/%s" % (uri, "admin/api"), api_key, no_check_certificate=no_check_certificate)
########################################################
# Services generations
########################################################
def create_service(self, service_id):
"""
Creates a new API service
:param service_id: id of the created API service
"""
self._perform_empty("POST", "services/", body = {
"serviceId" : service_id
})
def list_services(self):
"""
Lists the currently declared services and their enabled/disabled state
:return: a dict of services containing their id and state, as a JSON object
:rtype: dict
"""
return self._perform_json("GET", "services")
def service(self, service_id):
"""
Gets a handle to interact with a service
:param service_id: id of requested service
:rtype: :class: `dataikuapi.apinode_admin.service.APINodeService`
"""
return APINodeService(self, service_id)
def auth(self):
"""
Returns a handle to interact with authentication
:rtype: :class: `dataikuapi.apinode_admin.auth.APINodeAuth`
"""
return APINodeAuth(self)
def get_metrics(self):
"""
Get the metrics for this API Node
:return: the metrics, as a JSON object
:rtype: dict
"""
return self._perform_json("GET", "metrics")
def import_code_env_in_cache(self, file_dir, language):
"""
Import a code env in global cache from an exported code env base folder
:param file_dir: path of an exported code env base folder
:param language: language of the code env (`python` or `R`)
"""
return self._perform_json("POST", "cached-code-envs", params={
"fileDir": file_dir,
"language": language
})
def register_code_env_in_cache(self, exported_env_dir, built_env_dir, language):
"""
Import a code env in global cache from an exported code env base folder
:param exported_env_dir: path of an exported code env base folder
:param built_env_dir: path where the code env was built and is available
:param language: language of the code env (`python` or `R`)
"""
return self._perform_json("POST", "register-global-code-env", params={
"exportedEnvDir": exported_env_dir,
"builtEnvDir": built_env_dir,
"language": language
})
def import_model_archive_in_cache(self, model_archive_path):
"""
Import a model in model cache from an exported model archive
:param model_archive_path: path of an exported model archive
"""
return self._perform_json("POST", "model-cache", params={
"modelArchivePath": model_archive_path
})
def clear_model_cache(self):
"""
Clear the model cache
"""
self._perform_empty("DELETE", "model-cache")
def clean_unused_services_and_generations(self):
"""
Deletes disabled services, unused generations and unused code environments
"""
resp = self._perform_json("DELETE", "services-clean-unused")
print(json.dumps(resp, indent=4))
def clean_code_env_cache(self):
"""
Deletes unused code envs from cache
"""
resp = self._perform_json("DELETE", "cached-code-envs")
print(json.dumps(resp, indent=4))