From 69dd363f2ee73c97e5947d35dd4115d645c90a6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Thu, 21 Oct 2010 14:19:19 +0200
Subject: [PATCH] Adding backend method to wipe a block device
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/backend.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/backend.py b/lib/backend.py
index 4ef08ead7..3b8c55089 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1287,6 +1287,34 @@ def BlockdevCreate(disk, size, owner, on_primary, info):
   return device.unique_id
 
 
+def _WipeDevice(path):
+  """This function actually wipes the device.
+
+  @param path: The path to the device to wipe
+
+  """
+  result = utils.RunCmd("%s%s" % (constants.WIPE_CMD, utils.ShellQuote(path)))
+
+  if result.failed:
+    _Fail("Wipe command '%s' exited with error: %s; output: %s", result.cmd,
+          result.fail_reason, result.output)
+
+
+def BlockdevWipe(disk):
+  """Wipes a block device.
+
+  @type disk: L{objects.Disk}
+  @param disk: the disk object we want to wipe
+
+  """
+  try:
+    rdev = _RecursiveFindBD(disk)
+  except errors.BlockDeviceError, err:
+    _Fail("Cannot execute wipe for device %s: device not found", err)
+
+  _WipeDevice(rdev.dev_path)
+
+
 def BlockdevRemove(disk):
   """Remove a block device.
 
-- 
GitLab