Created
May 19, 2022 18:51
-
-
Save william-gr/611d7da361e30d1076cdb4086aed6971 to your computer and use it in GitHub Desktop.
Replacing a disk in TrueNAS 13.0-RELEASE
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 python3 | |
import argparse | |
import sys | |
from middlewared.client import Client | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('pool') | |
parser.add_argument('label') | |
parser.add_argument('disk') | |
parser.add_argument('passphrase', nargs='?') | |
args = parser.parse_args() | |
with Client() as c: | |
assert '13.0-RELEASE' in c.call('system.version') | |
pool = c.call('pool.query', [['name', '=', args.pool]]) | |
if not pool: | |
print('Pool not found.') | |
sys.exit(1) | |
disk = list(filter(lambda x: x['devname'] == args.disk, c.call('disk.get_unused'))) | |
if not disk: | |
print('Unused disk not found.') | |
sys.exit(1) | |
arg = {'label': args.label, 'disk': disk[0]['identifier']} | |
if pool[0]['encrypt'] == 2: | |
if not args.passphrase: | |
print('Passphrase required.') | |
sys.exit(1) | |
arg['passphrase'] = args.passphrase | |
c.call('pool.replace', pool[0]['id'], arg, job=True) | |
print('Replace initiated.') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment