-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpace_Reporting_90_day.py
59 lines (42 loc) · 2 KB
/
Space_Reporting_90_day.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from purestorage import purestorage
import sys
import csv
import requests
import time
import os
# Disable certificate warnings
requests.packages.urllib3.disable_warnings()
# Measure script run time
startTime = time.time()
# Set variables
array_IP = "<array_hostname>"
array_api = "<api_token>"
time_stamp = (time.strftime("%m-%d-%y"))
rptFileName = "space-report-" + time_stamp + "-" + array_IP + ".csv"
# Connect to FlashArray
array = purestorage.FlashArray(array_IP, api_token=array_api)
print('Connecting to array.')
# Get all volumes on the FlashArray
allVolumes = array.list_volumes()
print('Gathering all volumes.')
# Create CSV output file
with open(rptFileName, 'w') as csvfile:
fieldnames = ['Volume_Name', 'Current_Data_Reduction', 'Data_Reduction_90_Days_Ago', 'Current_Size(GB)', 'Size_90_Days_Ago(GB)', '90_Day_Growth(GB)']
writer = csv.DictWriter(csvfile,fieldnames=fieldnames)
writer.writeheader()
print('Parsing volume data.')
# Loop through all volumes to get historical space data
for currentVol in allVolumes:
thisVol = array.get_volume(currentVol['name'], space='True', historical='90d')
volName = thisVol[0]['name']
volCurDR = round(thisVol[0]['data_reduction'],2)
volStartDR = round(thisVol[len(thisVol)-1]['data_reduction'],2)
volStartSize = round(thisVol[0]['volumes'] / 1000 / 1000 / 1000, 2)
volCurSize = round(thisVol[len(thisVol)-1]['volumes'] / 1000 / 1000 / 1000, 2)
volSizeDif = volCurSize - volStartSize
volSizeDif = round(volSizeDif, 2)
writer.writerow({'Volume_Name': volName, 'Current_Data_Reduction': volCurDR, 'Data_Reduction_90_Days_Ago': volStartDR, 'Current_Size(GB)': volCurSize, 'Size_90_Days_Ago(GB)': volStartSize, '90_Day_Growth(GB)': volSizeDif})
print('Script completed in ', round(time.time()-startTime,2), ' seconds.')
print('Output file: ', rptFileName, ' located at: ', os.getcwd())
array.invalidate_cookie()
sys.exit()