-
-
Save sysbot/3302b0d7815732df2ddf 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
#!/usr/bin/python | |
import urllib2 | |
import json | |
import pprint | |
pp = pprint.PrettyPrinter(indent=4) | |
class instance_size: | |
def __init__(self): | |
pass | |
joes_intermed = dict() | |
urls = list() | |
for i in [ "", "previous-generation/" ]: | |
for j in [ "mswin" , "linux" ]: | |
urls.append("https://a0.awsstatic.com/pricing/1/deprecated/ec2/{}{}-od.json".format(i,j)) | |
for url in urls: | |
try: | |
instances = json.loads(urllib2.urlopen(url).read()) | |
except: | |
print url | |
continue | |
for i in instances['config']['regions']: | |
region = i['region'] | |
types = i['instanceTypes'] | |
# print region # , types | |
for itype in types: | |
# print itype | |
typename = itype['type'] | |
sizes = itype['sizes'] | |
for size in sizes: | |
# print size | |
instancename = size['size'] | |
# print instancename | |
if instancename not in joes_intermed: | |
joes_intermed[instancename] = dict() | |
joes_intermed[instancename]['family'] = typename | |
vcpu = int(size.get('vCPU',0)) | |
joes_intermed[instancename]['vCPU'] = vcpu | |
joes_intermed[instancename]['instance_type'] = instancename | |
joes_intermed[instancename]['ECU'] = float(vcpu * 2.75) # this is me bluffing | |
joes_intermed[instancename]['memory'] = float(size.get('memoryGiB',0)) | |
joes_intermed[instancename]['arch'] = ['x86_64'] | |
joes_intermed[instancename]['vpc'] = dict() | |
joes_intermed[instancename]['vpc']['ips_per_eni'] = 1 | |
joes_intermed[instancename]['vpc']['max_enis'] = 1 | |
joes_intermed[instancename]['network_performance'] = "Very Low" | |
joes_intermed[instancename]['pricing'] = dict() | |
joes_intermed[instancename]["ebs_optimized"] = False | |
joes_intermed[instancename]["storage"] = dict() | |
joes_intermed[instancename]["storage"]['ssd'] = ('SSD' in size.get('storageGB','')) | |
try: | |
joes_intermed[instancename]["storage"]['devices'] = int(size.get('storageGB','').split()[0]) | |
joes_intermed[instancename]["storage"]['size'] = int(size.get('storageGB','').split()[2]) | |
except: | |
joes_intermed[instancename]["storage"]['devices'] = 0 | |
joes_intermed[instancename]["storage"]['size'] = 0 | |
if 2 == len(region.split('-')): | |
region = region + "-1" | |
if region not in joes_intermed[instancename]['pricing']: | |
joes_intermed[instancename]['pricing'][region] = dict() | |
for i in size['valueColumns']: | |
os = i['name'] | |
price = i['prices']['USD'] | |
if 'os' == os: | |
joes_intermed[instancename]['pricing'][region]['linux'] = price | |
joes_intermed[instancename]['pricing'][region]['mswin'] = price | |
else: | |
joes_intermed[instancename]['pricing'][region][os] = price | |
ans = list() | |
for i in joes_intermed.itervalues(): | |
ans.append(i) | |
# pp.pprint(joes_intermed) | |
json.dump(ans, open('instances.json','w')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment