Skip to content

Commit a23f4b3

Browse files
authored
Merge pull request #301 from rushikeshjadhav/issue-276-available-disk
lib/host: Added `raw_disk_is_available()` using `blkid` for reliable raw disk checks.
2 parents 0f459bd + 72bb94a commit a23f4b3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/host.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,22 @@ def disks(self):
540540
disks.sort()
541541
return disks
542542

543-
def disk_is_available(self, disk):
543+
def raw_disk_is_available(self, disk: str) -> bool:
544+
"""
545+
Check if a raw disk (without any identifiable filesystem or partition label) is available.
546+
It suggests the disk is "raw" and likely unformatted thus available.
547+
"""
548+
return self.ssh_with_result(['blkid', '/dev/' + disk]).returncode == 2
549+
550+
def disk_is_available(self, disk: str) -> bool:
551+
"""
552+
Check if a disk is unmounted and appears available for use.
553+
It may or may not contain identifiable filesystem or partition label.
554+
If there are no mountpoints, it is assumed that the disk is not in use.
555+
556+
Warn: This function may misclassify LVM_member disks (e.g. in XOSTOR, RAID, ZFS) as "available".
557+
Such disks may not have mountpoints but still be in use.
558+
"""
544559
return len(self.ssh(['lsblk', '-n', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0
545560

546561
def available_disks(self, blocksize=512):

0 commit comments

Comments
 (0)