|
46 | 46 | 'us': ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'], |
47 | 47 | } |
48 | 48 | AWS_SKU_INDEX = 'AwsSkuIndex' |
49 | | -# this map is necessary to map human-readable names from SKU attributes to |
50 | | -# region codes. I added method in cloud adapter to get this map, but it requires |
51 | | -# permission ssm:GetParameter, so it may not work on most accounts. That's why |
52 | | -# I saved it here |
53 | | -AWS_REGION_NAMES_TO_CODES = { |
54 | | - 'Africa (Cape Town)': 'af-south-1', |
55 | | - 'Asia Pacific (Hong Kong)': 'ap-east-1', |
56 | | - 'Asia Pacific (Tokyo)': 'ap-northeast-1', |
57 | | - 'Asia Pacific (Seoul)': 'ap-northeast-2', |
58 | | - 'Asia Pacific (Osaka)': 'ap-northeast-3', |
59 | | - 'Asia Pacific (Mumbai)': 'ap-south-1', |
60 | | - 'Asia Pacific (Hyderabad)': 'ap-south-2', |
61 | | - 'Asia Pacific (Singapore)': 'ap-southeast-1', |
62 | | - 'Asia Pacific (Sydney)': 'ap-southeast-2', |
63 | | - 'Asia Pacific (Jakarta)': 'ap-southeast-3', |
64 | | - 'Asia Pacific (Melbourne)': 'ap-southeast-4', |
65 | | - 'Asia Pacific (Malaysia)': 'ap-southeast-5', |
66 | | - 'Asia Pacific (Thailand)': 'ap-southeast-7', |
67 | | - 'Canada (Central)': 'ca-central-1', |
68 | | - 'Canada West (Calgary)': 'ca-west-1', |
69 | | - 'Europe (Frankfurt)': 'eu-central-1', |
70 | | - 'Europe (Zurich)': 'eu-central-2', |
71 | | - 'Europe (Stockholm)': 'eu-north-1', |
72 | | - 'Europe (Milan)': 'eu-south-1', |
73 | | - 'Europe (Spain)': 'eu-south-2', |
74 | | - 'Europe (Ireland)': 'eu-west-1', |
75 | | - 'Europe (London)': 'eu-west-2', |
76 | | - 'Europe (Paris)': 'eu-west-3', |
77 | | - 'Israel (Tel Aviv)': 'il-central-1', |
78 | | - 'Middle East (Bahrain)': 'me-south-1', |
79 | | - 'Middle East (UAE)': 'me-central-1', |
80 | | - 'Mexico (Central)': 'mx-central-1', |
81 | | - 'South America (Sao Paulo)': 'sa-east-1', |
82 | | - 'US East (N. Virginia)': 'us-east-1', |
83 | | - 'US East (Ohio)': 'us-east-2', |
84 | | - 'US West (N. California)': 'us-west-1', |
85 | | - 'US West (Oregon)': 'us-west-2', |
86 | | -} |
87 | 49 | unique_sku_fields = [ |
88 | 50 | 'location', |
89 | 51 | 'locationType', |
@@ -171,6 +133,11 @@ def get_skus_from_cloud(sku): |
171 | 133 | def get_aws_recommendations(self, instance_map, cloud_account_map, |
172 | 134 | excluded_pools): |
173 | 135 | result = [] |
| 136 | + coordinates = self.aws.get_regions_coordinates() |
| 137 | + aws_region_names_to_codes = {} |
| 138 | + for region_id, coord in coordinates.items(): |
| 139 | + if 'name' in coord: |
| 140 | + aws_region_names_to_codes[coord['name']] = region_id |
174 | 141 | res = self.mongo_client.restapi.raw_expenses.aggregate([ |
175 | 142 | {'$match': { |
176 | 143 | '$and': [ |
@@ -205,9 +172,9 @@ def get_aws_recommendations(self, instance_map, cloud_account_map, |
205 | 172 | for sku_dict in similar_skus: |
206 | 173 | _index = sku_dict['location'].index('(') |
207 | 174 | location_detailed = sku_dict['location'][_index:] |
208 | | - for test_region in AWS_REGION_NAMES_TO_CODES: |
| 175 | + for test_region in aws_region_names_to_codes: |
209 | 176 | if location_detailed in test_region: |
210 | | - region = AWS_REGION_NAMES_TO_CODES.get(test_region) |
| 177 | + region = aws_region_names_to_codes.get(test_region) |
211 | 178 | break |
212 | 179 | else: |
213 | 180 | continue |
|
0 commit comments