@@ -169,30 +169,36 @@ def get_instance_type_and_family_info(self, region):
169169 instance_types = sorted (instance_type_info .keys ())
170170
171171 logger .debug (f"Getting pricing info for { len (instance_types )} instance types:\n { json .dumps (instance_types , indent = 4 , sort_keys = True )} " )
172- logger .debug ("{ } instance types in {}" . format ( len ( instance_types ), region ) )
172+ logger .debug (f" { len ( instance_types ) } instance types in { region } " )
173173
174174 if self .get_savings_plans :
175175 savingsPlanInfo = SavingsPlanInfo (region )
176176
177177 count = 1
178178 for instanceType in sorted (instance_types ):
179- logger .debug ("instanceType: {}" . format ( instanceType ) )
179+ logger .debug (f "instanceType: { instanceType } " )
180180 os = 'Linux'
181181 pricing_filter = [
182- {'Field' : 'ServiceCode' , 'Value' : 'AmazonEC2' , 'Type' : 'TERM_MATCH' },
183- {'Field' : 'instanceType' , 'Value' : instanceType , 'Type' : 'TERM_MATCH' },
184- {'Field' : 'tenancy' , 'Value' : 'shared' , 'Type' : 'TERM_MATCH' },
185- {'Field' : 'preInstalledSw' , 'Value' : 'NA' , 'Type' : 'TERM_MATCH' },
186- {'Field' : 'location' , 'Value' : region_name , 'Type' : 'TERM_MATCH' },
187- {'Field' : 'operatingSystem' , 'Value' : os , 'Type' : 'TERM_MATCH' },
188- {'Field' : 'capacitystatus' , 'Value' : 'Used' , 'Type' : 'TERM_MATCH' },
182+ {'Field' : 'location' , 'Value' : region_name , 'Type' : 'TERM_MATCH' },
183+ {'Field' : 'instanceType' , 'Value' : instanceType , 'Type' : 'TERM_MATCH' },
184+ {'Field' : 'operatingSystem' , 'Value' : os , 'Type' : 'TERM_MATCH' },
185+ {'Field' : 'ServiceCode' , 'Value' : 'AmazonEC2' , 'Type' : 'TERM_MATCH' },
186+ {'Field' : 'tenancy' , 'Value' : 'shared' , 'Type' : 'TERM_MATCH' },
187+ {'Field' : 'preInstalledSw' , 'Value' : 'NA' , 'Type' : 'TERM_MATCH' },
188+ {'Field' : 'capacitystatus' , 'Value' : 'Used' , 'Type' : 'TERM_MATCH' },
189+ {'Field' : 'vpcnetworkingsupport' , 'Value' : 'true' , 'Type' : 'TERM_MATCH' },
190+ {'Field' : 'operation' , 'Value' : 'RunInstances' , 'Type' : 'TERM_MATCH' },
189191 ]
190192 priceLists = self .get_products (pricing_filter )
191193 if len (priceLists ) == 0 :
192194 logger .warning (f"No pricelist for { instanceType } { region } ({ region_name } ). Instance type may not be available in this region." )
193195 continue
194196 if len (priceLists ) > 1 :
195- raise RuntimeError ("Number of PriceLists > 1 for {}" .format (instanceType ))
197+ logger .error (f"Number of PriceLists > 1 for { instanceType } " )
198+ for index , priceListJson in enumerate (priceLists ):
199+ priceList = json .loads (priceListJson )
200+ logger .info (f"priceList[{ index } ]:\n { json .dumps (priceList , indent = 4 )} " )
201+ raise RuntimeError (f"Number of PriceLists > 1 for { instanceType } " )
196202
197203 instance_type_info [instanceType ]['pricing' ] = {}
198204 instance_type_info [instanceType ]['pricing' ]['Reserved' ] = {}
@@ -209,7 +215,7 @@ def get_instance_type_and_family_info(self, region):
209215 # instance_type_info[instanceType]['priceLists'] = []
210216 for priceListJson in priceLists :
211217 priceList = json .loads (priceListJson )
212- #logger.debug("pricelist:\n{}".format( pp.pformat(priceList)) )
218+ #logger.debug(f "pricelist:\n{pp.pformat(priceList)}" )
213219 #instance_type_info[instanceType]['priceLists'].append(priceList)
214220 if 'physicalProcessor' in priceList ['product' ]['attributes' ]:
215221 physicalProcessor = priceList ['product' ]['attributes' ]['physicalProcessor' ]
@@ -219,18 +225,18 @@ def get_instance_type_and_family_info(self, region):
219225 for dimensionKey , priceDimension in rateCode ['priceDimensions' ].items ():
220226 unit = priceDimension ['unit' ]
221227 if unit != 'Hrs' :
222- raise RuntimeError ("Unknown pricing unit: {}" . format ( unit ) )
228+ raise RuntimeError (f "Unknown pricing unit: { unit } " )
223229 currency = list (priceDimension ['pricePerUnit' ])[0 ]
224230 if currency != 'USD' :
225- raise RuntimeError ("Unknown currency: {}" . format ( currency ) )
231+ raise RuntimeError (f "Unknown currency: { currency } " )
226232 on_demand_price = float (priceDimension ['pricePerUnit' ]['USD' ])
227233 elif term == 'Reserved' :
228234 for ri_info_key , ri_info in termInfo .items ():
229235 attributes = ri_info ['termAttributes' ]
230236 ri_length = attributes ['LeaseContractLength' ]
231237 ri_class = attributes ['OfferingClass' ]
232238 ri_PurchaseOption = attributes ['PurchaseOption' ]
233- ri_terms = "RI {} {} {}" . format ( ri_length , ri_class , ri_PurchaseOption )
239+ ri_terms = f "RI { ri_length } { ri_class } { ri_PurchaseOption } "
234240 ri_length_hours = float (ri_length .split ('yr' )[0 ]) * 365 * 24
235241 ri_price = float (0 )
236242 for priceDimensionKey , priceDimension in ri_info ['priceDimensions' ].items ():
@@ -241,7 +247,7 @@ def get_instance_type_and_family_info(self, region):
241247 elif unit == 'Hrs' :
242248 ri_price += pricePerUnit
243249 else :
244- raise RuntimeError ("Invalid reserved instance unit {}" . format ( unit ) )
250+ raise RuntimeError (f "Invalid reserved instance unit { unit } " )
245251 instance_type_info [instanceType ]['pricing' ]['Reserved' ][ri_terms ] = ri_price
246252 if ri_price > ri_max_price :
247253 ri_max_price = max (ri_max_price , ri_price )
@@ -250,7 +256,7 @@ def get_instance_type_and_family_info(self, region):
250256 ri_min_price = ri_price
251257 ri_min_price_terms = ri_terms
252258 else :
253- raise RuntimeError ("Invalid term {}" . format ( term ) )
259+ raise RuntimeError (f "Invalid term { term } " )
254260 instance_type_info [instanceType ]['pricing' ]['Reserved_min' ] = ri_min_price
255261 instance_type_info [instanceType ]['pricing' ]['Reserved_min_terms' ] = ri_min_price_terms
256262 instance_type_info [instanceType ]['pricing' ]['Reserved_max' ] = ri_max_price
0 commit comments