From 702c32703acbc67529cc42e62ea0a253911ece6d Mon Sep 17 00:00:00 2001 From: Dimitris Aragiorgis Date: Fri, 31 Jan 2014 17:36:55 +0200 Subject: [PATCH] Make disk.name and disk.uuid available in bdev 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. This fixes Issue 696. Signed-off-by: Dimitris Aragiorgis Signed-off-by: Klaus Aehlig Reviewed-by: Klaus Aehlig --- lib/storage/base.py | 5 +-- lib/storage/bdev.py | 54 +++++++++++++++++++++-------- man/ganeti-extstorage-interface.rst | 6 ++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/lib/storage/base.py b/lib/storage/base.py index f9c46318a..8d72aa101 100644 --- a/lib/storage/base.py +++ b/lib/storage/base.py @@ -72,7 +72,8 @@ class BlockDev(object): after assembly we'll have our correct major/minor. """ - def __init__(self, unique_id, children, size, params, dyn_params): + # pylint: disable=W0613 + def __init__(self, unique_id, children, size, params, dyn_params, *args): self._children = children self.dev_path = None self.unique_id = unique_id @@ -111,7 +112,7 @@ class BlockDev(object): @classmethod def Create(cls, unique_id, children, size, spindles, params, excl_stor, - dyn_params): + dyn_params, *args): """Create the device. If the device cannot be created, it will return None diff --git a/lib/storage/bdev.py b/lib/storage/bdev.py index 075b24f19..9847caab3 100644 --- a/lib/storage/bdev.py +++ b/lib/storage/bdev.py @@ -1205,12 +1205,14 @@ class ExtStorageDevice(base.BlockDev): handling of the externally provided block devices. """ - def __init__(self, unique_id, children, size, params, dyn_params): + def __init__(self, unique_id, children, size, params, dyn_params, *args): """Attaches to an extstorage block device. """ super(ExtStorageDevice, self).__init__(unique_id, children, size, params, dyn_params) + (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)) @@ -1222,13 +1224,15 @@ class ExtStorageDevice(base.BlockDev): @classmethod def Create(cls, unique_id, children, size, spindles, params, excl_stor, - dyn_params): + dyn_params, *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)) @@ -1239,7 +1243,7 @@ class ExtStorageDevice(base.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, dyn_params) @@ -1257,7 +1261,7 @@ class ExtStorageDevice(base.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. @@ -1277,7 +1281,8 @@ class ExtStorageDevice(base.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) @@ -1312,7 +1317,7 @@ class ExtStorageDevice(base.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 @@ -1353,7 +1358,8 @@ class ExtStorageDevice(base.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. @@ -1369,11 +1375,13 @@ class ExtStorageDevice(base.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 _ExtStorageAction(action, unique_id, ext_params, - size=None, grow=None, metadata=None): + size=None, grow=None, metadata=None, + name=None, uuid=None): """Take an External Storage action. Take an External Storage action concerning or affecting @@ -1393,6 +1401,10 @@ def _ExtStorageAction(action, unique_id, ext_params, @param grow: the new size in mebibytes (after grow) @type metadata: string @param metadata: metadata info of the Volume, for use by the provider + @type name: string + @param name: name of the Volume (objects.Disk.name) + @type uuid: string + @param uuid: uuid of the Volume (objects.Disk.uuid) @rtype: None or a block device path (during attach) """ @@ -1405,7 +1417,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, name, uuid) # Do not use log file for action `attach' as we need # to get the output from RunResult @@ -1522,7 +1534,8 @@ def ExtStorageFromDisk(name, base_dir=None): def _ExtStorageEnvironment(unique_id, ext_params, - size=None, grow=None, metadata=None): + size=None, grow=None, metadata=None, + name=None, uuid=None): """Calculate the environment for an External Storage script. @type unique_id: tuple (driver, vol_name) @@ -1535,6 +1548,10 @@ def _ExtStorageEnvironment(unique_id, ext_params, @param grow: new size of Volume after grow (in mebibytes) @type metadata: string @param metadata: metadata info of the Volume + @type name: string + @param name: name of the Volume (objects.Disk.name) + @type uuid: string + @param uuid: uuid of the Volume (objects.Disk.uuid) @rtype: dict @return: dict of environment variables @@ -1557,6 +1574,12 @@ def _ExtStorageEnvironment(unique_id, ext_params, if metadata is not None: result["VOL_METADATA"] = metadata + if name is not None: + result["VOL_CNAME"] = name + + if uuid is not None: + result["VOL_UUID"] = uuid + return result @@ -1611,7 +1634,8 @@ def FindDevice(disk, children): """ _VerifyDiskType(disk.dev_type) device = DEV_MAP[disk.dev_type](disk.logical_id, children, disk.size, - disk.params, disk.dynamic_params) + disk.params, disk.dynamic_params, + disk.name, disk.uuid) if not device.attached: return None return device @@ -1633,7 +1657,8 @@ def Assemble(disk, children): _VerifyDiskType(disk.dev_type) _VerifyDiskParams(disk) device = DEV_MAP[disk.dev_type](disk.logical_id, children, disk.size, - disk.params, disk.dynamic_params) + disk.params, disk.dynamic_params, + disk.name, disk.uuid) device.Assemble() return device @@ -1656,7 +1681,8 @@ def Create(disk, children, excl_stor): _VerifyDiskParams(disk) device = DEV_MAP[disk.dev_type].Create(disk.logical_id, children, disk.size, disk.spindles, disk.params, excl_stor, - disk.dynamic_params) + disk.dynamic_params, + disk.name, disk.uuid) return device # Please keep this at the bottom of the file for visibility. diff --git a/man/ganeti-extstorage-interface.rst b/man/ganeti-extstorage-interface.rst index 81c03c8db..f082d83e1 100644 --- a/man/ganeti-extstorage-interface.rst +++ b/man/ganeti-extstorage-interface.rst @@ -63,6 +63,12 @@ VOL_METADATA metadata to be associated with the volume. Currently, Ganeti sets this value to ``originstname+X`` where ``X`` is the instance's name. +VOL_CNAME + The name of the Disk config object (optional). + +VOL_UUID + The uuid of the Disk config object. + EXECUTABLE SCRIPTS ------------------ -- GitLab