Skip to content

Commit 52f58fb

Browse files
author
Thibaud Baas
committed
FM: Split client by cloud
1 parent 6a5ee56 commit 52f58fb

File tree

3 files changed

+125
-61
lines changed

3 files changed

+125
-61
lines changed

dataikuapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .dssclient import DSSClient
2-
from .fmclient import FMClient
2+
from .fmclient import FMClientAWS, FMClientAzure
33

44
from .apinode_client import APINodeClient
55
from .apinode_admin_client import APINodeAdminClient

dataikuapi/fm/virtualnetworks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create(self):
6969

7070

7171
class FMAzureVirtualNetworkCreator(FMVirtualNetworkCreator):
72-
def with_virtual_network(self, azure_vn_id, azure_subnet_id):
72+
def with_azure_virtual_network(self, azure_vn_id, azure_subnet_id):
7373
"""
7474
Setup the Azure Virtual Network and Subnet to with the VirtualNetwork
7575

dataikuapi/fmclient.py

Lines changed: 123 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,25 @@
2727

2828

2929
class FMClient(object):
30-
"""Entry point for the FM API client"""
31-
3230
def __init__(
3331
self,
3432
host,
3533
api_key_id,
3634
api_key_secret,
37-
cloud,
3835
tenant_id="main",
3936
extra_headers=None,
4037
):
4138
"""
42-
Instantiate a new FM API client on the given host with the given API key.
43-
44-
API keys can be managed in FM on the project page or in the global settings.
45-
46-
The API key will define which operations are allowed for the client.
47-
48-
:param str host: Full url of the FM
49-
39+
Base class for the different FM Clients
40+
Do not create this class, instead use :class:`dataikuapi.FMClientAWS` or :class:`dataikuapi.FMClientAzure`
5041
"""
42+
if self.cloud == None:
43+
raise NotImplementedError(
44+
"Do not use FMClient directly, instead use FMClientAWS or FMClientAzure"
45+
)
5146
self.api_key_id = api_key_id
5247
self.api_key_secret = api_key_secret
5348
self.host = host
54-
if cloud not in ["AWS", "Azure"]:
55-
raise ValueError('cloud should be either "AWS" or "Azure"')
56-
self.cloud = cloud
5749
self.__tenant_id = tenant_id
5850
self._session = Session()
5951

@@ -107,18 +99,6 @@ def get_virtual_network(self, virtual_network_id):
10799
)
108100
return FMVirtualNetwork(self, vn)
109101

110-
def new_virtual_network_creator(self, label):
111-
"""
112-
Instantiate a new virtual network creator
113-
114-
:param str label: The label of the
115-
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMVirtualNetworkCreator`
116-
"""
117-
if self.cloud == "AWS":
118-
return FMAWSVirtualNetworkCreator(self, label)
119-
elif self.cloud == "Azure":
120-
return FMAzureVirtualNetworkCreator(self, label)
121-
122102
########################################################
123103
# Instance settings template
124104
########################################################
@@ -147,18 +127,6 @@ def get_instance_template(self, template_id):
147127
)
148128
return FMInstanceSettingsTemplate(self, template)
149129

150-
def new_instance_template_creator(self, label):
151-
"""
152-
Instantiate a new instance template creator
153-
154-
:param str label: The label of the instance
155-
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMInstanceSettingsTemplateCreator`
156-
"""
157-
if self.cloud == "AWS":
158-
return FMAWSInstanceSettingsTemplateCreator(self, label)
159-
elif self.cloud == "Azure":
160-
return FMAzureInstanceSettingsTemplateCreator(self, label)
161-
162130
########################################################
163131
# Instance
164132
########################################################
@@ -185,27 +153,6 @@ def get_instance(self, instance_id):
185153
instance = self._perform_tenant_json("GET", "/instances/%s" % instance_id)
186154
return FMInstance(self, instance)
187155

188-
def new_instance_creator(
189-
self, label, instance_settings_template_id, virtual_network_id, image_id
190-
):
191-
"""
192-
Instantiate a new instance creator
193-
194-
:param str label: The label of the instance
195-
:param str instance_settings_template: The instance settings template id this instance should be based on
196-
:param str virtual_network: The virtual network where the instance should be spawned
197-
:param str image_id: The ID of the DSS runtime image (ex: dss-9.0.3-default)
198-
:rtype: :class:`dataikuapi.fm.instances.FMInstanceCreator`
199-
"""
200-
if self.cloud == "AWS":
201-
return FMAWSInstanceCreator(
202-
self, label, instance_settings_template_id, virtual_network_id, image_id
203-
)
204-
elif self.cloud == "Azure":
205-
return FMAzureInstanceCreator(
206-
self, label, instance_settings_template_id, virtual_network_id, image_id
207-
)
208-
209156
########################################################
210157
# Internal Request handling
211158
########################################################
@@ -297,3 +244,120 @@ def _perform_tenant_empty(
297244
files=files,
298245
raw_body=raw_body,
299246
)
247+
248+
249+
class FMClientAWS(FMClient):
250+
def __init__(
251+
self,
252+
host,
253+
api_key_id,
254+
api_key_secret,
255+
tenant_id="main",
256+
extra_headers=None,
257+
):
258+
"""
259+
AWS Only - Instantiate a new FM API client on the given host with the given API key.
260+
261+
API keys can be managed in FM on the project page or in the global settings.
262+
263+
The API key will define which operations are allowed for the client.
264+
265+
:param str host: Full url of the FM
266+
267+
"""
268+
self.cloud = "AWS"
269+
super(FMClientAWS, self).__init__(
270+
host, api_key_id, api_key_secret, tenant_id, extra_headers
271+
)
272+
273+
def new_virtual_network_creator(self, label):
274+
"""
275+
Instantiate a new virtual network creator
276+
277+
:param str label: The label of the
278+
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMAWSVirtualNetworkCreator`
279+
"""
280+
return FMAWSVirtualNetworkCreator(self, label)
281+
282+
def new_instance_template_creator(self, label):
283+
"""
284+
Instantiate a new instance template creator
285+
286+
:param str label: The label of the instance
287+
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMAWSInstanceSettingsTemplateCreator`
288+
"""
289+
return FMAWSInstanceSettingsTemplateCreator(self, label)
290+
291+
def new_instance_creator(
292+
self, label, instance_settings_template_id, virtual_network_id, image_id
293+
):
294+
"""
295+
Instantiate a new instance creator
296+
297+
:param str label: The label of the instance
298+
:param str instance_settings_template: The instance settings template id this instance should be based on
299+
:param str virtual_network: The virtual network where the instance should be spawned
300+
:param str image_id: The ID of the DSS runtime image (ex: dss-9.0.3-default)
301+
:rtype: :class:`dataikuapi.fm.instances.FMAWSInstanceCreator`
302+
"""
303+
return FMAWSInstanceCreator(
304+
self, label, instance_settings_template_id, virtual_network_id, image_id
305+
)
306+
307+
308+
class FMClientAzure(FMClient):
309+
def __init__(
310+
self,
311+
host,
312+
api_key_id,
313+
api_key_secret,
314+
tenant_id="main",
315+
extra_headers=None,
316+
):
317+
"""
318+
Azure Only - Instantiate a new FM API client on the given host with the given API key.
319+
320+
API keys can be managed in FM on the project page or in the global settings.
321+
322+
The API key will define which operations are allowed for the client.
323+
324+
:param str host: Full url of the FM
325+
"""
326+
self.cloud = "Azure"
327+
super(FMClientAWS, self).__init__(
328+
host, api_key_id, api_key_secret, tenant_id, extra_headers
329+
)
330+
331+
def new_virtual_network_creator(self, label):
332+
"""
333+
Instantiate a new virtual network creator
334+
335+
:param str label: The label of the
336+
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMAzureVirtualNetworkCreator`
337+
"""
338+
return FMAzureVirtualNetworkCreator(self, label)
339+
340+
def new_instance_template_creator(self, label):
341+
"""
342+
Instantiate a new instance template creator
343+
344+
:param str label: The label of the instance
345+
:rtype: :class:`dataikuapi.fm.instancesettingstemplates.FMAzureInstanceSettingsTemplateCreator`
346+
"""
347+
return FMAzureInstanceSettingsTemplateCreator(self, label)
348+
349+
def new_instance_creator(
350+
self, label, instance_settings_template_id, virtual_network_id, image_id
351+
):
352+
"""
353+
Instantiate a new instance creator
354+
355+
:param str label: The label of the instance
356+
:param str instance_settings_template: The instance settings template id this instance should be based on
357+
:param str virtual_network: The virtual network where the instance should be spawned
358+
:param str image_id: The ID of the DSS runtime image (ex: dss-9.0.3-default)
359+
:rtype: :class:`dataikuapi.fm.instances.FMAzureInstanceCreator`
360+
"""
361+
return FMAzureInstanceCreator(
362+
self, label, instance_settings_template_id, virtual_network_id, image_id
363+
)

0 commit comments

Comments
 (0)