Skip to content

Commit

Permalink
salt/volume: add a new module function to retrieve size & path
Browse files Browse the repository at this point in the history
This will replace call to `disk.dump`.
By returning both size and path, we can keep a single Salt call for
unformatted volume (for which we will need to get a reliable path from
Salt).

Refs: #2421
Signed-off-by: Sylvain Laperche <[email protected]>
  • Loading branch information
slaperche-scality committed Jun 26, 2020
1 parent 2b66caf commit a0f3a5a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions salt/_modules/metalk8s_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ def device_name(path):
return os.path.basename(realpath)


def device_info(name):
"""Return information about the backing storage device of the given volume.
Returned information are:
- an reliable path (e.g.: constant accross reboot) to the storage device
- the size of the storage device (in bytes)
Args:
name (str): volume name
CLI Example:
.. code-block:: bash
salt '<NODE_NAME>' metalk8s_volumes.device_info example-volume
"""
return _get_volume(name).device_info()


# Volume {{{


Expand Down Expand Up @@ -222,6 +241,12 @@ def clean_up(self):
"""Clean up the backing storage device."""
return

def device_info(self):
"""Return size and path of the underlying block device"""
path = '/dev/disk/by-uuid/{}'.format(self.get('metadata.uid'))
size = __salt__['disk.dump'](path)['getsize64']
return {'size': size, 'path': path}

@abc.abstractproperty
def path(self):
"""Path to the backing device."""
Expand Down

0 comments on commit a0f3a5a

Please sign in to comment.