Skip to content
This repository was archived by the owner on Apr 9, 2021. It is now read-only.

Commit b38783e

Browse files
committed
GHOST-601: Handle previous generation AWS EC2 data
1 parent e4e08b3 commit b38783e

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

aws_data.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,17 @@ def load_instance_data(instance_types, regions):
146146
for region in regions:
147147
if region not in instance_types:
148148
instance_types[region] = []
149-
region_data = get_aws_per_region_data(region)
150-
if not region_data:
149+
aws_db_data = get_aws_per_region_data(region)
150+
if not aws_db_data:
151151
print 'Cannot get region {r}'.format(r=region)
152152
continue
153-
for p in region_data['prices']:
154-
size = p['attributes']
155-
instance_types[region].append(InstanceType(name=size['aws:ec2:instanceType'],
156-
cores=size['aws:ec2:vcpu'],
157-
memory=size['aws:ec2:memory'],
158-
disk=size['aws:ec2:storage']))
153+
for region_data in [aws_db_data.get('data_latest', {}), aws_db_data.get('data_previous', {})]:
154+
for p in region_data.get('prices', []):
155+
size = p['attributes']
156+
instance_types[region].append(InstanceType(name=size['aws:ec2:instanceType'],
157+
cores=size['aws:ec2:vcpu'],
158+
memory=size['aws:ec2:memory'],
159+
disk=size['aws:ec2:storage']))
159160

160161

161162
load_instance_data(instance_types, regions_locations)

aws_data_updater.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
from aws_data import regions_locations
1414

1515
AWS_INSTANCES_DATA_URL = 'https://d2xn1uj035lhvj.cloudfront.net/pricing/1.0/ec2/region/{region}/ondemand/linux/index.json'
16+
AWS_OLD_INSTANCES_DATA_URL = 'https://d2xn1uj035lhvj.cloudfront.net/pricing/1.0/ec2/region/{region}/previous-generation/ondemand/linux/index.json'
1617

1718

18-
def get_region_data(aws_region):
19-
with requests.get(AWS_INSTANCES_DATA_URL.format(region=aws_region)) as resp:
19+
def get_region_data(aws_region, url):
20+
with requests.get(url.format(region=aws_region)) as resp:
2021
if resp.status_code != 200:
2122
print 'Cannot get region {r}'.format(r=aws_region)
2223
return None
@@ -36,7 +37,9 @@ def main():
3637
args = parse_args()
3738
for aws_region in [args.region] if args.region else regions_locations:
3839
print('Updating AWS Data for region "{r}"'.format(r=aws_region))
39-
update_aws_data_region(aws_region, get_region_data(aws_region))
40+
old_region_data = get_region_data(aws_region, AWS_OLD_INSTANCES_DATA_URL) or {}
41+
latest_region_data = get_region_data(aws_region, AWS_INSTANCES_DATA_URL) or {}
42+
update_aws_data_region(aws_region, old_region_data, latest_region_data)
4043

4144

4245
if __name__ == '__main__':

data/aws_data_dal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def get_aws_per_region_data(aws_region):
2525
if not aws_region:
2626
return None
2727
region_data = db.aws_data.find_one({'region': aws_region})
28-
return region_data['data'] if region_data else None
28+
return region_data
2929

3030

31-
def update_aws_data_region(aws_region, json_data):
31+
def update_aws_data_region(aws_region, json_latest_data, json_previous_data):
3232
return db.aws_data.replace_one(
3333
{'region': aws_region},
34-
{'region': aws_region, 'data': json_data},
34+
{'region': aws_region, 'data_latest': json_latest_data, 'data_previous': json_previous_data},
3535
upsert=True,
3636
)

0 commit comments

Comments
 (0)