cloudmeta

package module
v0.1.26 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2021 License: MPL-2.0 Imports: 6 Imported by: 0

README

Cloudmeta

A cloud meta data utility.

Why cloudmeta?

With it, you can get popular cloud meta data, such as aws instance info, spot price, od-demand price, spot interruption info, regions info and so on.

For now, SpotMax team are providing open database for you

Who may use it?

If you are writing some automation code with aws/aliyun, I think you can get some idea in these project!

Supporting cloud platform

  1. aws
  2. aliyun

Usage

go get github.com/spotmaxtech/cloudmeta
package main

import (
	"fmt"
	"github.com/spotmaxtech/cloudmeta"
	)

func main() {
	meta := cloudmeta.DefaultAWSMetaDb()
	region := meta.Region().GetRegionInfo("us-east-1")
	fmt.Println(region)
}

Documentation

Index

Constants

View Source
const (
	TestConsulAddress      = "consul.spotmaxtech.com"
	ConsulRegionKey        = "cloudmeta/aws/region.json"
	ConsulInstanceKey      = "cloudmeta/aws/instances"
	ConsulSpotInstanceKey  = "cloudmeta/aws/spotinstance.json"
	ConsulInterruptRateKey = "cloudmeta/aws/interruptrate.json"
	ConsulSpotPriceKey     = "cloudmeta/aws/spotprice.json"
	ConsulOdPriceKey       = "cloudmeta/aws/odprice.json"
	ConsulImageKey         = "cloudmeta/aws/image.json"

	ALiConsulRegionKey       = "cloudmeta/aliyun/region.json"
	ALiConsulSpotPriceKey    = "cloudmeta/aliyun/spotprice.json"
	ALiConsulOdPriceKey      = "cloudmeta/aliyun/odprice.json"
	ALiConsulSpotInstanceKey = "cloudmeta/aliyun/spotInstances"
)

Variables

This section is empty.

Functions

func Initialize added in v0.1.26

func Initialize(consul string)

Types

type ALiImage added in v0.1.20

type ALiImage struct {
	Region Region
	ALiImageData
	// contains filtered or unexported fields
}

func NewALiImage added in v0.1.20

func NewALiImage(key string, region Region) *ALiImage

func (*ALiImage) FetchALiImage added in v0.1.20

func (image *ALiImage) FetchALiImage(consul *gokit.Consul) error

func (*ALiImage) ListImageByRegion added in v0.1.20

func (image *ALiImage) ListImageByRegion(region string) *map[string]map[string]*ImageALi

func (*ALiImage) ListImageByRegionAndOS added in v0.1.20

func (image *ALiImage) ListImageByRegionAndOS(region string, os string) *map[string]*ImageALi

type ALiImageData added in v0.1.20

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

type ALiInstanceMatrix added in v0.1.21

type ALiInstanceMatrix struct {
	Region Region
	// contains filtered or unexported fields
}

func NewALiInstanceMatrix added in v0.1.21

func NewALiInstanceMatrix(key string, region Region) *ALiInstanceMatrix

func (*ALiInstanceMatrix) FetchALiMatrix added in v0.1.21

func (imatrix *ALiInstanceMatrix) FetchALiMatrix(consul *gokit.Consul) error

func (*ALiInstanceMatrix) ListInstanceMatrixByRegion added in v0.1.21

func (imatrix *ALiInstanceMatrix) ListInstanceMatrixByRegion(region string) *map[string]map[string][]string

func (*ALiInstanceMatrix) ListInstanceMatrixByRegionAndZone added in v0.1.21

func (imatrix *ALiInstanceMatrix) ListInstanceMatrixByRegionAndZone(region string, zone string) *map[string][]string

func (*ALiInstanceMatrix) ListInstanceMatrixByRegionV2 added in v0.1.21

func (imatrix *ALiInstanceMatrix) ListInstanceMatrixByRegionV2(region string) *map[string][]string

type ALiMetaDB added in v0.1.13

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

func DefaultAliMetaDb

func DefaultAliMetaDb() *ALiMetaDB

func NewMetaDBALi added in v0.1.13

func NewMetaDBALi(addr string) (*ALiMetaDB, error)

func (*ALiMetaDB) ODPrice added in v0.1.14

func (m *ALiMetaDB) ODPrice() ODPriceALi

func (*ALiMetaDB) Region added in v0.1.14

func (m *ALiMetaDB) Region() Region

func (*ALiMetaDB) SpotInstance added in v0.1.14

func (m *ALiMetaDB) SpotInstance() SpotInstanceALi

func (*ALiMetaDB) SpotPrice added in v0.1.14

func (m *ALiMetaDB) SpotPrice() SpotPriceALi

func (*ALiMetaDB) UpdateALi added in v0.1.13

func (m *ALiMetaDB) UpdateALi() error

type ALiSpotInstance added in v0.1.17

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

func NewALiSpotInstance added in v0.1.17

func NewALiSpotInstance(key string, region Region) *ALiSpotInstance

func (*ALiSpotInstance) FetchALiSpot added in v0.1.17

func (s *ALiSpotInstance) FetchALiSpot(consul *gokit.Consul) error

func (*ALiSpotInstance) GetInstByRegion added in v0.1.17

func (s *ALiSpotInstance) GetInstByRegion(region string) map[string]map[string]map[string]*SpotInstanceInfoAli

func (*ALiSpotInstance) GetInstByRegionAndZones added in v0.1.17

func (s *ALiSpotInstance) GetInstByRegionAndZones(region string, zone string) *[]*SpotInstanceInfoAli

func (*ALiSpotInstance) GetInstInfoByTypes added in v0.1.18

func (s *ALiSpotInstance) GetInstInfoByTypes(region string, zone string, inst []string) *map[string]*SpotInstanceInfoAli

type AWSImage added in v0.1.2

type AWSImage struct {
	AWSImageData
	// contains filtered or unexported fields
}

func NewAWSImage added in v0.1.2

func NewAWSImage(key string) *AWSImage

func (*AWSImage) FetchImage added in v0.1.4

func (image *AWSImage) FetchImage(consul *gokit.Consul) error

func (*AWSImage) ListImagesByRegion added in v0.1.2

func (image *AWSImage) ListImagesByRegion(region string) *map[string]map[string]*ec2.Image

func (*AWSImage) ListImagesByRegionAndType added in v0.1.2

func (image *AWSImage) ListImagesByRegionAndType(region string, imagetype string) *map[string]*ec2.Image

type AWSImageData added in v0.1.2

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

type AWSInstance

type AWSInstance struct {
	AWSInstanceData
	// contains filtered or unexported fields
}

func NewAWSInstance

func NewAWSInstance(key string, region Region) *AWSInstance

func (*AWSInstance) Fetch

func (i *AWSInstance) Fetch(consul *gokit.Consul) error

func (*AWSInstance) Filter

func (i *AWSInstance) Filter(list []*FilterType) *AWSInstanceData

func (*AWSInstance) GetInstInfo

func (i *AWSInstance) GetInstInfo(region string, instance string) *InstInfo

func (*AWSInstance) Keys

func (i *AWSInstance) Keys(region string) gokit.Set

func (*AWSInstance) List

func (i *AWSInstance) List(region string) []*InstInfo

type AWSInstanceData

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

type AWSOdPrice

type AWSOdPrice struct {
	AWSOdPriceData
	// contains filtered or unexported fields
}

func NewAWSOdPrice

func NewAWSOdPrice(key string) *AWSOdPrice

func (*AWSOdPrice) Fetch

func (i *AWSOdPrice) Fetch(consul *gokit.Consul) error

func (*AWSOdPrice) Filter

func (i *AWSOdPrice) Filter(list []*FilterType) *AWSOdPriceData

func (*AWSOdPrice) GetPrice

func (i *AWSOdPrice) GetPrice(region string, instance string) float64

func (*AWSOdPrice) List

func (i *AWSOdPrice) List(region string) []*AWSOdPriceList

type AWSOdPriceData

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

type AWSOdPriceList

type AWSOdPriceList struct {
	InstanceType string  `json:"instance_type"`
	Price        float64 `json:"price"`
}

type AWSSpotInstance added in v0.1.25

type AWSSpotInstance struct {
	AWSSpotInstanceData
	// contains filtered or unexported fields
}

func NewAWSSpotInstance added in v0.1.25

func NewAWSSpotInstance(key string, region Region) *AWSSpotInstance

func (*AWSSpotInstance) Fetch added in v0.1.25

func (si *AWSSpotInstance) Fetch(consul *gokit.Consul) error

func (*AWSSpotInstance) GetInstInfo added in v0.1.25

func (si *AWSSpotInstance) GetInstInfo(region string, instance string) *InstInfo

func (*AWSSpotInstance) List added in v0.1.25

func (si *AWSSpotInstance) List(region string) []*InstInfo

type AWSSpotInstanceData added in v0.1.25

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

type AliInstance

type AliInstance struct {
	AliInstanceData
	// contains filtered or unexported fields
}

func NewAliInstance added in v0.1.2

func NewAliInstance(key string) *AliInstance

func (*AliInstance) FetchAli added in v0.1.2

func (i *AliInstance) FetchAli(consul *gokit.Consul) error

func (*AliInstance) List added in v0.1.2

func (i *AliInstance) List(region string) []*InstInfo

func (*AliInstance) ListByZone added in v0.1.3

func (i *AliInstance) ListByZone(region string, zone string) []*InstInfo

type AliInstanceData added in v0.1.2

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

type AliOdPrice added in v0.1.2

type AliOdPrice struct {
	AliOdPriceData
	// contains filtered or unexported fields
}

func NewAliOdPrice added in v0.1.2

func NewAliOdPrice(key string) *AliOdPrice

func (*AliOdPrice) FetchAli added in v0.1.2

func (i *AliOdPrice) FetchAli(consul *gokit.Consul) error

func (*AliOdPrice) ListAli added in v0.1.2

func (i *AliOdPrice) ListAli(region string) map[string]*ODPriceAli

type AliOdPriceData added in v0.1.2

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

type AliRegion

type AliRegion struct {
}

TODO: implement aliyun regions

type AliSpotPrice added in v0.1.2

type AliSpotPrice struct {
	AliSpotPriceData
	// contains filtered or unexported fields
}

func NewAliSpotPrice added in v0.1.2

func NewAliSpotPrice(key string) *AliSpotPrice

func (*AliSpotPrice) FetchAli added in v0.1.2

func (i *AliSpotPrice) FetchAli(consul *gokit.Consul) error

func (*AliSpotPrice) ListAli added in v0.1.2

func (i *AliSpotPrice) ListAli(region string, zone string) map[string]*SpotPriceInfoAli

type AliSpotPriceData added in v0.1.2

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

type CloudIdentifier

type CloudIdentifier int
const (
	AWS CloudIdentifier = iota
	Ali CloudIdentifier = 1
)

type CommonRegion added in v0.1.2

type CommonRegion struct {
	CommonRegionData
	// contains filtered or unexported fields
}

func NewCommonRegion added in v0.1.2

func NewCommonRegion(key string) *CommonRegion

func (*CommonRegion) Fetch added in v0.1.2

func (r *CommonRegion) Fetch(consul *gokit.Consul) error

func (*CommonRegion) Filter added in v0.1.2

func (r *CommonRegion) Filter(list []*string) *CommonRegionData

func (*CommonRegion) GetRegionInfo added in v0.1.2

func (r *CommonRegion) GetRegionInfo(name string) *RegionInfo

func (*CommonRegion) Keys added in v0.1.2

func (r *CommonRegion) Keys() gokit.Set

func (*CommonRegion) List added in v0.1.2

func (r *CommonRegion) List() []*RegionInfo

type CommonRegionData added in v0.1.2

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

type CommonSpotPrice added in v0.1.2

type CommonSpotPrice struct {
	CommonSpotPriceData
	// contains filtered or unexported fields
}

func NewCommonSpotPrice added in v0.1.2

func NewCommonSpotPrice(key string) *CommonSpotPrice

func (*CommonSpotPrice) Fetch added in v0.1.2

func (i *CommonSpotPrice) Fetch(consul *gokit.Consul) error

func (*CommonSpotPrice) Filter added in v0.1.2

func (i *CommonSpotPrice) Filter(list []*FilterType) *CommonSpotPriceData

func (*CommonSpotPrice) GetPrice added in v0.1.2

func (i *CommonSpotPrice) GetPrice(region string, instance string) *SpotPriceInfo

func (*CommonSpotPrice) List added in v0.1.2

func (i *CommonSpotPrice) List(region string) []*SpotPriceInfo

type CommonSpotPriceData added in v0.1.2

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

type DbSet

type DbSet struct {
	Region       Region
	Instance     Instance
	SpotInstance SpotInstanceAWS
	Interrupt    Interrupt
	ODPrice      ODPrice
	SpotPrice    SpotPrice
	Image        Image
}

type DbSetALi added in v0.1.13

type DbSetALi struct {
	Region       Region
	SpotPrice    SpotPriceALi
	ODPrice      ODPriceALi
	SpotInstance SpotInstanceALi
}

type FilterType

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

type Image added in v0.1.2

type Image interface {
	FetchImage(consul *gokit.Consul) error
	ListImagesByRegion(region string) *map[string]map[string]*ec2.Image
	ListImagesByRegionAndType(region string, imagetype string) *map[string]*ec2.Image
}

aws Image

type ImageALi added in v0.1.20

type ImageALi struct {
	ImageId      string `json:"imageId"`
	ImageName    string `json:"imageName"`
	Architecture string `json:"architecture"`
	Size         int    `json:"size"`
	OSName       string `json:"osName"`
	Status       string `json:"status"`
	OSType       string `json:"osType"`
	Platform     string `json:"platform"`
}

type ImageInfoALi added in v0.1.20

type ImageInfoALi interface {
	FetchALiImage(consul *gokit.Consul) error
	ListImageByRegion(region string) *map[string]map[string]*ImageALi
	ListImageByRegionAndOS(region string, os string) *map[string]*ImageALi
}

type InstInfo

type InstInfo struct {
	Name      string  `json:"name"`
	Core      int16   `json:"core"`
	Mem       float64 `json:"mem"`
	Storage   string  `json:"storage"`
	Family    string  `json:"family"`
	ODPrice   float64 `json:"odprice"`
	SpotPrice float64 `json:"spotprice"`
}

TODO: more info item? TODO: make category const?

type Instance

type Instance interface {
	Fetch(consul *gokit.Consul) error
	List(region string) []*InstInfo
	GetInstInfo(region string, instance string) *InstInfo
}

type InstanceMatrixALi added in v0.1.21

type InstanceMatrixALi interface {
	FetchALiMatrix(consul *gokit.Consul) error
	ListInstanceMatrixByRegion(region string) *map[string]map[string][]string
	ListInstanceMatrixByRegionAndZone(region string, zone string) *map[string][]string
	ListInstanceMatrixByRegionV2(region string) *map[string][]string
}

type Interrupt

type Interrupt interface {
	Fetch(consul *gokit.Consul) error
	GetInterruptInfo(region string, instance string) *InterruptInfo
}

type InterruptAdvisor

type InterruptAdvisor struct {
	InterruptAdvisorData
	// contains filtered or unexported fields
}

func NewAWSInterrupt

func NewAWSInterrupt(key string) *InterruptAdvisor

func (*InterruptAdvisor) Fetch

func (i *InterruptAdvisor) Fetch(consul *gokit.Consul) error

func (*InterruptAdvisor) Filter

func (i *InterruptAdvisor) Filter(list []*FilterType) *InterruptAdvisorData

func (*InterruptAdvisor) GetInterruptInfo

func (i *InterruptAdvisor) GetInterruptInfo(region string, name string) *InterruptInfo

func (*InterruptAdvisor) List

func (i *InterruptAdvisor) List(region string) []*InterruptInfo

type InterruptAdvisorData

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

type InterruptInfo

type InterruptInfo struct {
	Name     string `json:"name"`
	Rate     int    `json:"rate"`
	RateDesc string `json:"rate_desc"`
}

type InterruptInfoAli added in v0.1.3

type InterruptInfoAli struct {
	Interrupt float64 `json:"interrupt_rate"`
}

type MetaDb

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

func DefaultAWSMetaDb

func DefaultAWSMetaDb() *MetaDb

func NewMetaDBAWS added in v0.1.13

func NewMetaDBAWS(addr string) (*MetaDb, error)

func (*MetaDb) Image added in v0.1.2

func (m *MetaDb) Image() Image

func (*MetaDb) Instance

func (m *MetaDb) Instance() Instance

func (*MetaDb) Interrupt

func (m *MetaDb) Interrupt() Interrupt

func (*MetaDb) ODPrice

func (m *MetaDb) ODPrice() ODPrice

func (*MetaDb) OK

func (m *MetaDb) OK() bool

test ok or not

func (*MetaDb) Region

func (m *MetaDb) Region() Region

func (*MetaDb) SpotInstance

func (m *MetaDb) SpotInstance() Instance

func (*MetaDb) SpotPrice

func (m *MetaDb) SpotPrice() SpotPrice

func (*MetaDb) Update

func (m *MetaDb) Update() error

update new meta version

type ODPrice

type ODPrice interface {
	Fetch(consul *gokit.Consul) error
	GetPrice(region string, instance string) float64
}

type ODPriceALi added in v0.1.13

type ODPriceALi interface {
	FetchAli(consul *gokit.Consul) error
	ListAli(region string) map[string]*ODPriceAli
}

type ODPriceAli added in v0.1.2

type ODPriceAli struct {
	InstType      string  `json:"instance_type"`
	OriginalPrice float64 `json:"original_price"`
	TradePrice    float64 `json:"trade_price"`
	DiscountPrice float64 `json:"discount_price"`
	Description   string  `json:"description"`
}

type Region

type Region interface {
	Fetch(consul *gokit.Consul) error
	List() []*RegionInfo
	GetRegionInfo(name string) *RegionInfo
}

type RegionInfo

type RegionInfo struct {
	Name  string   `json:"name"`
	Text  string   `json:"text"`
	Zones []string `json:"zones"`
}

type SpotInstanceALi added in v0.1.17

type SpotInstanceALi interface {
	FetchALiSpot(consul *gokit.Consul) error
	GetInstByRegion(region string) map[string]map[string]map[string]*SpotInstanceInfoAli
	GetInstByRegionAndZones(region string, zone string) *[]*SpotInstanceInfoAli
	GetInstInfoByTypes(region string, zone string, inst []string) *map[string]*SpotInstanceInfoAli
}

type SpotInstanceAWS added in v0.1.25

type SpotInstanceAWS interface {
	Fetch(consul *gokit.Consul) error
	List(region string) []*InstInfo
	GetInstInfo(region string, instance string) *InstInfo
}

type SpotInstanceInfoAli added in v0.1.2

type SpotInstanceInfoAli struct {
	InstType      string  `json:"instance_type"`
	Cores         int16   `json:"core"`
	Mem           float64 `json:"memory"`
	OriginalPrice float64 `json:"original_price"`
	TradePrice    float64 `json:"trade_price"`
	DiscountPrice float64 `json:"discount_price"`
	SpotPrice     float64 `json:"spot_price"`
	Family        string  `json:"family"`
	Desc          string  `json:"desc"`
}

type SpotPrice

type SpotPrice interface {
	Fetch(consul *gokit.Consul) error
	GetPrice(region string, instance string) *SpotPriceInfo
}

type SpotPriceALi added in v0.1.13

type SpotPriceALi interface {
	FetchAli(consul *gokit.Consul) error
	ListAli(region string, zone string) map[string]*SpotPriceInfoAli
}

type SpotPriceInfo

type SpotPriceInfo struct {
	InstanceType string             `json:"instance_type"`
	Avg          float64            `json:"avg"`
	AzMap        map[string]float64 `json:"az_map"`
}

type SpotPriceInfoAli added in v0.1.2

type SpotPriceInfoAli struct {
	InstType    string  `json:"instance_type"`
	Avg         float64 `json:"spot_price(avg)"`
	OriginPrice float64 `json:"origin_price(avg)"`
	Interrupt   float64 `json:"interrupt_rate"`
}

Jump to

Keyboard shortcuts

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