Skip to content

Commit 0e9e58c

Browse files
FChataignerlpenet
authored andcommitted
type returned objects to the appropriate subclass
1 parent e7b1f5a commit 0e9e58c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

dataikuapi/fmclient.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
FMVirtualNetwork,
1313
FMAWSVirtualNetworkCreator,
1414
FMAzureVirtualNetworkCreator,
15+
FMAWSVirtualNetwork,
16+
FMAzureVirtualNetwork
1517
)
1618
from .fm.instances import (
1719
FMInstance,
1820
FMInstanceEncryptionMode,
1921
FMAWSInstanceCreator,
2022
FMAzureInstanceCreator,
23+
FMAWSInstance,
24+
FMAzureInstance
2125
)
2226
from .fm.instancesettingstemplates import (
2327
FMInstanceSettingsTemplate,
@@ -87,6 +91,14 @@ def get_cloud_tags(self, tenant_id):
8791
# VirtualNetwork
8892
########################################################
8993

94+
def _make_virtual_network(self, vn):
95+
if self.cloud == 'AWS':
96+
return FMAWSVirtualNetwork(self, vn)
97+
elif self.cloud == 'Azure':
98+
return FMAzureVirtualNetwork(self, vn)
99+
else:
100+
raise Exception("Unknown cloud type %s" % self.cloud)
101+
90102
def list_virtual_networks(self):
91103
"""
92104
List all Virtual Networks
@@ -95,7 +107,7 @@ def list_virtual_networks(self):
95107
:rtype: list of :class:`dataikuapi.fm.virtualnetworks.FMVirtualNetwork`
96108
"""
97109
vns = self._perform_tenant_json("GET", "/virtual-networks")
98-
return [FMVirtualNetwork(self, x) for x in vns]
110+
return [self._make_virtual_network(x) for x in vns]
99111

100112
def get_virtual_network(self, virtual_network_id):
101113
"""
@@ -109,7 +121,7 @@ def get_virtual_network(self, virtual_network_id):
109121
vn = self._perform_tenant_json(
110122
"GET", "/virtual-networks/%s" % virtual_network_id
111123
)
112-
return FMVirtualNetwork(self, vn)
124+
return self._make_virtual_network(vn)
113125

114126
########################################################
115127
# Instance settings template
@@ -143,6 +155,14 @@ def get_instance_template(self, template_id):
143155
# Instance
144156
########################################################
145157

158+
def _make_instance(self, i):
159+
if self.cloud == 'AWS':
160+
return FMAWSInstance(self, i)
161+
elif self.cloud == 'Azure':
162+
return FMAzureInstance(self, i)
163+
else:
164+
raise Exception("Unknown cloud type %s" % self.cloud)
165+
146166
def list_instances(self):
147167
"""
148168
List all DSS Instances
@@ -151,7 +171,7 @@ def list_instances(self):
151171
:rtype: list of :class:`dataikuapi.fm.instances.FMInstance`
152172
"""
153173
instances = self._perform_tenant_json("GET", "/instances")
154-
return [FMInstance(self, **x) for x in instances]
174+
return [self._make_instance(x) for x in instances]
155175

156176
def get_instance(self, instance_id):
157177
"""
@@ -163,7 +183,7 @@ def get_instance(self, instance_id):
163183
:rtype: :class:`dataikuapi.fm.instances.FMInstance`
164184
"""
165185
instance = self._perform_tenant_json("GET", "/instances/%s" % instance_id)
166-
return FMInstance(self, instance)
186+
return self._make_instance(instance)
167187

168188
########################################################
169189
# Internal Request handling

0 commit comments

Comments
 (0)