-
Notifications
You must be signed in to change notification settings - Fork 16
/
get-ec2-prices
executable file
·73 lines (59 loc) · 2.43 KB
/
get-ec2-prices
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""Return a dic with prices for different ec2 providers
Uses pricing data from https://github.com/ilia-semenov/awspricingfull
To produce a csv file with ondemand ec2 prices:
import awspricingfull
allpricing = awspricingfull.EC2Prices().save_csv(u='ondemand',
path='/path/aws.csv')
Specify the csv file with prices and run with
./get_ec2_pricing.py /path/aws.csv
"""
import sys
import csv
import json
from libcloud.compute.types import Provider
if not len(sys.argv) == 2:
sys.exit('Provide csv file')
csv_file = sys.argv[1]
regions = {}
with open(csv_file, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
region = row[0]
size = row[1]
os = row[2]
price = row[3]
if not regions.get(region):
regions[region] = {}
if not regions[region].get(size):
regions[region][size] = {}
regions[region][size][os] = price
mist_regions = {}
mist_regions[Provider.EC2_EU_WEST] = regions['eu-west-1']
mist_regions[Provider.EC2_SA_EAST] = regions['sa-east-1']
mist_regions[Provider.EC2_AP_NORTHEAST] = regions['ap-northeast-1']
mist_regions[Provider.EC2_AP_SOUTHEAST2] = regions['ap-southeast-2']
mist_regions[Provider.EC2_AP_SOUTHEAST] = regions['ap-southeast-1']
mist_regions[Provider.EC2_US_WEST] = regions['us-west-1']
mist_regions[Provider.EC2_US_WEST_OREGON] = regions['us-west-2']
mist_regions[Provider.EC2_US_EAST] = regions['us-east-1']
mist_regions['ec2_us_east_ohio'] = regions['us-east-2']
mist_regions['ec2_eu_central'] = regions['eu-central-1']
mist_regions[Provider.EC2_AP_NORTHEAST2] = regions['ap-northeast-2']
mist_regions[Provider.EC2_AP_NORTHEAST1] = regions['ap-northeast-1']
mist_regions['ec2_ap_south_1'] = regions['ap-south-1']
mist_regions[Provider.EC2_CA_CENTRAL1] = regions['ca-central-1']
mist_regions[Provider.EC2_EU_WEST2] = regions['eu-west-2']
# formatting for easy copy/paste to mist.io/config.py
for provider in mist_regions:
print " \"%s\": {" % provider
for key in mist_regions[provider].keys()[:-1]:
print " \"%s\": %s," % (
key, json.dumps(mist_regions[provider][key])
)
key = mist_regions[provider].keys()[-1]
print " \"%s\": %s" % (
key, json.dumps(mist_regions[provider][key])
)
# don't use a comma for the last key, for valid JSON
print ' },\n'