Created
April 26, 2017 20:57
-
-
Save rbenigno/f870d59c72bdac79c0578d667703be7f to your computer and use it in GitHub Desktop.
Dump volume list for a Pure FlashArray
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.7 | |
""" | |
Dump LUN inventory from Pure array | |
""" | |
# Import purestorage | |
try: | |
from purestorage import * | |
except ImportError, e: | |
print "Import error: {}".format(str(e)) | |
print 'https://pypi.python.org/pypi/purestorage' | |
exit(1) | |
import argparse, json, pprint | |
# Disable warnings... | |
import requests | |
requests.packages.urllib3.disable_warnings() | |
# Define and parse command line arguements | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("array", help="Pure FlashArray Host/IP") | |
parser.add_argument("api_token", help="API Token") | |
return parser.parse_args() | |
def convert_gb(size): | |
return '{0:.2f}'.format(size/float(float(1024) ** 3)) | |
def dump_luns(array): | |
vols = array.list_volumes() | |
print '{: >50}\t{: >11}\t{: >24}'.format("Name", "Size", "Serial") | |
print '{: >50}\t{: >11}\t{: >24}'.format('-' * 50, '-' * 11, '-' * 24) | |
for vol in vols: | |
volsize = '{} GB'.format(convert_gb(vol["size"])) | |
print '{: >50}\t{: >11}\t{: >24}'.format(vol["name"], volsize, vol["serial"].lower()) | |
### --------------------------------------------------------------------------- | |
### MAIN | |
### --------------------------------------------------------------------------- | |
# Main function (when running as an executable) | |
if __name__ == '__main__': | |
import json | |
# Retrive the command line arguments | |
args = parse_args() | |
# Connection Info | |
pure_host = args.array | |
api_token = args.api_token | |
pure_array = purestorage.FlashArray(pure_host, api_token=api_token) | |
dump_luns(pure_array) | |
pure_array.invalidate_cookie() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment