@@ -300,6 +300,43 @@ def set_custom_certificate(self, pem_data):
300300 return self
301301
302302
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+
303340class FMAWSInstance (FMInstance ):
304341 def set_elastic_ip (self , enable , elasticip_allocation_id ):
305342 """
@@ -341,3 +378,53 @@ class FMInstanceStatus(dict):
341378 def __init__ (self , data ):
342379 """Do not call this directly, use :meth:`FMInstance.get_status`"""
343380 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+
0 commit comments