(snap) Snapshot support for ExtStorage
[ganeti-local] / lib / bdev.py
index 7226f1f..b2a6971 100644 (file)
@@ -3149,9 +3149,19 @@ class ExtStorageDevice(BlockDev):
     _ExtStorageAction(constants.ES_ACTION_SETINFO, self.unique_id,
                       self.ext_params, metadata=text)
 
+  def Snapshot(self, snapshot_name):
+    """Take a snapshot of the block device.
+
+    """
+    # Call the External Storage's setinfo script,
+    # to set metadata for an existing Volume inside the External Storage
+    _ExtStorageAction(constants.ES_ACTION_SNAPSHOT, self.unique_id,
+                      self.ext_params, snapshot_name=snapshot_name)
+
 
 def _ExtStorageAction(action, unique_id, ext_params,
-                      size=None, grow=None, metadata=None):
+                      size=None, grow=None, metadata=None,
+                      snapshot_name=None):
   """Take an External Storage action.
 
   Take an External Storage action concerning or affecting
@@ -3183,7 +3193,7 @@ def _ExtStorageAction(action, unique_id, ext_params,
 
   # Create the basic environment for the driver's scripts
   create_env = _ExtStorageEnvironment(unique_id, ext_params, size,
-                                      grow, metadata)
+                                      grow, metadata, snapshot_name)
 
   # Do not use log file for action `attach' as we need
   # to get the output from RunResult
@@ -3295,12 +3305,14 @@ def ExtStorageFromDisk(name, base_dir=None):
                        detach_script=es_files[constants.ES_SCRIPT_DETACH],
                        setinfo_script=es_files[constants.ES_SCRIPT_SETINFO],
                        verify_script=es_files[constants.ES_SCRIPT_VERIFY],
+                       snapshot_script=es_files[constants.ES_SCRIPT_SNAPSHOT],
                        supported_parameters=parameters)
   return True, es_obj
 
 
 def _ExtStorageEnvironment(unique_id, ext_params,
-                           size=None, grow=None, metadata=None):
+                           size=None, grow=None, metadata=None,
+                           snapshot_name=None):
   """Calculate the environment for an External Storage script.
 
   @type unique_id: tuple (driver, vol_name)
@@ -3335,6 +3347,9 @@ def _ExtStorageEnvironment(unique_id, ext_params,
   if metadata is not None:
     result["VOL_METADATA"] = metadata
 
+  if snapshot_name is not None:
+    result["VOL_SNAPSHOT_NAME"] = snapshot_name
+
   return result