Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Add basic GCP pricing support
Browse files Browse the repository at this point in the history
  • Loading branch information
rnarenpujari committed Jul 28, 2019
1 parent ed8fdb5 commit 221ebbb
Show file tree
Hide file tree
Showing 7 changed files with 9,284 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/controller/dgraph/models/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (

// Cloud provider constants
AWS = "aws"
GCP = "gcp"

// Time constants
HoursInMonth = 720
Expand Down
13 changes: 9 additions & 4 deletions pkg/controller/dgraph/models/rateCard.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ func getPerUnitResourcePriceForNode(nodeName string) (float64, float64) {
}

func getPricePerUnitResourceFromNodePrice(node Node) (float64, float64) {
nodePriceXID := node.InstanceType + "-" + node.OS
nodePrice, err := retrieveNodePrice(nodePriceXID)
if err == nil {
return nodePrice.PricePerCPU, nodePrice.PricePerMemory
xidsToTry := []string{
node.InstanceType + "-" + node.OS,
node.InstanceType + "-ANY",
}
for _, xid := range xidsToTry {
nodePrice, err := retrieveNodePrice(xid)
if err == nil {
return nodePrice.PricePerCPU, nodePrice.PricePerMemory
}
}
return DefaultCPUCostInFloat64, DefaultMemCostInFloat64
}
12 changes: 11 additions & 1 deletion pkg/pricing/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/Sirupsen/logrus"
"github.com/vmware/purser/pkg/controller/dgraph/models"
"github.com/vmware/purser/pkg/pricing/aws"
"github.com/vmware/purser/pkg/pricing/gcp"
"k8s.io/client-go/kubernetes"
)

Expand All @@ -42,9 +43,18 @@ func GetClusterProviderAndRegion() (string, string) {

// PopulateRateCard given a cloud (cloudProvider and region) it populates corresponding rate card in dgraph
func (c *Cloud) PopulateRateCard() {
var rateCard *models.RateCard

switch c.CloudProvider {
case models.AWS:
rateCard := aws.GetRateCardForAWS(c.Region)
rateCard = aws.GetRateCardForAWS(c.Region)
case models.GCP:
rateCard = gcp.GetRateCardForGCP(c.Region)
}

if rateCard != nil {
models.StoreRateCard(rateCard)
} else {
logrus.Printf("Could not get rate card")
}
}
Loading

0 comments on commit 221ebbb

Please sign in to comment.