Skip to content

Commit 5c83452

Browse files
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 <[email protected]>
1 parent 4fbe63e commit 5c83452

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
@@ -516,7 +516,22 @@ def disks(self):
516516
disks.sort()
517517
return disks
518518

519-
def disk_is_available(self, disk):
519+
def raw_disk_is_available(self, disk: str) -> bool:
520+
"""
521+
Check if a raw disk (without any identifiable filesystem or partition label) is available.
522+
It suggests the disk is "raw" and likely unformatted thus available.
523+
"""
524+
return self.ssh_with_result(['blkid', '/dev/' + disk]).returncode == 2
525+
526+
def disk_is_available(self, disk: str) -> bool:
527+
"""
528+
Check if a disk is unmounted and appears available for use.
529+
It may or may not contain identifiable filesystem or partition label.
530+
If there are no mountpoints, it is assumed that the disk is not in use.
531+
532+
Warn: This function may misclassify LVM_member disks (e.g. in XOSTOR, RAID, ZFS) as "available".
533+
Such disks may not have mountpoints but still be in use.
534+
"""
520535
return len(self.ssh(['lsblk', '-n', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0
521536

522537
def available_disks(self, blocksize=512):

0 commit comments

Comments
 (0)