MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / buildPriceEntries

Function buildPriceEntries

internal/estimate/estimator.go:400–483  ·  view source on GitHub ↗

buildPriceEntries converts an api.PricingItem into a sorted slice of PriceEntry. OnDemand is always first; the rest are sorted by model name, then rate.

(item api.PricingItem)

Source from the content-addressed store, hash-verified

398// buildPriceEntries converts an api.PricingItem into a sorted slice of PriceEntry.
399// OnDemand is always first; the rest are sorted by model name, then rate.
400func buildPriceEntries(item api.PricingItem) ([]resources.PriceEntry, decimal.Decimal) {
401 var entries []resources.PriceEntry
402 var onDemandRate decimal.Decimal
403
404 for _, p := range item.Prices {
405 model := ""
406 if p.PricingModel != nil {
407 model = *p.PricingModel
408 }
409 purchaseOption := ""
410 if p.PurchaseOption != nil {
411 purchaseOption = *p.PurchaseOption
412 }
413 term := ""
414 if p.Year != nil {
415 term = p.Year.String()
416 }
417 upfront := ""
418 if p.UpfrontFee != nil {
419 upfront = p.UpfrontFee.String()
420 }
421 unit := ""
422 if p.Unit != nil {
423 unit = *p.Unit
424 }
425
426 rate := decimal.Zero
427 if len(p.Rates) > 0 && p.Rates[0].Price != nil {
428 if d, err := decimal.NewFromString(p.Rates[0].Price.String()); err == nil {
429 rate = d
430 }
431 }
432
433 isCurrent := strings.EqualFold(model, "OnDemand")
434 if isCurrent && rate.GreaterThan(onDemandRate) {
435 onDemandRate = rate
436 }
437
438 isUsage := !isHourlyUnit(unit)
439
440 // Build rate tiers for volume-based pricing (more than one rate).
441 var tiers []resources.RateTier
442 if len(p.Rates) > 1 {
443 for _, r := range p.Rates {
444 tier := resources.RateTier{}
445 if r.Price != nil {
446 tier.Price = r.Price.String()
447 }
448 if r.StartRange != nil {
449 tier.StartRange = r.StartRange.String()
450 }
451 if r.EndRange != nil {
452 tier.EndRange = r.EndRange.String()
453 }
454 tiers = append(tiers, tier)
455 }
456 }
457

Callers 1

EstimateAllResourcesFunction · 0.85

Calls 2

isHourlyUnitFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected