From 72bb94af24e97744f7c6e8f2219de5e30736eff7 Mon Sep 17 00:00:00 2001 From: Rushikesh Jadhav Date: Wed, 7 May 2025 23:11:09 +0530 Subject: [PATCH] Added `raw_disk_is_available()` using `blkid` for reliable raw disk checks. Added docstring explaining what this new method does vs `disk_is_available`. Added type hints. Signed-off-by: Rushikesh Jadhav --- lib/host.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/host.py b/lib/host.py index 29ffd9b0..e5da2def 100644 --- a/lib/host.py +++ b/lib/host.py @@ -516,7 +516,22 @@ def disks(self): disks.sort() return disks - def disk_is_available(self, disk): + def raw_disk_is_available(self, disk: str) -> bool: + """ + Check if a raw disk (without any identifiable filesystem or partition label) is available. + It suggests the disk is "raw" and likely unformatted thus available. + """ + return self.ssh_with_result(['blkid', '/dev/' + disk]).returncode == 2 + + def disk_is_available(self, disk: str) -> bool: + """ + Check if a disk is unmounted and appears available for use. + It may or may not contain identifiable filesystem or partition label. + If there are no mountpoints, it is assumed that the disk is not in use. + + Warn: This function may misclassify LVM_member disks (e.g. in XOSTOR, RAID, ZFS) as "available". + Such disks may not have mountpoints but still be in use. + """ return len(self.ssh(['lsblk', '-n', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0 def available_disks(self, blocksize=512):