Last active
August 29, 2015 13:56
-
-
Save wkettler/9335886 to your computer and use it in GitHub Desktop.
Return the device ID's for all drives in a zpool.
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
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