Skip to content

Commit 919d959

Browse files
authored
Merge pull request #178 from dataiku/task/fm-papi-additions
Task/fm papi additions
2 parents 05dd3e4 + 237f9f5 commit 919d959

File tree

3 files changed

+143
-2
lines changed

3 files changed

+143
-2
lines changed

dataikuapi/fm/instances.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,44 @@ def delete(self):
237237
)
238238
return FMFuture.from_resp(self.client, future)
239239

240+
def get_initial_password(self):
241+
"""
242+
Get the initial DSS admin password.
243+
244+
Can only be called once
245+
246+
:return: a password for the 'admin' user.
247+
"""
248+
return self.client._perform_tenant_json(
249+
"GET", "/instances/%s/actions/get-initial-password" % self.id
250+
)
251+
252+
def reset_user_password(self, username, password):
253+
"""
254+
Reset the password for a user on the DSS instance
255+
256+
:param string username: login
257+
:param string password: new password
258+
:return: A :class:`~dataikuapi.fm.future.FMFuture` representing the password reset process
259+
:rtype: :class:`~dataikuapi.fm.future.FMFuture`
260+
"""
261+
future = self.client._perform_tenant_json(
262+
"GET", "/instances/%s/actions/reset-user-password" % self.id, params={ 'userName':username, 'password':password }
263+
)
264+
return FMFuture.from_resp(self.client, future)
265+
266+
def replay_setup_actions(self):
267+
"""
268+
Replay the setup actions on the DSS instance
269+
270+
:return: A :class:`~dataikuapi.fm.future.FMFuture` representing the replay process
271+
:rtype: :class:`~dataikuapi.fm.future.FMFuture`
272+
"""
273+
future = self.client._perform_tenant_json(
274+
"GET", "/instances/%s/actions/replay-setup-actions" % self.id
275+
)
276+
return FMFuture.from_resp(self.client, future)
277+
240278
def set_automated_snapshots(self, enable, period, keep=0):
241279
"""
242280
Set the automated snapshots policy for this instance
@@ -262,6 +300,43 @@ def set_custom_certificate(self, pem_data):
262300
return self
263301

264302

303+
########################################################
304+
# Snapshots
305+
########################################################
306+
307+
def list_snapshots(self):
308+
"""
309+
List all snapshots of this instance
310+
311+
:return: list of snapshots
312+
:rtype: list of :class:`dataikuapi.fm.instances.FMSnapshot`
313+
"""
314+
snapshots = self.client._perform_tenant_json("GET", "/instances/%s/snapshots" % self.id)
315+
return [FMSnapshot(self.client, self.id, x["id"], x) for x in snapshots]
316+
317+
def get_snapshot(self, snapshot_id):
318+
"""
319+
Get a snapshot of this instance
320+
321+
:param str snapshot_id: identifier of the snapshot
322+
323+
:return: Snapshot
324+
:rtype: :class:`dataikuapi.fm.instances.FMSnapshot`
325+
"""
326+
return FMSnapshot(self.client, self.id, snapshot_id)
327+
328+
def snapshot(self, reason_for_snapshot=None):
329+
"""
330+
Create a snapshot of the DSS instance
331+
332+
:return: Snapshot
333+
:rtype: :class:`dataikuapi.fm.instances.FMSnapshot`
334+
"""
335+
snapshot = self.client._perform_tenant_json(
336+
"POST", "/instances/%s/snapshots" % self.id, params={ "reasonForSnapshot":reason_for_snapshot }
337+
)
338+
return FMSnapshot(self.client, self.id, snapshot["id"], snapshot)
339+
265340
class FMAWSInstance(FMInstance):
266341
def set_elastic_ip(self, enable, elasticip_allocation_id):
267342
"""
@@ -303,3 +378,53 @@ class FMInstanceStatus(dict):
303378
def __init__(self, data):
304379
"""Do not call this directly, use :meth:`FMInstance.get_status`"""
305380
super(FMInstanceStatus, self).__init__(data)
381+
382+
383+
class FMSnapshot(object):
384+
"""
385+
A handle to interact with a snapshot of a DSS instance.
386+
Do not create this directly, use :meth:`FMInstance.snapshot`
387+
"""
388+
389+
def __init__(self, client, instance_id, snapshot_id, snapshot_data=None):
390+
self.client = client
391+
self.instance_id = instance_id
392+
self.snapshot_id = snapshot_id
393+
self.snapshot_data = snapshot_data
394+
395+
def get_info(self):
396+
"""
397+
Get the information about this snapshot
398+
399+
:return: a dict
400+
"""
401+
if self.snapshot_data is None:
402+
self.snapshot_data = self.client._perform_tenant_json(
403+
"GET", "/instances/%s/snapshots/%s" % (self.instance_id, self.snapshot_id)
404+
)
405+
return self.snapshot_data
406+
407+
def reprovision(self):
408+
"""
409+
Reprovision the physical DSS instance from this snapshot
410+
411+
:return: A :class:`~dataikuapi.fm.future.FMFuture` representing the reprovision process
412+
:rtype: :class:`~dataikuapi.fm.future.FMFuture`
413+
"""
414+
future = self.client._perform_tenant_json(
415+
"POST", "/instances/%s/snapshots/%s/reprovision" % (self.instance_id, self.snapshot_id)
416+
)
417+
return FMFuture.from_resp(self.client, future)
418+
419+
def delete(self):
420+
"""
421+
Delete the snapshot
422+
423+
:return: A :class:`~dataikuapi.fm.future.FMFuture` representing the deletion process
424+
:rtype: :class:`~dataikuapi.fm.future.FMFuture`
425+
"""
426+
future = self.client._perform_tenant_json(
427+
"DELETE", "/instances/%s/snapshots/%s" % (self.instance_id, self.snapshot_id)
428+
)
429+
return FMFuture.from_resp(self.client, future)
430+

dataikuapi/fm/virtualnetworks.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def __init__(self, client, label):
1010
"""
1111
self.client = client
1212
self.data = {}
13+
self.use_default_values = False
1314
self.data["label"] = label
1415
self.data["mode"] = "EXISTING_MONOTENANT"
1516

@@ -25,6 +26,13 @@ def with_internet_access_mode(self, internet_access_mode):
2526
self.data["internetAccessMode"] = internet_access_mode
2627
return self
2728

29+
def with_default_values(self):
30+
"""
31+
Setup the VPC and Subnet to with the default values: the vpc and subnet of the FM instance
32+
"""
33+
self.use_default_values = True
34+
return self
35+
2836

2937
class FMAWSVirtualNetworkCreator(FMVirtualNetworkCreator):
3038
def with_vpc(self, aws_vpc_id, aws_subnet_id):
@@ -63,7 +71,7 @@ def create(self):
6371
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMAWSVirtualNetwork`
6472
"""
6573
vn = self.client._perform_tenant_json(
66-
"POST", "/virtual-networks", body=self.data
74+
"POST", "/virtual-networks", body=self.data, params={ 'useDefaultValues':self.use_default_values }
6775
)
6876
return FMAWSVirtualNetwork(self.client, vn)
6977

@@ -97,7 +105,7 @@ def create(self):
97105
:rtype: :class:`dataikuapi.fm.virtualnetworks.FMAzureVirtualNetwork`
98106
"""
99107
vn = self.client._perform_tenant_json(
100-
"POST", "/virtual-networks", body=self.data
108+
"POST", "/virtual-networks", body=self.data, params={ 'useDefaultValues':self.use_default_values }
101109
)
102110
return FMAzureVirtualNetwork(self.client, vn)
103111

dataikuapi/fmclient.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ def get_instance(self, instance_id):
193193
instance = self._perform_tenant_json("GET", "/instances/%s" % instance_id)
194194
return self._make_instance(instance)
195195

196+
def list_instance_images(self):
197+
"""
198+
List all available images to create new instances
199+
200+
:return: list of images, as a pair of id and label
201+
"""
202+
return self._perform_tenant_json("GET", "/images")
203+
196204
########################################################
197205
# Internal Request handling
198206
########################################################

0 commit comments

Comments
 (0)