Skip to content

Commit

Permalink
Merge pull request #91 from truenas/improv1
Browse files Browse the repository at this point in the history
NAS-130620 / 25.04 / improve list_disks()
  • Loading branch information
yocalebo authored Aug 17, 2024
2 parents 1301af8 + 6599231 commit b10f9d7
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions truenas_installer/disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,15 @@ async def list_disks():

disks = []
for disk in json.loads(
(await run(["lsblk", "-b", "-fJ", "-o", "name,fstype,label,log-sec,rm,size"])).stdout
(await run(["lsblk", "-b", "-fJ", "-o", "name,fstype,label,rm,size,model"])).stdout
)["blockdevices"]:
device = f"/dev/{disk['name']}"

if disk["name"].startswith(("dm", "loop", "md", "sr", "st")):
continue

if disk["size"] < MIN_DISK_SIZE:
elif disk["size"] < MIN_DISK_SIZE:
continue

if re.search(fr"{device}p?[0-9]+", mtab):
elif re.search(fr"/dev/{disk["name"]}p?[0-9]+", mtab):
continue

model = "Unknown Device"
if m := re.search("Model: (.+)", (await run(["sgdisk", "-p", device], check=False)).stdout):
model = m.group(1)

zfs_members = []
if disk["fstype"] is not None:
label = disk["fstype"]
Expand All @@ -75,6 +67,19 @@ async def list_disks():
else:
label = ""

disks.append(Disk(disk["name"], disk["size"], model, label, zfs_members, disk["rm"]))

return disks
disks.append(
Disk(
disk["name"],
disk["size"],
disk["model"] or "Unknown Model",
label,
zfs_members,
disk["rm"]
)
)

# we sort the disks by name because `nvme` comes before `sd*`
# and our appliances have nvme boot drives so by putting nvme
# devices up top in the installer, it provides a convenience
# for other departments
return sorted(disks, key=lambda x: x.name)

0 comments on commit b10f9d7

Please sign in to comment.