Created
November 13, 2016 02:21
-
-
Save dapperfu/2e669217fad8f171c880aa507a0d43cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
from __future__ import print_function | |
import re | |
import subprocess | |
import libzfs | |
def get_disk_info(dev): | |
result = subprocess.check_output(["camcontrol", "identify", dev]) | |
serial = re.compile("serial number[ ]+ ([^\n]+)").findall(result)[0] | |
model = re.compile("device model[ ]+ ([^\n]+)").findall(result)[0] | |
return serial, model | |
regex = re.compile("gptid/([^ ]+)[ ]+N/A[ ]+([ad]+[\d]+)p([\d]+)") | |
pools = list(libzfs.ZFS().pools) | |
for pool in pools: | |
print("Pool: {}".format(pool.name)) | |
gptids = subprocess.check_output(["glabel","status"]) | |
partitions = regex.findall(gptids) | |
for disk in pool.disks: | |
if "gptid" in disk: | |
pool_disk_gptid = disk.split("/")[3].lower() | |
found=False | |
for gptid, pool_disk_dev, part in partitions: | |
if pool_disk_gptid == gptid: | |
print(" gptid: {}".format(pool_disk_gptid)) | |
pool_disk_dev = "/dev/"+pool_disk_dev | |
found=True | |
break | |
if not found: | |
continue | |
else: | |
print(" gptid: N/A") | |
pool_disk_dev, part = disk.split("p") | |
serial, model = get_disk_info(pool_disk_dev) | |
print(" Dev: {}p{}".format(pool_disk_dev, part)) | |
print(" Model: {}".format(model)) | |
print(" Serial: {}".format(serial)) | |
print("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dumps all the disk model and serial number for all zfs pools. Tested on
FreeBSD freenas.lan 10.3-STABLE FreeBSD 10.3-STABLE #0 r295946+07c41cd(9.10-STABLE)
Sample output: