Commit e398546b authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a small bdev helper function



I wanted to write that snippet the third time, which is too much :)
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent ded769c1
......@@ -75,6 +75,17 @@ def _ThrowError(msg, *args):
raise errors.BlockDeviceError(msg)
def _CheckResult(result):
"""Throws an error if the given result is a failed one.
@param result: result from RunCmd
"""
if result.failed:
_ThrowError("Command: %s error: %s - %s", result.cmd, result.fail_reason,
result.output)
def _CanReadDevice(path):
"""Check if we can read from the given device.
......@@ -797,11 +808,8 @@ class LogicalVolume(BlockDev):
_ThrowError("Not enough free space: required %s,"
" available %s", size, free_size)
result = utils.RunCmd(["lvcreate", "-L%dm" % size, "-s",
"-n%s" % snap_name, self.dev_path])
if result.failed:
_ThrowError("command: %s error: %s - %s",
result.cmd, result.fail_reason, result.output)
_CheckResult(utils.RunCmd(["lvcreate", "-L%dm" % size, "-s",
"-n%s" % snap_name, self.dev_path]))
return (self._vg_name, snap_name)
......@@ -818,11 +826,7 @@ class LogicalVolume(BlockDev):
# Only up to 128 characters are allowed
text = text[:128]
result = utils.RunCmd(["lvchange", "--addtag", text,
self.dev_path])
if result.failed:
_ThrowError("Command: %s error: %s - %s", result.cmd, result.fail_reason,
result.output)
_CheckResult(utils.RunCmd(["lvchange", "--addtag", text, self.dev_path]))
def Grow(self, amount, dryrun, backingstore):
"""Grow the logical volume.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment