@@ -292,6 +292,43 @@ def set_custom_certificate(self, pem_data):
292292 return self
293293
294294
295+ ########################################################
296+ # Snapshots
297+ ########################################################
298+
299+ def list_snapshots (self ):
300+ """
301+ List all snapshots of this instance
302+
303+ :return: list of snapshots
304+ :rtype: list of :class:`dataikuapi.fm.instances.FMSnapshot`
305+ """
306+ snapshots = self .client ._perform_tenant_json ("GET" , "/instances/%s/snapshots" % self .id )
307+ return [FMSnapshot (self .client , self .id , x ["id" ], x ) for x in snapshots ]
308+
309+ def get_snapshot (self , snapshot_id ):
310+ """
311+ Get a snapshot of this instance
312+
313+ :param str snapshot_id: identifier of the snapshot
314+
315+ :return: Snapshot
316+ :rtype: :class:`dataikuapi.fm.instances.FMSnapshot`
317+ """
318+ return FMSnapshot (self .client , self .id , snapshot_id )
319+
320+ def snapshot (self , reason_for_snapshot = None ):
321+ """
322+ Create a snapshot of the DSS instance
323+
324+ :return: Snapshot
325+ :rtype: :class:`dataikuapi.fm.instances.FMSnapshot`
326+ """
327+ snapshot = self .client ._perform_tenant_json (
328+ "POST" , "/instances/%s/snapshots" % self .id , params = { "reasonForSnapshot" :reason_for_snapshot }
329+ )
330+ return FMSnapshot (self .client , self .id , snapshot ["id" ], snapshot )
331+
295332class FMAWSInstance (FMInstance ):
296333 def set_elastic_ip (self , enable , elasticip_allocation_id ):
297334 """
@@ -333,3 +370,53 @@ class FMInstanceStatus(dict):
333370 def __init__ (self , data ):
334371 """Do not call this directly, use :meth:`FMInstance.get_status`"""
335372 super (FMInstanceStatus , self ).__init__ (data )
373+
374+
375+ class FMSnapshot (object ):
376+ """
377+ A handle to interact with a snapshot of a DSS instance.
378+ Do not create this directly, use :meth:`FMInstance.snapshot`
379+ """
380+
381+ def __init__ (self , client , instance_id , snapshot_id , snapshot_data = None ):
382+ self .client = client
383+ self .instance_id = instance_id
384+ self .snapshot_id = snapshot_id
385+ self .snapshot_data = snapshot_data
386+
387+ def get_info (self ):
388+ """
389+ Get the information about this snapshot
390+
391+ :return: a dict
392+ """
393+ if self .snapshot_data is None :
394+ self .snapshot_data = self .client ._perform_tenant_json (
395+ "GET" , "/instances/%s/snapshots/%s" % (self .instance_id , self .snapshot_id )
396+ )
397+ return self .snapshot_data
398+
399+ def reprovision (self ):
400+ """
401+ Reprovision the physical DSS instance from this snapshot
402+
403+ :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the reprovision process
404+ :rtype: :class:`~dataikuapi.fm.future.FMFuture`
405+ """
406+ future = self .client ._perform_tenant_json (
407+ "POST" , "/instances/%s/snapshots/%s/reprovision" % (self .instance_id , self .snapshot_id )
408+ )
409+ return FMFuture .from_resp (self .client , future )
410+
411+ def delete (self ):
412+ """
413+ Delete the snapshot
414+
415+ :return: A :class:`~dataikuapi.fm.future.FMFuture` representing the deletion process
416+ :rtype: :class:`~dataikuapi.fm.future.FMFuture`
417+ """
418+ future = self .client ._perform_tenant_json (
419+ "DELETE" , "/instances/%s/snapshots/%s" % (self .instance_id , self .snapshot_id )
420+ )
421+ return FMFuture .from_resp (self .client , future )
422+
0 commit comments