cloudinfo

package
v0.0.0-...-2215086 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// vmKeyTemplate format for generating vm cache keys
	VmKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services/%s/regions/%s/vms"

	// priceKeyTemplate format for generating price cache keys
	PriceKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/regions/%s/prices/%s"

	// zoneKeyTemplate format for generating zone cache keys
	ZoneKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services/%s/regions/%s/zones/"

	// regionKeyTemplate format for generating region cache keys
	RegionKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services/%s/regions/"

	// statusKeyTemplate format for generating status cache keys
	StatusKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/status/"

	// imageKeyTemplate format for generating image cache keys
	ImageKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services/%s/regions/%s/images"

	// versionKeyTemplate format for generating kubernetes version cache keys
	VersionKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services/%s/regions/%s/versions"

	// servicesKeyTemplate key for storing provider specific services
	ServicesKeyTemplate = "/banzaicloud.com/cloudinfo/providers/%s/services"
)

Variables

Functions

func Attributes

func Attributes(cpu, memory, ntwPerfCat, vmCategory string) map[string]string

Attributes create a map with the specified parameters

func Contains

func Contains(slice []string, s string) bool

Contains is a helper function to check if a slice contains a string

func CreateString

func CreateString(keys ...string) string

CreateString builds strings effectively

func NewCloudInfo

func NewCloudInfo(providers []string, ciStore CloudInfoStore, logger Logger) (*cloudInfo, error)

NewCloudInfo creates a new cloudInfo instance

func NewScrapingManager

func NewScrapingManager(provider string, infoer CloudInfoer, store CloudInfoStore, log Logger,
	metrics metrics.Reporter, tracer tracing.Tracer, eventBus messaging.EventBus, errorHandler ErrorHandler) *scrapingManager

Types

type CloudInfoStore

type CloudInfoStore interface {
	Ready() bool

	StoreRegions(provider, service string, val map[string]string)
	GetRegions(provider, service string) (map[string]string, bool)
	DeleteRegions(provider, service string)

	StoreZones(provider, service, region string, val []string)
	GetZones(provider, service, region string) ([]string, bool)
	DeleteZones(provider, service, region string)

	StorePrice(provider, region, instanceType string, val types.Price)
	GetPrice(provider, region, instanceType string) (types.Price, bool)

	StoreVm(provider, service, region string, val []types.VMInfo)
	GetVm(provider, service, region string) ([]types.VMInfo, bool)
	DeleteVm(provider, service, region string)

	StoreImage(provider, service, regionId string, val []types.Image)
	GetImage(provider, service, regionId string) ([]types.Image, bool)
	DeleteImage(provider, service, regionId string)

	StoreVersion(provider, service, region string, val []types.LocationVersion)
	GetVersion(provider, service, region string) ([]types.LocationVersion, bool)
	DeleteVersion(provider, service, region string)

	StoreStatus(provider string, val string)
	GetStatus(provider string) (string, bool)

	StoreServices(provider string, services []types.Service)
	GetServices(provider string) ([]types.Service, bool)

	Export(w io.Writer) error
	Import(r io.Reader) error

	Close()
}

Storage operations for cloud information

type CloudInfoer

type CloudInfoer interface {
	// Initialize is called once per product info renewals so it can be used to download a large price descriptor
	Initialize() (map[string]map[string]types.Price, error)

	// GetVirtualMachines retrieves the available virtual machines in a region
	GetVirtualMachines(region string) ([]types.VMInfo, error)

	// GetProducts gets product information based on the given arguments from an external system
	GetProducts(vms []types.VMInfo, service, regionId string) ([]types.VMInfo, error)

	// GetZones returns the availability zones in a region
	GetZones(region string) ([]string, error)

	// GetRegions retrieves the available regions form the external system
	GetRegions(service string) (map[string]string, error)

	// HasShortLivedPriceInfo signals if a product info provider has frequently changing price info
	HasShortLivedPriceInfo() bool

	// GetCurrentPrices retrieves all the spot prices in a region
	GetCurrentPrices(region string) (map[string]types.Price, error)

	// HasImages signals if a product info provider has image support
	HasImages() bool

	// GetServiceImages retrieves the images supported by the given service in the given region
	GetServiceImages(service, region string) ([]types.Image, error)

	// GetVersions retrieves the  versions supported by the given service in the given region
	GetVersions(service, region string) ([]types.LocationVersion, error)

	// GetServiceProducts retrieves the products supported by the given service in the given region
	GetServiceProducts(region, service string) ([]types.ProductDetails, error)
}

CloudInfoer lists operations for retrieving cloud provider information Implementers are expected to know the cloud provider specific logic (eg.: cloud provider client usage etc ...) This interface abstracts the cloud provider specifics to its clients

type ErrorHandler

type ErrorHandler interface {
	// Handle handles an error.
	Handle(err error)
}

ErrorHandler handles an error.

type Executor

type Executor interface {
	Execute(ctx context.Context, sf TaskFn) error
}

Executor

func NewPeriodicExecutor

func NewPeriodicExecutor(period time.Duration, log Logger) Executor

NewPeriodicExecutor creates a new Executor with the given time period

type FloatFilter

type FloatFilter struct {
	Lt  *float64
	Lte *float64
	Gt  *float64
	Gte *float64
	Eq  *float64
	Ne  *float64
	In  []float64
	Nin []float64
}

FloatFilter represents the query operators for a float field.

type InMemoryInstanceTypeStore

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

InMemoryInstanceTypeStore keeps instance types in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryInstanceTypeStore

func NewInMemoryInstanceTypeStore() *InMemoryInstanceTypeStore

NewInMemoryInstanceTypeStore returns a new InMemoryInstanceTypeStore.

func (*InMemoryInstanceTypeStore) GetProductDetails

func (s *InMemoryInstanceTypeStore) GetProductDetails(provider string, service string, region string) ([]types.ProductDetails, error)

GetProductDetails retrieves product details from the given provider and region.

func (*InMemoryInstanceTypeStore) GetZones

func (s *InMemoryInstanceTypeStore) GetZones(provider, service, region string) ([]string, error)

GetZones returns all the availability zones for a region.

type InMemoryProviderStore

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

InMemoryProviderStore keeps providers in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryProviderStore

func NewInMemoryProviderStore() *InMemoryProviderStore

NewInMemoryProviderStore returns a new InMemoryProviderStore.

func (*InMemoryProviderStore) GetProviders

func (s *InMemoryProviderStore) GetProviders() ([]types.Provider, error)

type InMemoryRegionStore

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

InMemoryRegionStore keeps regions in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryRegionStore

func NewInMemoryRegionStore() *InMemoryRegionStore

NewInMemoryRegionStore returns a new InMemoryRegionStore.

func (*InMemoryRegionStore) GetRegions

func (s *InMemoryRegionStore) GetRegions(provider string, service string) (map[string]string, error)

func (*InMemoryRegionStore) GetZones

func (s *InMemoryRegionStore) GetZones(provider string, service string, region string) ([]string, error)

type InMemoryServiceStore

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

InMemoryServiceStore keeps services in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryServiceStore

func NewInMemoryServiceStore() *InMemoryServiceStore

NewInMemoryServiceStore returns a new InMemoryServiceStore.

func (*InMemoryServiceStore) GetServices

func (s *InMemoryServiceStore) GetServices(provider string) ([]types.Service, error)

type InstanceType

type InstanceType struct {
	Name            string
	Region          string
	Zone            string
	Price           float64
	SpotPrice       float64
	CPU             float64
	Memory          float64
	Gpu             float64
	NetworkCategory NetworkCategory
	Category        InstanceTypeCategory
}

InstanceType represents a single instance type.

type InstanceTypeCategory

type InstanceTypeCategory string
const (
	InstanceTypeCategoryGeneralPurpose   InstanceTypeCategory = "GENERAL_PURPOSE"
	InstanceTypeCategoryMemoryOptimized  InstanceTypeCategory = "MEMORY_OPTIMIZED"
	InstanceTypeCategoryStorageOptimized InstanceTypeCategory = "STORAGE_OPTIMIZED"
	InstanceTypeCategoryComputeOptimized InstanceTypeCategory = "COMPUTE_OPTIMIZED"
)

func (InstanceTypeCategory) IsValid

func (e InstanceTypeCategory) IsValid() bool

func (InstanceTypeCategory) MarshalGQL

func (e InstanceTypeCategory) MarshalGQL(w io.Writer)

func (InstanceTypeCategory) String

func (e InstanceTypeCategory) String() string

func (*InstanceTypeCategory) UnmarshalGQL

func (e *InstanceTypeCategory) UnmarshalGQL(v interface{}) error

type InstanceTypeCategoryFilter

type InstanceTypeCategoryFilter struct {
	Eq  *InstanceTypeCategory
	Ne  *InstanceTypeCategory
	In  []InstanceTypeCategory
	Nin []InstanceTypeCategory
}

IntFilter represents the query operators for an instance type network category field.

type InstanceTypeQuery

type InstanceTypeQuery struct {
	Region *string
	Zone   *string
	Filter *InstanceTypeQueryFilter
}

InstanceTypeQuery represents the input parameters if an instance type query.

type InstanceTypeQueryFilter

type InstanceTypeQueryFilter struct {
	Price           *FloatFilter
	SpotPrice       *FloatFilter
	Spot            *bool
	CPU             *FloatFilter
	Memory          *FloatFilter
	Gpu             *FloatFilter
	NetworkCategory *NetworkCategoryFilter
	Category        *InstanceTypeCategoryFilter
}

InstanceTypeQueryFilter filters instance types by their fields.

type InstanceTypeQueryValidationError

type InstanceTypeQueryValidationError struct {
	Message string
}

InstanceTypeQueryValidationError is returned if an instance type query is invalid.

func (InstanceTypeQueryValidationError) Error

Error implements the error interface.

func (InstanceTypeQueryValidationError) IsBusinessError

func (InstanceTypeQueryValidationError) IsBusinessError() bool

IsBusinessError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead.

type InstanceTypeService

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

InstanceTypeService filters instance types according to the received query.

func NewInstanceTypeService

func NewInstanceTypeService(store InstanceTypeStore) *InstanceTypeService

NewInstanceTypeService returns a new InstanceTypeService.

func (*InstanceTypeService) Query

func (s *InstanceTypeService) Query(ctx context.Context, provider string, service string, query InstanceTypeQuery) ([]InstanceType, error)

Query processes an instance type query and responds with a list match of instance types matching that query.

type InstanceTypeStore

type InstanceTypeStore interface {
	// GetProductDetails retrieves product details from the given provider and region.
	GetProductDetails(provider string, service string, region string) ([]types.ProductDetails, error)

	// GetZones returns all the availability zones for a region.
	GetZones(provider, service, region string) ([]string, error)
}

InstanceTypeStore retrieves instance types from the given provider and region.

type IntFilter

type IntFilter struct {
	Lt  *int
	Lte *int
	Gt  *int
	Gte *int
	Eq  *int
	Ne  *int
	In  []int
	Nin []int
}

IntFilter represents the query operators for an int field.

type Logger

type Logger interface {
	// Trace logs a debug event.
	Trace(msg string, fields ...map[string]interface{})

	// Debug logs a debug event.
	Debug(msg string, fields ...map[string]interface{})

	// Info logs an info event.
	Info(msg string, fields ...map[string]interface{})

	// Warn logs a warning event.
	Warn(msg string, fields ...map[string]interface{})

	// Error logs an error event.
	Error(msg string, fields ...map[string]interface{})

	// WithFields annotates a logger with key-value pairs.
	WithFields(fields map[string]interface{}) Logger

	// WithContext annotates a logger with a context.
	WithContext(ctx context.Context) Logger
}

Logger is the fundamental interface for all log operations.

type NetworkCategory

type NetworkCategory string
const (
	NetworkCategoryLow      NetworkCategory = "LOW"
	NetworkCategoryModerate NetworkCategory = "MODERATE"
	NetworkCategoryHigh     NetworkCategory = "HIGH"
)

func (NetworkCategory) IsValid

func (e NetworkCategory) IsValid() bool

func (NetworkCategory) MarshalGQL

func (e NetworkCategory) MarshalGQL(w io.Writer)

func (NetworkCategory) String

func (e NetworkCategory) String() string

func (*NetworkCategory) UnmarshalGQL

func (e *NetworkCategory) UnmarshalGQL(v interface{}) error

type NetworkCategoryFilter

type NetworkCategoryFilter struct {
	Eq  *NetworkCategory
	Ne  *NetworkCategory
	In  []NetworkCategory
	Nin []NetworkCategory
}

IntFilter represents the query operators for an instance type network category field.

type PeriodicExecutor

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

PeriodicExecutor Executor that periodically executes the passed in task function

func (*PeriodicExecutor) Execute

func (ps *PeriodicExecutor) Execute(ctx context.Context, sf TaskFn) error

Execute executes the task function periodically in a new goroutine For tasks that need to be periodically executed within a defined deadline, the appropriate context needs to be passed in

type Provider

type Provider struct {
	Code string
	Name string
}

Provider represents a single cloud provider.

type ProviderService

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

ProviderService returns the list of supported providers and relevant information.

func NewProviderService

func NewProviderService(store ProviderStore) *ProviderService

NewProviderService returns a new ProviderService.

func (*ProviderService) ListProviders

func (s *ProviderService) ListProviders(ctx context.Context) ([]Provider, error)

ListProviders returns a list of providers.

type ProviderStore

type ProviderStore interface {
	// GetProviders returns the supported providers.
	GetProviders() ([]types.Provider, error)
}

ProviderStore retrieves providers.

type Region

type Region struct {
	Code string
	Name string
	// contains filtered or unexported fields
}

Region is a general area in which a cloud provider has services available.

func (*Region) ProviderName

func (r *Region) ProviderName() string

ProviderName returns the provider name of the region. Used when resolving zones based on a region.

func (*Region) ServiceName

func (r *Region) ServiceName() string

ServiceName returns the service name of the region. Used when resolving zones based on a region.

type RegionService

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

RegionService provides access to regions supported by a service.

func NewRegionService

func NewRegionService(store RegionStore) *RegionService

NewRegionService returns a new RegionService.

func (*RegionService) ListRegions

func (s *RegionService) ListRegions(ctx context.Context, provider string, service string) ([]Region, error)

ListRegions returns a list of regions supported by a service.

func (*RegionService) ListZones

func (s *RegionService) ListZones(ctx context.Context, provider string, service string, region string) ([]Zone, error)

ListZones returns a list of zones within a region.

type RegionStore

type RegionStore interface {
	// GetRegions returns the supported regions for a service.
	GetRegions(provider string, service string) (map[string]string, error)

	// GetZones returns the supported zones within a region.
	GetZones(provider string, service string, region string) ([]string, error)
}

RegionStore retrieves regions.

type ScrapingDriver

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

func NewScrapingDriver

func NewScrapingDriver(renewalInterval time.Duration,
	infoers map[string]CloudInfoer,
	store CloudInfoStore,
	eventBus messaging.EventBus,
	metrics metrics.Reporter,
	tracer tracing.Tracer,
	errorHandler ErrorHandler,
	log Logger) *ScrapingDriver

func (*ScrapingDriver) RefreshProvider

func (sd *ScrapingDriver) RefreshProvider(ctx context.Context, provider string)

func (*ScrapingDriver) StartScraping

func (sd *ScrapingDriver) StartScraping() error

type Service

type Service struct {
	Code string
	// contains filtered or unexported fields
}

Service represents a single service.

func (*Service) ProviderName

func (s *Service) ProviderName() string

ProviderName returns the provider name of the service. Used when resolving regions based on a service.

type ServiceService

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

ServiceService returns the list of supported services.

func NewServiceService

func NewServiceService(store ServiceStore) *ServiceService

NewServiceService returns a new ServiceService.

func (*ServiceService) ListServices

func (s *ServiceService) ListServices(ctx context.Context, provider string) ([]Service, error)

ListServices returns a list of services supported by a provider.

type ServiceStore

type ServiceStore interface {
	// GetServices returns the supported services for a provider.
	GetServices(provider string) ([]types.Service, error)
}

ServiceStore retrieves services.

type TaskFn

type TaskFn func(c context.Context)

TaskFn function type for executing task logic

type Zone

type Zone struct {
	Code string
}

Zone is a specific location within a region.

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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