Skip to content

Commit 234341e

Browse files
author
Thibaud Baas
committed
FM: InstanceSettingsTemplate format + doc
1 parent 1de0927 commit 234341e

File tree

1 file changed

+116
-52
lines changed

1 file changed

+116
-52
lines changed

dataikuapi/fm/instancesettingstemplates.py

Lines changed: 116 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22
import json
33
from dataikuapi.fm.future import FMFuture
44

5+
56
class FMInstanceSettingsTemplateCreator(object):
67
def __init__(self, client, label):
78
"""
8-
Create an Instance Template
9-
10-
:param str azureSshKey: Optional, Azure Only, the ssh public key to add to the instance. Needed to get SSH access to the DSS instance, using the centos user.
11-
:param str startupManagedIdentity: Optional, Azure Only, the managed identity assigned to the DSS instance at startup time
12-
:param str runtimeManagedIdentity: Optional, Azure Only, the managed identity assigned to the DSS instance at runtime
9+
A builder class to create an Instance Settings Template
1310
14-
:return: requested instance settings template
15-
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMInstanceSettingsTemplate`
11+
:param str label: The label of the Virtual Network
1612
"""
1713

1814
self.data = {}
1915
self.data["label"] = label
2016
self.client = client
2117

2218
def create(self):
23-
template = self.client._perform_tenant_json("POST", "/instance-settings-templates", body=self.data)
19+
"""
20+
Create the Instance Settings Template
21+
22+
:return: Created InstanceSettingsTemplate
23+
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMInstanceSettingsTemplate`
24+
"""
25+
26+
template = self.client._perform_tenant_json(
27+
"POST", "/instance-settings-templates", body=self.data
28+
)
2429
return FMInstanceSettingsTemplate(self, template)
2530

2631
def with_setup_actions(self, setup_actions):
@@ -67,13 +72,17 @@ def with_runtime_instance_profile(self, runtime_instance_profile_arn):
6772
self.data["runtimeInstanceProfileArn"] = runtime_instance_profile_arn
6873
return self
6974

70-
def with_restrict_aws_metadata_server_access(self, restrict_aws_metadata_server_access = True):
75+
def with_restrict_aws_metadata_server_access(
76+
self, restrict_aws_metadata_server_access=True
77+
):
7178
"""
7279
Restrict AWS metadata server access on the DSS instance.
7380
7481
:param boolean restrict_aws_metadata_server_access: Optional, If true, restrict the access to the metadata server access. Defaults to true
7582
"""
76-
self.data["restrictAwsMetadataServerAccess"] = restrict_aws_metadata_server_access
83+
self.data[
84+
"restrictAwsMetadataServerAccess"
85+
] = restrict_aws_metadata_server_access
7786
return self
7887

7988
def with_default_aws_api_access_mode(self):
@@ -83,7 +92,14 @@ def with_default_aws_api_access_mode(self):
8392
self.data["dataikuAwsAPIAccessMode"] = "NONE"
8493
return self
8594

86-
def with_keypair_aws_api_access_mode(self, aws_access_key_id, aws_keypair_storage_mode="NONE", aws_secret_access_key=None, aws_secret_access_key_aws_secret_name=None, aws_secrets_manager_region=None):
95+
def with_keypair_aws_api_access_mode(
96+
self,
97+
aws_access_key_id,
98+
aws_keypair_storage_mode="NONE",
99+
aws_secret_access_key=None,
100+
aws_secret_access_key_aws_secret_name=None,
101+
aws_secrets_manager_region=None,
102+
):
87103
"""
88104
DSS Instance will use an Access Key to authenticate against the AWS API.
89105
@@ -93,8 +109,14 @@ def with_keypair_aws_api_access_mode(self, aws_access_key_id, aws_keypair_storag
93109
:param str aws_secret_access_key_aws_secret_name: Optional, ASM secret name. Only needed if aws_keypair_storage_mode is "AWS_SECRET_MANAGER"
94110
:param str aws_secrets_manager_region: Optional, Secret Manager region to use. Only needed if aws_keypair_storage_mode is "AWS_SECRET_MANAGER"
95111
"""
96-
if aws_keypair_storage_mode not in ["NONE", "INLINE_ENCRYPTED", "AWS_SECRETS_MANAGER"]:
97-
raise ValueError("aws_keypair_storage_mode should be either \"NONE\", \"INLINE_ENCRYPTED\" or \"AWS_SECRET_MANAGER\"")
112+
if aws_keypair_storage_mode not in [
113+
"NONE",
114+
"INLINE_ENCRYPTED",
115+
"AWS_SECRETS_MANAGER",
116+
]:
117+
raise ValueError(
118+
'aws_keypair_storage_mode should be either "NONE", "INLINE_ENCRYPTED" or "AWS_SECRET_MANAGER"'
119+
)
98120

99121
self.data["dataikuAwsAPIAccessMode"] = "KEYPAIR"
100122
self.data["dataikuAwsKeypairStorageMode"] = aws_keypair_storage_mode
@@ -106,12 +128,18 @@ def with_keypair_aws_api_access_mode(self, aws_access_key_id, aws_keypair_storag
106128

107129
if aws_keypair_storage_mode == "INLINE_ENCRYPTED":
108130
if aws_secret_access_key == None:
109-
raise ValueError("When aws_keypair_storage_mode is \"INLINE_ENCRYPTED\", aws_secret_access_key should be provided")
131+
raise ValueError(
132+
'When aws_keypair_storage_mode is "INLINE_ENCRYPTED", aws_secret_access_key should be provided'
133+
)
110134
self.data["dataikuAwsSecretAccessKey"] = aws_secret_access_key
111135
elif aws_keypair_storage_mode == "AWS_SECRETS_MANAGER":
112136
if aws_secret_access_key_aws_secret_name == None:
113-
raise ValueError("When aws_keypair_storage_mode is \"AWS_SECRETS_MANAGER\", aws_secret_access_key_aws_secret_name should be provided")
114-
self.data["dataikuAwsSecretAccessKeyAwsSecretName"] = aws_secret_access_key_aws_secret_name
137+
raise ValueError(
138+
'When aws_keypair_storage_mode is "AWS_SECRETS_MANAGER", aws_secret_access_key_aws_secret_name should be provided'
139+
)
140+
self.data[
141+
"dataikuAwsSecretAccessKeyAwsSecretName"
142+
] = aws_secret_access_key_aws_secret_name
115143
self.data["awsSecretsManagerRegion"] = aws_secrets_manager_region
116144

117145
return self
@@ -149,16 +177,20 @@ def with_runtime_managed_identity(self, runtime_managed_identity):
149177

150178
class FMInstanceSettingsTemplate(object):
151179
def __init__(self, client, ist_data):
152-
self.client = client
153-
self.id = ist_data['id']
180+
self.client = client
181+
self.id = ist_data["id"]
154182
self.ist_data = ist_data
155183

156184
def save(self):
157185
"""
158186
Update the Instance Settings Template.
159187
"""
160-
self.client._perform_tenant_empty("PUT", "/instance-settings-templates/%s" % self.id, body=self.ist_data)
161-
self.ist_data = self.client._perform_tenant_json("GET", "/instance-settings-templates/%s" % self.id)
188+
self.client._perform_tenant_empty(
189+
"PUT", "/instance-settings-templates/%s" % self.id, body=self.ist_data
190+
)
191+
self.ist_data = self.client._perform_tenant_json(
192+
"GET", "/instance-settings-templates/%s" % self.id
193+
)
162194

163195
def delete(self):
164196
"""
@@ -167,7 +199,9 @@ def delete(self):
167199
:return: A :class:`~dataikuapi.fm.future.FMFuture` representing the deletion process
168200
:rtype: :class:`~dataikuapi.fm.future.FMFuture`
169201
"""
170-
future = self.client._perform_tenant_json("DELETE", "/instance-settings-templates/%s" % self.id)
202+
future = self.client._perform_tenant_json(
203+
"DELETE", "/instance-settings-templates/%s" % self.id
204+
)
171205
return FMFuture.from_resp(self.client, future)
172206

173207
def add_setup_action(self, setup_action):
@@ -176,7 +210,7 @@ def add_setup_action(self, setup_action):
176210
177211
:param object setup_action: a :class:`dataikuapi.fm.instancesettingstemplates.FMSetupAction`
178212
"""
179-
self.ist_data['setupActions'].append(setup_action)
213+
self.ist_data["setupActions"].append(setup_action)
180214
self.save()
181215

182216

@@ -193,7 +227,7 @@ def __init__(self, setupActionType, params=None):
193227
"type": setupActionType.value,
194228
}
195229
if params:
196-
data['params'] = params
230+
data["params"] = params
197231

198232
super(FMSetupAction, self).__init__(data)
199233

@@ -202,7 +236,7 @@ def add_authorized_key(ssh_key):
202236
"""
203237
Return a ADD_AUTHORIZED_KEY FMSetupAction
204238
"""
205-
return FMSetupAction(FMSetupActionType.ADD_AUTHORIZED_KEY, {"sshKey": ssh_key })
239+
return FMSetupAction(FMSetupActionType.ADD_AUTHORIZED_KEY, {"sshKey": ssh_key})
206240

207241
@staticmethod
208242
def run_ansible_task(stage, yaml_string):
@@ -212,7 +246,10 @@ def run_ansible_task(stage, yaml_string):
212246
:param object stage: a :class:`dataikuapi.fm.instancesettingstemplates.FMSetupActionStage`
213247
:param str yaml_string: a yaml encoded string defining the ansibles tasks to run
214248
"""
215-
return FMSetupAction(FMSetupActionType.RUN_ANSIBLE_TASKS, {"stage": stage.value, "ansibleTasks": yaml_string })
249+
return FMSetupAction(
250+
FMSetupActionType.RUN_ANSIBLE_TASKS,
251+
{"stage": stage.value, "ansibleTasks": yaml_string},
252+
)
216253

217254
@staticmethod
218255
def install_system_packages(packages):
@@ -221,20 +258,33 @@ def install_system_packages(packages):
221258
222259
:param list packages: List of packages to install
223260
"""
224-
return FMSetupAction(FMSetupActionType.INSTALL_SYSTEM_PACKAGES, {"packages": packages })
261+
return FMSetupAction(
262+
FMSetupActionType.INSTALL_SYSTEM_PACKAGES, {"packages": packages}
263+
)
225264

226265
@staticmethod
227-
def setup_advanced_security(basic_headers = True, hsts = False):
266+
def setup_advanced_security(basic_headers=True, hsts=False):
228267
"""
229268
Return an SETUP_ADVANCED_SECURITY FMSetupAction
230269
231270
:param boolean basic_headers: Optional, Prevent browsers to render Web content served by DSS to be embedded into a frame, iframe, embed or object tag. Defaults to True
232271
:param boolean hsts: Optional, Enforce HTTP Strict Transport Security. Defaults to False
233272
"""
234-
return FMSetupAction(FMSetupActionType.SETUP_ADVANCED_SECURITY, {"basic_headers": basic_headers, "hsts": hsts})
273+
return FMSetupAction(
274+
FMSetupActionType.SETUP_ADVANCED_SECURITY,
275+
{"basic_headers": basic_headers, "hsts": hsts},
276+
)
235277

236278
@staticmethod
237-
def install_jdbc_driver(database_type, url, paths_in_archive=None, http_headers=None, http_username=None, http_password=None, datadir_subdirectory=None):
279+
def install_jdbc_driver(
280+
database_type,
281+
url,
282+
paths_in_archive=None,
283+
http_headers=None,
284+
http_username=None,
285+
http_password=None,
286+
datadir_subdirectory=None,
287+
):
238288
"""
239289
Return a INSTALL_JDBC_DRIVER FMSetupAction
240290
@@ -246,7 +296,18 @@ def install_jdbc_driver(database_type, url, paths_in_archive=None, http_headers=
246296
:param str http_password: Optional, If the HTTP(S) endpoint expect a Basic Authentication, add here the password. To authenticate with a SAS Token on Azure Blob Storage (not recommended), store the token in this field.
247297
:param str datadir_subdirectory: Optional, Some drivers are shipped with a high number of JAR files along with them. In that case, you might want to install them under an additional level in the DSS data directory. Set the name of this subdirectory here. Not required for most drivers.
248298
"""
249-
return FMSetupAction(FMSetupActionType.INSTALL_JDBC_DRIVER, {"url": url, "dbType": database_type.value, "pathsInArchive": paths_in_archive, "headers": http_headers, "username": http_username, "password": http_password, "subpathInDatadir": datadir_subdirectory})
299+
return FMSetupAction(
300+
FMSetupActionType.INSTALL_JDBC_DRIVER,
301+
{
302+
"url": url,
303+
"dbType": database_type.value,
304+
"pathsInArchive": paths_in_archive,
305+
"headers": http_headers,
306+
"username": http_username,
307+
"password": http_password,
308+
"subpathInDatadir": datadir_subdirectory,
309+
},
310+
)
250311

251312
@staticmethod
252313
def setup_k8s_and_spark():
@@ -255,30 +316,33 @@ def setup_k8s_and_spark():
255316
"""
256317
return FMSetupAction(FMSetupActionType.SETUP_K8S_AND_SPARK)
257318

319+
258320
class FMSetupActionType(Enum):
259-
RUN_ANSIBLE_TASKS="RUN_ANSIBLE_TASKS"
260-
INSTALL_SYSTEM_PACKAGES="INSTALL_SYSTEM_PACKAGES"
261-
INSTALL_DSS_PLUGINS_FROM_STORE="INSTALL_DSS_PLUGINS_FROM_STORE"
262-
SETUP_K8S_AND_SPARK="SETUP_K8S_AND_SPARK"
263-
SETUP_RUNTIME_DATABASE="SETUP_RUNTIME_DATABASE"
264-
SETUP_MUS_AUTOCREATE="SETUP_MUS_AUTOCREATE"
265-
SETUP_UI_CUSTOMIZATION="SETUP_UI_CUSTOMIZATION"
266-
SETUP_MEMORY_SETTINGS="SETUP_MEMORY_SETTINGS"
267-
SETUP_GRAPHICS_EXPORT="SETUP_GRAPHICS_EXPORT"
268-
ADD_AUTHORIZED_KEY="ADD_AUTHORIZED_KEY"
269-
INSTALL_JDBC_DRIVER="INSTALL_JDBC_DRIVER"
270-
SETUP_ADVANCED_SECURITY="SETUP_ADVANCED_SECURITY"
321+
RUN_ANSIBLE_TASKS = "RUN_ANSIBLE_TASKS"
322+
INSTALL_SYSTEM_PACKAGES = "INSTALL_SYSTEM_PACKAGES"
323+
INSTALL_DSS_PLUGINS_FROM_STORE = "INSTALL_DSS_PLUGINS_FROM_STORE"
324+
SETUP_K8S_AND_SPARK = "SETUP_K8S_AND_SPARK"
325+
SETUP_RUNTIME_DATABASE = "SETUP_RUNTIME_DATABASE"
326+
SETUP_MUS_AUTOCREATE = "SETUP_MUS_AUTOCREATE"
327+
SETUP_UI_CUSTOMIZATION = "SETUP_UI_CUSTOMIZATION"
328+
SETUP_MEMORY_SETTINGS = "SETUP_MEMORY_SETTINGS"
329+
SETUP_GRAPHICS_EXPORT = "SETUP_GRAPHICS_EXPORT"
330+
ADD_AUTHORIZED_KEY = "ADD_AUTHORIZED_KEY"
331+
INSTALL_JDBC_DRIVER = "INSTALL_JDBC_DRIVER"
332+
SETUP_ADVANCED_SECURITY = "SETUP_ADVANCED_SECURITY"
333+
271334

272335
class FMSetupActionStage(Enum):
273-
after_dss_startup="after_dss_startup"
274-
after_install="after_install"
275-
before_install="before_install"
336+
after_dss_startup = "after_dss_startup"
337+
after_install = "after_install"
338+
before_install = "before_install"
339+
276340

277341
class FMSetupActionAddJDBCDriverDatabaseType(Enum):
278-
mysql="mysql"
279-
mssql="mssql"
280-
oracle="oracle"
281-
mariadb="mariadb"
282-
snowflake="snowflake"
283-
athena="athena"
284-
bigquery="bigquery"
342+
mysql = "mysql"
343+
mssql = "mssql"
344+
oracle = "oracle"
345+
mariadb = "mariadb"
346+
snowflake = "snowflake"
347+
athena = "athena"
348+
bigquery = "bigquery"

0 commit comments

Comments
 (0)