Created
April 24, 2019 19:18
-
-
Save kbcaleb/fdb633bf82e81ae1878c871c95ce35ae to your computer and use it in GitHub Desktop.
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
import boto3 | |
import sys | |
import locale | |
# Currency locale | |
locale.setlocale( locale.LC_ALL, 'en_US' ) | |
# Profile array | |
profiles = ['aws-profile1', 'aws-profile2', 'aws-profile-3'] | |
for profile in profiles: | |
aws = boto3.session.Session(profile_name=profile) | |
ec2 = aws.client('ec2') | |
# Find all io1 drives | |
# TODO "NextToken" > 500 results | |
servers = ec2.describe_volumes( | |
Filters=[ | |
{ | |
'Name': 'volume-type', | |
'Values': [ | |
'io1' | |
] | |
} | |
] | |
) | |
# Zero counts | |
totalSizeSum = 0 | |
totalPiopSum = 0 | |
totalCost = 0 | |
snapTotalSizeSum = 0 | |
snapTotalPiopSum = 0 | |
snapTotalCost = 0 | |
# Iterate | |
if (len(servers['Volumes']) != 0): | |
for server in servers['Volumes']: | |
snapId = server['SnapshotId'] | |
volumeState = server['State'] | |
if (volumeState == 'in-use'): | |
# price out non-snapshot volumes | |
if (len(snapId) == 0): | |
# Check for empties & sum up | |
if "Size" in server: | |
totalSizeSum = totalSizeSum+server['Size'] | |
# Check for empties & sum up | |
if "Iops" in server: | |
totalPiopSum = totalPiopSum+server['Iops'] | |
# price out snapshot volumes | |
else: | |
# Check for empties & sum up | |
if "Size" in server: | |
snapTotalSizeSum = snapTotalSizeSum+server['Size'] | |
# Check for empties & sum up | |
if "Iops" in server: | |
snapTotalPiopSum = snapTotalPiopSum+server['Iops'] | |
# Price out non-snapshots | |
totalSizeCost = (totalSizeSum*.125) | |
totalPiopCost = totalPiopSum*.065 | |
totalCost = totalSizeCost+totalPiopCost | |
annualCost = totalCost*12 | |
# Price out snapshots | |
snapTotalSizeCost = (snapTotalSizeSum*.125) | |
snapTotalPiopCost = snapTotalPiopSum*.065 | |
snapTotalCost = snapTotalSizeCost+snapTotalPiopCost | |
snapAnnualCost = snapTotalCost*12 | |
# Sum it all | |
FinalTotal = totalCost+snapTotalCost | |
annualFinalTotal = FinalTotal*12 | |
# Return cost | |
if totalCost or snapTotalCost != 0: | |
print("================================") | |
print(profile,"- Total Annual PIOP's cost: ",locale.currency(annualFinalTotal, grouping=True)) | |
print(profile,"- Monthly PIOP's snapshot cost : ",locale.currency(snapTotalCost, grouping=True)) | |
print(profile,"- Monthly PIOP's non-snapshot cost : ",locale.currency(totalCost, grouping=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment