Expose block device grow in backend.py
authorIustin Pop <iustin@google.com>
Mon, 16 Jun 2008 15:08:18 +0000 (15:08 +0000)
committerIustin Pop <iustin@google.com>
Mon, 16 Jun 2008 15:08:18 +0000 (15:08 +0000)
This patch adds a wrapper over the block device grow operation that
converts the input and output parameters as needed for the rpc layer.

Reviewed-by: imsnah

lib/backend.py

index 25beef9..1746823 100644 (file)
@@ -1146,6 +1146,32 @@ def OSFromDisk(name, base_dir=None):
                     api_version=api_version)
 
 
+def GrowBlockDevice(disk, amount):
+  """Grow a stack of block devices.
+
+  This function is called recursively, with the childrens being the
+  first one resize.
+
+  Args:
+    disk: the disk to be grown
+
+  Returns: a tuple of (status, result), with:
+    status: the result (true/false) of the operation
+    result: the error message if the operation failed, otherwise not used
+
+  """
+  r_dev = _RecursiveFindBD(disk)
+  if r_dev is None:
+    return False, "Cannot find block device %s" % (disk,)
+
+  try:
+    r_dev.Grow(amount)
+  except errors.BlockDeviceError, err:
+    return False, str(err)
+
+  return True, None
+
+
 def SnapshotBlockDevice(disk):
   """Create a snapshot copy of a block device.