Skip to content

Commit e5707fa

Browse files
committed
update w/compEngId workaround and to meet luna pricing needs
1 parent 933c84a commit e5707fa

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

internal/cloudinfo/providers/google/cloudinfo.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (g *GceInfoer) Initialize() (map[string]map[string]types.Price, error) {
203203
region := r
204204
price := pricePerRegion[region]
205205
for _, mt := range allMts.Items {
206-
if !cloudinfo.Contains(unsupportedInstanceTypes, mt.Name) {
206+
if !cloudinfo.Contains(unsupportedInstanceTypes, mt.Name) && !strings.HasSuffix(mt.Name, "-metal") {
207207
if allPrices[zone] == nil {
208208
allPrices[zone] = make(map[string]types.Price)
209209
}
@@ -243,6 +243,8 @@ func (g *GceInfoer) Initialize() (map[string]map[string]types.Price, error) {
243243
}
244244

245245
func (g *GceInfoer) getPrice() (map[string]map[string]map[string]float64, error) {
246+
logger := log.WithFields(g.log, map[string]interface{}{"service": "compute"})
247+
logger.Debug("getting price")
246248
svcList, err := g.cbSvc.Services.List().Fields("services/displayName", "services/name").Do()
247249
if err != nil {
248250
return nil, err
@@ -254,10 +256,17 @@ func (g *GceInfoer) getPrice() (map[string]map[string]map[string]float64, error)
254256
compEngId = svc.Name
255257
}
256258
}
259+
// Working around "Compute Engine" not found in svcList; presumably, list needs to be fetched as multiple pages
260+
if compEngId == "" {
261+
compEngId = "services/6F81-5844-456A"
262+
}
257263

258264
price := make(map[string]map[string]map[string]float64)
259265
err = g.cbSvc.Services.Skus.List(compEngId).Pages(context.Background(), func(response *cloudbilling.ListSkusResponse) error {
260266
for _, sku := range response.Skus {
267+
if strings.Contains(sku.Description, "Upgrade Premium") || strings.Contains(sku.Description, "DWS Defined Duration") {
268+
continue
269+
}
261270
if sku.Category.ResourceGroup == "G1Small" || sku.Category.ResourceGroup == "F1Micro" {
262271
priceInUsd, err := g.priceInUsd(sku.PricingInfo)
263272
if err != nil {
@@ -274,25 +283,26 @@ func (g *GceInfoer) getPrice() (map[string]map[string]map[string]float64, error)
274283
price[region]["f1-micro"] = g.priceFromSku(price, region, "f1-micro", sku.Category.UsageType, priceInUsd)
275284
}
276285
}
277-
}
278-
if sku.Category.ResourceGroup == "N1Standard" {
279-
if !strings.Contains(sku.Description, "Upgrade Premium") {
280-
priceInUsd, err := g.priceInUsd(sku.PricingInfo)
281-
if err != nil {
282-
return err
283-
}
286+
} else if sku.Category.ResourceGroup == "N1Standard" {
287+
priceInUsd, err := g.priceInUsd(sku.PricingInfo)
288+
if err != nil {
289+
return err
290+
}
284291

285-
for _, region := range sku.ServiceRegions {
286-
if price[region] == nil {
287-
price[region] = make(map[string]map[string]float64)
288-
}
289-
if strings.Contains(sku.Description, "Instance Ram") {
290-
price[region][types.Memory] = g.priceFromSku(price, region, types.Memory, sku.Category.UsageType, priceInUsd)
291-
} else {
292-
price[region][types.CPU] = g.priceFromSku(price, region, types.CPU, sku.Category.UsageType, priceInUsd)
293-
}
292+
for _, region := range sku.ServiceRegions {
293+
if price[region] == nil {
294+
price[region] = make(map[string]map[string]float64)
295+
}
296+
if strings.Contains(sku.Description, "Instance Ram") {
297+
price[region][types.Memory] = g.priceFromSku(price, region, types.Memory, sku.Category.UsageType, priceInUsd)
298+
} else if strings.Contains(sku.Description, "Instance Core") {
299+
price[region][types.CPU] = g.priceFromSku(price, region, types.CPU, sku.Category.UsageType, priceInUsd)
300+
} else {
301+
logger.Debug("ignoring N1Standard", map[string]interface{}{"sku": sku})
294302
}
295303
}
304+
} else if sku.Category.UsageType == "OnDemand" {
305+
logger.Debug("unrecognized sku.Category.ResourceGroup", map[string]interface{}{"sku": sku})
296306
}
297307
}
298308
return nil

0 commit comments

Comments
 (0)