]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_disk/main.py: Allow FreeBSD zap a OSD disk 15642/head
authorWillem Jan Withagen <wjw@digiware.nl>
Mon, 12 Jun 2017 20:43:54 +0000 (22:43 +0200)
committerWillem Jan Withagen <wjw@digiware.nl>
Sat, 1 Jul 2017 17:23:56 +0000 (19:23 +0200)
 - refactor zap() into a Linux and FreeBSD version

Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
src/ceph-disk/ceph_disk/main.py

index de036cd0320137438275923d760962ff874cb795..9dfe1e560a210fcf015caae6e0167dcccd093260 100755 (executable)
@@ -1532,14 +1532,7 @@ def update_partition(dev, description):
     command_check_call(['udevadm', 'settle', '--timeout=600'])
 
 
-def zap(dev):
-    """
-    Destroy the partition table and content of a given disk.
-    """
-    dev = os.path.realpath(dev)
-    dmode = os.stat(dev).st_mode
-    if not stat.S_ISBLK(dmode) or is_partition(dev):
-        raise Error('not full block device; cannot zap', dev)
+def zap_linux(dev):
     try:
         # Thoroughly wipe all partitions of any traces of
         # Filesystems or OSD Journals
@@ -1598,13 +1591,42 @@ def zap(dev):
                 dev,
             ],
         )
-
         update_partition(dev, 'zapped')
 
     except subprocess.CalledProcessError as e:
         raise Error(e)
 
 
+def zap_freebsd(dev):
+    try:
+        # For FreeBSD we just need to zap the partition.
+        command_check_call(
+            [
+                'gpart',
+                'destroy',
+                '-F',
+                dev,
+            ],
+        )
+
+    except subprocess.CalledProcessError as e:
+        raise Error(e)
+
+
+def zap(dev):
+    """
+    Destroy the partition table and content of a given disk.
+    """
+    dev = os.path.realpath(dev)
+    dmode = os.stat(dev).st_mode
+    if not stat.S_ISBLK(dmode) or is_partition(dev):
+        raise Error('not full block device; cannot zap', dev)
+    if FREEBSD:
+        zap_freebsd(dev)
+    else:
+        zap_linux(dev)
+
+
 def adjust_symlink(target, path):
     create = True
     if os.path.lexists(path):