Skip to content

Instantly share code, notes, and snippets.

@wkettler
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wkettler/9335886 to your computer and use it in GitHub Desktop.
Save wkettler/9335886 to your computer and use it in GitHub Desktop.
Return the device ID's for all drives in a zpool.
from execute import execute, Retcode
import re
def get_zpool_drives(zpool):
"""
Returns all drives in the zpool.
Inputs:
zpool (str): Zpool name
Outputs:
drives (list): A list of zpool drives
"""
drives = []
try:
retcode, output = execute('zpool status %s' % zpool)
except:
raise
else:
if retcode:
raise Retcode(output)
for line in output.split("\n"):
match = re.search(r'(c[0-9]t.*d[0-9])', line)
if match:
drives.append(match.group(1).split()[0].strip())
return drives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment