computeengine

package
v0.0.0-...-dc510da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: OSL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package computeengine provides GCP Compute Engine Committed Use Discounts client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingService

type BillingService interface {
	ListSKUs(serviceID string) (*cloudbilling.ListSkusResponse, error)
}

BillingService interface for billing operations (enables mocking)

type CommitmentRequest

type CommitmentRequest struct {
	Name      string // unique per region+project
	Plan      string // "TWELVE_MONTH" or "THIRTY_SIX_MONTH"
	Region    string
	Resources []ResourceCommitment
}

CommitmentRequest represents a single GCP commitment to create.

func GroupCommitments

func GroupCommitments(recs []common.Recommendation) []CommitmentRequest

GroupCommitments groups recommendations by project+region+term into CommitmentRequests. GCP requires both a VCPU and a MEMORY resource (memory Amount in MB) in a single commitments.insert call. Each recommendation's Count is treated as vCPU count; the memory Amount is read from ComputeDetails.MemoryGB (populated by extractMemoryMBFromRecommendation). Recommendations with an unrecognized term or missing memory are skipped with a log warning so a bad rec never contaminates an otherwise valid group.

type CommitmentsIterator

type CommitmentsIterator interface {
	Next() (*computepb.Commitment, error)
}

CommitmentsIterator interface for commitments iteration (enables mocking)

type CommitmentsOperation

type CommitmentsOperation interface {
	Wait(ctx context.Context, opts ...gax.CallOption) error
}

CommitmentsOperation interface for commitment operations (enables mocking)

type CommitmentsService

CommitmentsService interface for commitments operations (enables mocking)

type ComputeEngineClient

type ComputeEngineClient struct {
	// contains filtered or unexported fields
}

ComputeEngineClient handles GCP Compute Engine Committed Use Discounts

func NewClient

func NewClient(ctx context.Context, projectID, region string, opts ...option.ClientOption) (*ComputeEngineClient, error)

NewClient creates a new GCP Compute Engine client

func (*ComputeEngineClient) GetExistingCommitments

func (c *ComputeEngineClient) GetExistingCommitments(ctx context.Context) ([]common.Commitment, error)

GetExistingCommitments retrieves existing Compute Engine CUDs

func (*ComputeEngineClient) GetOfferingDetails

GetOfferingDetails retrieves CUD offering details from GCP Billing API

func (*ComputeEngineClient) GetRecommendations

GetRecommendations gets CUD recommendations from GCP Recommender API

func (*ComputeEngineClient) GetRegion

func (c *ComputeEngineClient) GetRegion() string

GetRegion returns the region

func (*ComputeEngineClient) GetServiceType

func (c *ComputeEngineClient) GetServiceType() common.ServiceType

GetServiceType returns the service type

func (*ComputeEngineClient) GetValidResourceTypes

func (c *ComputeEngineClient) GetValidResourceTypes(ctx context.Context) ([]string, error)

GetValidResourceTypes returns valid machine types from GCP Compute API

func (*ComputeEngineClient) PurchaseCommitment

PurchaseCommitment purchases a Compute Engine CUD

func (*ComputeEngineClient) SetBillingService

func (c *ComputeEngineClient) SetBillingService(svc BillingService)

SetBillingService sets the billing service (for testing)

func (*ComputeEngineClient) SetCommitmentsService

func (c *ComputeEngineClient) SetCommitmentsService(svc CommitmentsService)

SetCommitmentsService sets the commitments service (for testing)

func (*ComputeEngineClient) SetMachineTypesService

func (c *ComputeEngineClient) SetMachineTypesService(svc MachineTypesService)

SetMachineTypesService sets the machine types service (for testing)

func (*ComputeEngineClient) SetRecommenderClient

func (c *ComputeEngineClient) SetRecommenderClient(client RecommenderClient)

SetRecommenderClient sets the recommender client (for testing)

func (*ComputeEngineClient) ValidateOffering

func (c *ComputeEngineClient) ValidateOffering(ctx context.Context, rec common.Recommendation) error

ValidateOffering validates that a machine type exists

type ComputePricing

type ComputePricing struct {
	HourlyRate        float64
	CommitmentPrice   float64
	OnDemandPrice     float64
	Currency          string
	SavingsPercentage float64
}

ComputePricing contains pricing information for Compute Engine

type MachineTypesIterator

type MachineTypesIterator interface {
	Next() (*computepb.MachineType, error)
}

MachineTypesIterator interface for machine types iteration (enables mocking)

type MachineTypesService

type MachineTypesService interface {
	List(ctx context.Context, req *computepb.ListMachineTypesRequest) MachineTypesIterator
	Close() error
}

MachineTypesService interface for machine types operations (enables mocking)

type RecommenderClient

type RecommenderClient interface {
	ListRecommendations(ctx context.Context, req *recommenderpb.ListRecommendationsRequest) RecommenderIterator
	Close() error
}

RecommenderClient interface for recommender operations (enables mocking)

type RecommenderIterator

type RecommenderIterator interface {
	Next() (*recommenderpb.Recommendation, error)
}

RecommenderIterator interface for recommender iteration (enables mocking)

type ResourceCommitment

type ResourceCommitment struct {
	Amount int64  // number of vCPUs or memory in MB
	Type   string // GCP ResourceCommitment.Type enum: "VCPU" or "MEMORY"
}

ResourceCommitment represents a single resource within a GCP commitment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL