(2.11) Make disk.name and disk.uuid available in bdev
authorDimitris Aragiorgis <dimara@grnet.gr>
Mon, 10 Mar 2014 10:19:17 +0000 (12:19 +0200)
committerDimitris Aragiorgis <dimara@grnet.gr>
Thu, 27 Mar 2014 08:01:18 +0000 (10:01 +0200)
Until now Disk name and uuid was not available on bdev level.
In case of ExtStorage, this info is useful, and may be for other
templates in the future too.

This patch treats the name and uuid object slots just like the size
one and passes them to BlockDev.__init__() and to BlockDev.Create().

The ExtStrorage interface exports these options to scripts via the
VOL_CNAME and VOL_UUID environment variables.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

This should be backported since in stable-2.11 bdev.py is split
in lib/storage/*.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>

lib/bdev.py
man/ganeti-extstorage-interface.rst

index b2a6971..f083484 100644 (file)
@@ -264,7 +264,8 @@ class BlockDev(object):
   after assembly we'll have our correct major/minor.
 
   """
-  def __init__(self, unique_id, children, size, params):
+  # pylint: disable=W0613
+  def __init__(self, unique_id, children, size, params, *args):
     self._children = children
     self.dev_path = None
     self.unique_id = unique_id
@@ -301,7 +302,7 @@ class BlockDev(object):
     raise NotImplementedError
 
   @classmethod
-  def Create(cls, unique_id, children, size, params, excl_stor):
+  def Create(cls, unique_id, children, size, params, excl_stor, *args):
     """Create the device.
 
     If the device cannot be created, it will return None
@@ -2985,11 +2986,15 @@ class ExtStorageDevice(BlockDev):
   handling of the externally provided block devices.
 
   """
-  def __init__(self, unique_id, children, size, params):
+  def __init__(self, unique_id, children, size, params, *args):
     """Attaches to an extstorage block device.
 
     """
-    super(ExtStorageDevice, self).__init__(unique_id, children, size, params)
+    super(ExtStorageDevice, self).__init__(unique_id, children, size, params,
+                                           *args)
+
+    (self.name, self.uuid) = args
+
     if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
       raise ValueError("Invalid configuration data %s" % str(unique_id))
 
@@ -3000,13 +3005,15 @@ class ExtStorageDevice(BlockDev):
     self.Attach()
 
   @classmethod
-  def Create(cls, unique_id, children, size, params, excl_stor):
+  def Create(cls, unique_id, children, size, params, excl_stor, *args):
     """Create a new extstorage device.
 
     Provision a new volume using an extstorage provider, which will
     then be mapped to a block device.
 
     """
+    (name, uuid) = args
+
     if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
       raise errors.ProgrammerError("Invalid configuration data %s" %
                                    str(unique_id))
@@ -3017,9 +3024,9 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's create script,
     # to provision a new Volume inside the External Storage
     _ExtStorageAction(constants.ES_ACTION_CREATE, unique_id,
-                      params, str(size))
+                      params, size=str(size), name=name, uuid=uuid)
 
-    return ExtStorageDevice(unique_id, children, size, params)
+    return ExtStorageDevice(unique_id, children, size, params, name, uuid)
 
   def Remove(self):
     """Remove the extstorage device.
@@ -3035,7 +3042,7 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's remove script,
     # to remove the Volume from the External Storage
     _ExtStorageAction(constants.ES_ACTION_REMOVE, self.unique_id,
-                      self.ext_params)
+                      self.ext_params, name=self.name, uuid=self.uuid)
 
   def Rename(self, new_id):
     """Rename this device.
@@ -3055,7 +3062,8 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's attach script,
     # to attach an existing Volume to a block device under /dev
     self.dev_path = _ExtStorageAction(constants.ES_ACTION_ATTACH,
-                                      self.unique_id, self.ext_params)
+                                      self.unique_id, self.ext_params,
+                                      name=self.name, uuid=self.uuid)
 
     try:
       st = os.stat(self.dev_path)
@@ -3090,7 +3098,7 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's detach script,
     # to detach an existing Volume from it's block device under /dev
     _ExtStorageAction(constants.ES_ACTION_DETACH, self.unique_id,
-                      self.ext_params)
+                      self.ext_params, name=self.name, uuid=self.uuid)
 
     self.minor = None
     self.dev_path = None
@@ -3131,7 +3139,8 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's grow script,
     # to grow an existing Volume inside the External Storage
     _ExtStorageAction(constants.ES_ACTION_GROW, self.unique_id,
-                      self.ext_params, str(self.size), grow=str(new_size))
+                      self.ext_params, size=str(self.size), grow=str(new_size),
+                      name=self.name, uuid=self.uuid)
 
   def SetInfo(self, text):
     """Update metadata with info text.
@@ -3147,7 +3156,8 @@ class ExtStorageDevice(BlockDev):
     # Call the External Storage's setinfo script,
     # to set metadata for an existing Volume inside the External Storage
     _ExtStorageAction(constants.ES_ACTION_SETINFO, self.unique_id,
-                      self.ext_params, metadata=text)
+                      self.ext_params, metadata=text,
+                      name=self.name, uuid=self.uuid)
 
   def Snapshot(self, snapshot_name):
     """Take a snapshot of the block device.
@@ -3156,12 +3166,13 @@ class ExtStorageDevice(BlockDev):
     # 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)
+                      self.ext_params, snapshot_name=snapshot_name,
+                      name=self.name, uuid=self.uuid)
 
 
 def _ExtStorageAction(action, unique_id, ext_params,
                       size=None, grow=None, metadata=None,
-                      snapshot_name=None):
+                      snapshot_name=None, name=None, uuid=None):
   """Take an External Storage action.
 
   Take an External Storage action concerning or affecting
@@ -3193,7 +3204,8 @@ 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, snapshot_name)
+                                      grow, metadata, snapshot_name,
+                                      name, uuid)
 
   # Do not use log file for action `attach' as we need
   # to get the output from RunResult
@@ -3312,7 +3324,7 @@ def ExtStorageFromDisk(name, base_dir=None):
 
 def _ExtStorageEnvironment(unique_id, ext_params,
                            size=None, grow=None, metadata=None,
-                           snapshot_name=None):
+                           snapshot_name=None, name=None, uuid=None):
   """Calculate the environment for an External Storage script.
 
   @type unique_id: tuple (driver, vol_name)
@@ -3350,6 +3362,12 @@ def _ExtStorageEnvironment(unique_id, ext_params,
   if snapshot_name is not None:
     result["VOL_SNAPSHOT_NAME"] = snapshot_name
 
+  if name is not None:
+    result["VOL_CNAME"] = name
+
+  if uuid is not None:
+    result["VOL_UUID"] = uuid
+
   return result
 
 
@@ -3416,7 +3434,7 @@ def FindDevice(disk, children):
   """
   _VerifyDiskType(disk.dev_type)
   device = DEV_MAP[disk.dev_type](disk.physical_id, children, disk.size,
-                                  disk.params)
+                                  disk.params, disk.name, disk.uuid)
   if not device.attached:
     return None
   return device
@@ -3438,7 +3456,7 @@ def Assemble(disk, children):
   _VerifyDiskType(disk.dev_type)
   _VerifyDiskParams(disk)
   device = DEV_MAP[disk.dev_type](disk.physical_id, children, disk.size,
-                                  disk.params)
+                                  disk.params, disk.name, disk.uuid)
   device.Assemble()
   return device
 
@@ -3458,5 +3476,6 @@ def Create(disk, children, excl_stor):
   _VerifyDiskType(disk.dev_type)
   _VerifyDiskParams(disk)
   device = DEV_MAP[disk.dev_type].Create(disk.physical_id, children, disk.size,
-                                         disk.params, excl_stor)
+                                         disk.params, excl_stor,
+                                         disk.name, disk.uuid)
   return device
index 81c03c8..0310631 100644 (file)
@@ -63,6 +63,16 @@ VOL_METADATA
     metadata to be associated with the volume. Currently, Ganeti sets
     this value to ``originstname+X`` where ``X`` is the instance's name.
 
+SNAPSHOT_NAME
+    Available only to the **snapshot** script. This is the name of the
+    snapshot requested by the user.
+
+VOL_CNAME
+    The name of the Disk config object (optional)
+
+VOL_UUID
+    The uuid of the Disk config object.
+
 EXECUTABLE SCRIPTS
 ------------------