in pkg/ec2pricing/ec2pricing.go [166:208]
func (p *EC2Pricing) GetOndemandInstanceTypeCost(instanceType string) (float64, error) {
// Check cache first and return it if available
if price, ok := p.onDemandCache[instanceType]; ok {
return price, nil
}
regionDescription := p.getRegionForPricingAPI()
// TODO: mac.metal instances cannot be found with the below filters
productInput := pricing.GetProductsInput{
ServiceCode: aws.String(serviceCode),
Filters: []*pricing.Filter{
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("ServiceCode"), Value: aws.String(serviceCode)},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("operatingSystem"), Value: aws.String("linux")},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("location"), Value: aws.String(regionDescription)},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("capacitystatus"), Value: aws.String("used")},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("preInstalledSw"), Value: aws.String("NA")},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("tenancy"), Value: aws.String("shared")},
{Type: aws.String(pricing.FilterTypeTermMatch), Field: aws.String("instanceType"), Value: aws.String(instanceType)},
},
}
pricePerUnitInUSD := float64(-1)
var processingErr error
errAPI := p.PricingClient.GetProductsPages(&productInput, func(pricingOutput *pricing.GetProductsOutput, nextPage bool) bool {
var errParse error
for _, priceDoc := range pricingOutput.PriceList {
_, pricePerUnitInUSD, errParse = parseOndemandUnitPrice(priceDoc)
if errParse != nil {
processingErr = multierr.Append(processingErr, errParse)
// keep going through pages if we can't parse the pricing doc
return true
}
}
return false
})
if errAPI != nil {
return -1, errAPI
}
if processingErr != nil {
return -1, processingErr
}
return pricePerUnitInUSD, nil
}