From ffab4eb7211f04a4a10e6d441d2e067151c65d75 Mon Sep 17 00:00:00 2001 From: Willem Jan Withagen Date: Mon, 12 Jun 2017 22:43:54 +0200 Subject: [PATCH] ceph_disk/main.py: Allow FreeBSD zap a OSD disk - refactor zap() into a Linux and FreeBSD version Signed-off-by: Willem Jan Withagen --- src/ceph-disk/ceph_disk/main.py | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index de036cd0320..9dfe1e560a2 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -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):