Repository URL to install this package:
| 
      
        
        
        Version: 
        
         
          
          3.3.32  ▾
        
         | 
| 
    
    python-workloadmgrclient
  
    /
        
    usr
  
        /
        
    lib
  
        /
        
    python2.7
  
        /
        
    dist-packages
  
        /
        
    workloadmgrclient
  
        /
        
    v1
  
        /
        snapshots.py
   | 
|---|
# Copyright (c) 2014 TrilioData, Inc.
# All Rights Reserved.
"""
Snapshots interface (1.1 extension).
"""
import six
try:
    from urllib import urlencode
except ImportError:
    from urllib.parse import urlencode
    
from workloadmgrclient import base
class Snapshot(base.Resource):
    """A workload snapshot either full or incremental"""
    def __repr__(self):
        return "<Snapshot: %s>" % self.id
    
    def delete(self):
        """Delete this snapshot."""
        return self.manager.delete(self)
    
    def cancel(self):
        """Cancels this snapshot."""
        return self.manager.cancel(self)            
    def restore(self, test, name=None, description=None, options=None):
        """Restore the snapshot """
        return self.manager.restore(self, test, name, description, options)
    
    def mount(self, mount_vm_id, options=None):
        """Mount the snapshot """
        return self.manager.mount(self, mount_vm_id, options)
    def dismount(self):
        """DisMount the snapshot """
        return self.manager.dismount(self)
    
class SnapshotsManager(base.ManagerWithFind):
    """Manage :class:`Snapshot` resources."""
    resource_class = Snapshot
    def get(self, snapshot_id):
        """Show details of a workload snapshot.
        :param snapshot_id: The ID of the workload snapshot to display.
        :rtype: :class:`Snapshot`
        """
        return self._get("/snapshots/%s" % snapshot_id, "snapshot")
    def list(self, detailed=False, search_opts=None):
        """Get a list of all workload snapshots
        :rtype: list of :class:`Snapshot`
        """
        if search_opts is None:
            search_opts = {}   
            
        qparams = {}
        for opt, val in six.iteritems(search_opts):
            if val:
                qparams[opt] = val
        query_string = "?%s" % urlencode(qparams) if qparams else ""
        detail = ""
        if detailed:
            detail = "/detail"
        return self._list("/snapshots%s%s" % (detail, query_string),
                          "snapshots")
                          
    def delete(self, snapshot_id):
        """Delete a workload snapshot.
        :param snapshot_id: The :class:`Snapshot` to delete.
        """
        self._delete("/snapshots/%s" % base.getid(snapshot_id))
        
    def cancel(self, snapshot_id):
        """Cancel a workload snapshot.
        :param snapshot_id: The :class:`Snapshot` to cancel.
        """
        self._cancel("/snapshots/%s/cancel" % base.getid(snapshot_id))        
    def restore(self, snapshot_id, test=False, name=None, description=None, options=None):
        """restores a workload snapshot.
        :param snapshot_id: The :class:`Snapshot` to restore.
        """
        if test == True:
            body = {'testbubble': { 'name': name, 'description': description, 'options':options}}
            self._post("/snapshots/%s?test=1" % base.getid(snapshot_id), body)
        else:
            body = {'restore': { 'name': name, 'description': description, 'options':options}}
            self._post("/snapshots/%s" % base.getid(snapshot_id), body)
    def mount(self, snapshot_id, mount_vm_id, options=None):
        """mounts a workload snapshot.
        :param snapshot_id: The :class:`Snapshot` to mount.
        """
        body = {'mount': { 'mount_vm_id': mount_vm_id,
                           'options':options}}
        self._mount("/snapshots/%s/mount" % base.getid(snapshot_id), body)
    def dismount(self, snapshot_id, options=None):
        """dismounts a workload snapshot.
        :param snapshot_id: The :class:`Snapshot` to dismount.
        """
        body = {'mount': {'options':options}}
        self._post("/snapshots/%s/dismount" % base.getid(snapshot_id), body)
    def snapshot_mounted_list(self, workload_id):
        """
        get mounted snapshots list
        """
        if workload_id is not None:
           return self._snapshot_mounted_list("/workloads/%s/snapshots/mounted/list" % workload_id)
        else:
             return self._snapshot_mounted_list("/snapshots/mounted/list")