cloud

package
v0.0.0-...-047dcd9 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VPS = Production("vps")
	OBS = Production("obs")
	FC  = Production("fc")

	Aliyun = enrollPlatform("aliyun", PlatformInfo{SupportPrepaid: true, SupportPostpaid: false})
	AWS    = enrollPlatform("aws", PlatformInfo{SupportPrepaid: false, SupportPostpaid: true})
	GCP    = enrollPlatform("gcp", PlatformInfo{SupportPrepaid: false, SupportPostpaid: true})
	Twilio = enrollPlatform("twilio", PlatformInfo{SupportPrepaid: true, SupportPostpaid: false})
)
View Source
var (
	PrePaid  = ChargeType("prepaid")  // Yearly package or monthly package.
	PostPaid = ChargeType("postpaid") // Pay on demand.

	PayByBandwidth = InternetChargeType("PayByBandwidth")
	PayByTraffic   = InternetChargeType("PayByTraffic")

	SpotWithMaxPrice = SpotStrategy("SpotWithMaxPrice")
	SpotAsPriceGo    = SpotStrategy("SpotAsPriceGo")
)

Functions

This section is empty.

Types

type ACLType

type ACLType string

ACLType bucket/object ACL

const (
	// ACLPrivate definition : private read and write
	ACLPrivate ACLType = "private"
	// ACLPublicRead definition : public read and private write
	ACLPublicRead ACLType = "public-read"
	// ACLPublicReadWrite definition : public read and public write
	ACLPublicReadWrite ACLType = "public-read-write"
)

type AliyunClient

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

func (*AliyunClient) Close

func (ac *AliyunClient) Close() error

func (*AliyunClient) EcCreateSecurityGroup

func (ac *AliyunClient) EcCreateSecurityGroup(regionId string, sg SecurityGroup) (string, error)

func (*AliyunClient) EcCreateVps

func (ac *AliyunClient) EcCreateVps(regionId string, tmpl VpsCreationTmpl) (string, error)

func (*AliyunClient) EcDeleteSecurityGroup

func (ac *AliyunClient) EcDeleteSecurityGroup(regionId, securityGroupId string) error

func (*AliyunClient) EcDeleteVps

func (ac *AliyunClient) EcDeleteVps(regionId string, vpsIds []string, force bool) error

func (*AliyunClient) EcListImages

func (ac *AliyunClient) EcListImages(regionId string) ([]SysImage, error)

func (*AliyunClient) EcListOnDemandSpecs

func (ac *AliyunClient) EcListOnDemandSpecs(regionId string) (*VpsSpecList, error)

func (*AliyunClient) EcListSecurityGroups

func (ac *AliyunClient) EcListSecurityGroups(regionId string) ([]SecurityGroup, error)

func (*AliyunClient) EcListSpotSpecs

func (ac *AliyunClient) EcListSpotSpecs(regionId string) (*VpsSpecList, error)

func (*AliyunClient) EcListSwitches

func (ac *AliyunClient) EcListSwitches(regionId, zoneId string) ([]string, error)

func (*AliyunClient) EcListVps

func (ac *AliyunClient) EcListVps(regionId string) ([]VpsInfo, error)

func (*AliyunClient) EcStartVps

func (ac *AliyunClient) EcStartVps(regionId, vpsId string) error

func (*AliyunClient) GetBalance

func (ac *AliyunClient) GetBalance() (*Balance, error)

func (*AliyunClient) ListRegions

func (ac *AliyunClient) ListRegions() ([]string, error)

func (*AliyunClient) ListZones

func (ac *AliyunClient) ListZones(regionId string) ([]string, error)

func (*AliyunClient) ObsDeleteBucket

func (ac *AliyunClient) ObsDeleteBucket(regionId, bucketName string, deleteIfNotEmpty *bool) error

func (*AliyunClient) ObsDeleteObject

func (ac *AliyunClient) ObsDeleteObject(regionId, bucketName, blobId string) error

func (*AliyunClient) ObsGetObject

func (ac *AliyunClient) ObsGetObject(regionId, bucketName, blobId string) ([]byte, error)

func (*AliyunClient) ObsGetObjectSize

func (ac *AliyunClient) ObsGetObjectSize(regionId, bucketName, blobId string) (*gvolume.Volume, error)

func (*AliyunClient) ObsIsBucketExist

func (ac *AliyunClient) ObsIsBucketExist(regionId, bucketName string) (bool, error)

func (*AliyunClient) ObsListBuckets

func (ac *AliyunClient) ObsListBuckets(regionId string) ([]string, error)

func (*AliyunClient) ObsListObjectKeys

func (ac *AliyunClient) ObsListObjectKeys(regionId string, bucketName string) ([]string, error)

func (*AliyunClient) ObsNewBucket

func (ac *AliyunClient) ObsNewBucket(regionId, bucketName string) error

func (*AliyunClient) ObsRenameObject

func (ac *AliyunClient) ObsRenameObject(regionId, bucketName, oldObjectKey, newObjectKey string) error

func (*AliyunClient) ObsScanObjectKeys

func (ac *AliyunClient) ObsScanObjectKeys(regionId, bucketName, pageToken string) ([]string, string, error)

func (*AliyunClient) ObsUpsertObject

func (ac *AliyunClient) ObsUpsertObject(regionId, bucketName, blobId string, blob []byte) error

func (*AliyunClient) SmsSendMsg

func (ac *AliyunClient) SmsSendMsg(fromMobile, toMobile, message string) (err error)

func (*AliyunClient) SmsSendTmpl

func (ac *AliyunClient) SmsSendTmpl(regionId string, mobiles []string, sign, tmpl string, params map[string]string) error

type Auth

type Auth struct {
	AccessKey string
	SecretKey string
}

type Balance

type Balance struct {
	Currency  string
	Available gdecimal.Decimal
}

type ChargeType

type ChargeType string

How to charge.

type CheapestSpotVpsScanner

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

func NewCheapestSpotVpsScanner

func NewCheapestSpotVpsScanner(cli Cloud) *CheapestSpotVpsScanner

func (*CheapestSpotVpsScanner) GetCheapestNonCreditSpotVpsSpec

func (s *CheapestSpotVpsScanner) GetCheapestNonCreditSpotVpsSpec() *VpsSpecExList

func (*CheapestSpotVpsScanner) Scan

func (s *CheapestSpotVpsScanner) Scan() error

type Cloud

type Cloud interface {
	ListRegions() ([]string, error)
	ListZones(regionId string) ([]string, error)
	GetBalance() (*Balance, error)
	EcListSpotSpecs(regionId string) (*VpsSpecList, error)
	EcListImages(regionId string) ([]SysImage, error)
	EcListVps(regionId string) ([]VpsInfo, error)
	EcListSecurityGroups(regionId string) ([]SecurityGroup, error)
	EcCreateSecurityGroup(regionId string, sg SecurityGroup) (string, error)
	EcDeleteSecurityGroup(regionId, securityGroupId string) error
	EcListSwitches(regionId, zoneId string) ([]string, error)
	EcCreateVps(regionId string, tmpl VpsCreationTmpl) (string, error)
	EcStartVps(regionId, vpsId string) error
	EcDeleteVps(regionId string, vpsIds []string, force bool) error
	ObsIsBucketExist(regionId, bucketName string) (bool, error)
	ObsNewBucket(regionId, bucketName string) error
	ObsDeleteBucket(regionId, bucketName string, deleteIfNotEmpty *bool) error
	ObsListBuckets(regionId string) ([]string, error)
	ObsListObjectKeys(regionId, bucketName string) ([]string, error)
	ObsScanObjectKeys(regionId, bucketName, pageToken string) ([]string, string, error)
	ObsGetObjectSize(regionId, bucketName, objectKey string) (*gvolume.Volume, error)
	ObsGetObject(regionId, bucketName, objectKey string) ([]byte, error)
	ObsUpsertObject(regionId, bucketName, objectKey string, objectVal []byte) error
	ObsRenameObject(regionId, bucketName, oldObjectKey, newObjectKey string) error
	ObsDeleteObject(regionId, bucketName, objectKey string) error
	SmsSendTmpl(regionId string, mobiles []string, sign, tmpl string, params map[string]string) error
	SmsSendMsg(fromMobile, toMobile, message string) error
	Close() error
}

TODO:RegionId 要不要优化掉 AWS Lambda的demo https://github.com/razeone/serverless-blog-api/blob/master/hello/main.go

func New

func New(platform Platform, accessKey string, secretKey string, LAN bool) (Cloud, error)

type Endpoint

type Endpoint struct {
	WAN string
	LAN string
}

type GCPClient

type GCPClient struct {
}

func NewGCP

func NewGCP(auth Auth) (*GCPClient, error)

type InternetChargeType

type InternetChargeType string

Internet charge type.

type Platform

type Platform string

func (*Platform) Info

func (p *Platform) Info() PlatformInfo

func (Platform) String

func (p Platform) String() string

type PlatformInfo

type PlatformInfo struct {
	SupportPrepaid         bool
	SupportPostpaid        bool
	IsGetsStrongConsist    bool
	IsNonGetsStrongConsist bool
}

type Production

type Production string

type RegionInfo

type RegionInfo struct {
	Country   string
	City      string
	Endpoints map[Production]Endpoint
}

type Retry

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

func (*Retry) Close

func (c *Retry) Close() (err error)

func (*Retry) EcCreateSecurityGroup

func (c *Retry) EcCreateSecurityGroup(regionId string, sg SecurityGroup) (securityGroupId string, err error)

func (*Retry) EcCreateVps

func (c *Retry) EcCreateVps(regionId string, tmpl VpsCreationTmpl) (res string, err error)

func (*Retry) EcDeleteSecurityGroup

func (c *Retry) EcDeleteSecurityGroup(regionId, securityGroupId string) (err error)

func (*Retry) EcDeleteVps

func (c *Retry) EcDeleteVps(regionId string, vpsIds []string, force bool) (err error)

func (*Retry) EcListImages

func (c *Retry) EcListImages(regionId string) (res []SysImage, err error)

func (*Retry) EcListSecurityGroups

func (c *Retry) EcListSecurityGroups(regionId string) (res []SecurityGroup, err error)

func (*Retry) EcListSpotSpecs

func (c *Retry) EcListSpotSpecs(regionId string) (res *VpsSpecList, err error)

func (*Retry) EcListSwitches

func (c *Retry) EcListSwitches(regionId, zoneId string) (res []string, err error)

func (*Retry) EcListVps

func (c *Retry) EcListVps(regionId string) (res []VpsInfo, err error)

func (*Retry) EcStartVps

func (c *Retry) EcStartVps(regionId, vpsId string) (err error)

func (*Retry) GetBalance

func (c *Retry) GetBalance() (balance *Balance, err error)

func (*Retry) ListRegions

func (c *Retry) ListRegions() (names []string, err error)

func (*Retry) ListZones

func (c *Retry) ListZones(regionId string) (names []string, err error)

func (*Retry) ObsDeleteBucket

func (c *Retry) ObsDeleteBucket(regionId, bucketName string, deleteIfNotEmpty *bool) (err error)

func (*Retry) ObsDeleteObject

func (c *Retry) ObsDeleteObject(regionId, bucketName, blobId string) (err error)

func (*Retry) ObsGetObject

func (c *Retry) ObsGetObject(regionId, bucketName, blobId string) (val []byte, err error)

func (*Retry) ObsGetObjectSize

func (c *Retry) ObsGetObjectSize(regionId, bucketName, objectKey string) (vol *gvolume.Volume, err error)

func (*Retry) ObsIsBucketExist

func (c *Retry) ObsIsBucketExist(regionId, bucketName string) (exist bool, err error)

func (*Retry) ObsListBuckets

func (c *Retry) ObsListBuckets(regionId string) (names []string, err error)

func (*Retry) ObsListObjectKeys

func (c *Retry) ObsListObjectKeys(regionId, bucketName string) (keys []string, err error)

func (*Retry) ObsNewBucket

func (c *Retry) ObsNewBucket(regionId, bucketName string) (err error)

func (*Retry) ObsRenameObject

func (c *Retry) ObsRenameObject(regionId, bucketName, oldKey, newKey string) (err error)

func (*Retry) ObsScanObjectKeys

func (c *Retry) ObsScanObjectKeys(regionId, bucketName, pageToken string) (keys []string, nextPageToken string, err error)

func (*Retry) ObsUpsertObject

func (c *Retry) ObsUpsertObject(regionId, bucketName, blobId string, blob []byte) (err error)

func (*Retry) SetRetry

func (c *Retry) SetRetry(retry uint8)

func (*Retry) SetRetryInterval

func (c *Retry) SetRetryInterval(dur time.Duration)

func (*Retry) SmsSendMsg

func (c *Retry) SmsSendMsg(fromMobile, toMobile, message string) (err error)

func (*Retry) SmsSendTmpl

func (c *Retry) SmsSendTmpl(regionId string, mobiles []string, sign, tmpl string, params map[string]string) (err error)

type RetryCloud

type RetryCloud interface {
	Cloud
	SetRetry(retry uint8)
	SetRetryInterval(dur time.Duration)
}

func NewRetry

func NewRetry(platform Platform, accessKey string, secretKey string, LAN bool) (RetryCloud, error)

type SecurityGroup

type SecurityGroup struct {
	Id          string
	Name        string
	Permissions []SecurityPermission
}

type SecurityPermission

type SecurityPermission struct {
	Description  string
	Direction    string // "in", "out"
	Protocol     string // "tcp","udp"...
	SrcPortRange [2]int
	SrcCidrIP    string
	DstPortRange [2]int
	DstCidrIP    string
}

type SpotStrategy

type SpotStrategy string

Spot strategy.

type SysImage

type SysImage struct {
	Id        string
	Name      string
	OS        string // "linux", "windows"...
	Distro    string // "debian", "ubuntu"...
	Arch      string // "x86_64"...
	Available bool
}

type TwilioClient

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

func (*TwilioClient) Close

func (t *TwilioClient) Close() error

func (*TwilioClient) EcCreateSecurityGroup

func (t *TwilioClient) EcCreateSecurityGroup(regionId string, sg SecurityGroup) (string, error)

func (*TwilioClient) EcCreateVps

func (t *TwilioClient) EcCreateVps(regionId string, tmpl VpsCreationTmpl) (string, error)

func (*TwilioClient) EcDeleteSecurityGroup

func (t *TwilioClient) EcDeleteSecurityGroup(regionId, securityGroupId string) error

func (*TwilioClient) EcDeleteVps

func (t *TwilioClient) EcDeleteVps(regionId string, vpsIds []string, force bool) error

func (*TwilioClient) EcListImages

func (t *TwilioClient) EcListImages(regionId string) ([]SysImage, error)

func (*TwilioClient) EcListSecurityGroups

func (t *TwilioClient) EcListSecurityGroups(regionId string) ([]SecurityGroup, error)

func (*TwilioClient) EcListSpotSpecs

func (t *TwilioClient) EcListSpotSpecs(regionId string) (*VpsSpecList, error)

func (*TwilioClient) EcListSwitches

func (t *TwilioClient) EcListSwitches(regionId, zoneId string) ([]string, error)

func (*TwilioClient) EcListVps

func (t *TwilioClient) EcListVps(regionId string) ([]VpsInfo, error)

func (*TwilioClient) EcStartVps

func (t *TwilioClient) EcStartVps(regionId, vpsId string) error

func (*TwilioClient) FcListFunctions

func (t *TwilioClient) FcListFunctions(regionId, service string) ([]string, error)

func (*TwilioClient) ListRegions

func (t *TwilioClient) ListRegions() ([]string, error)

func (*TwilioClient) ListZones

func (t *TwilioClient) ListZones(regionId string) ([]string, error)

func (*TwilioClient) ObsDeleteBucket

func (t *TwilioClient) ObsDeleteBucket(regionId, bucketName string, deleteIfNotEmpty *bool) error

func (*TwilioClient) ObsDeleteObject

func (t *TwilioClient) ObsDeleteObject(regionId, bucketName, objectKey string) error

func (*TwilioClient) ObsGetObject

func (t *TwilioClient) ObsGetObject(regionId, bucketName, objectKey string) ([]byte, error)

func (*TwilioClient) ObsGetObjectSize

func (t *TwilioClient) ObsGetObjectSize(regionId, bucketName, objectKey string) (*gvolume.Volume, error)

func (*TwilioClient) ObsIsBucketExist

func (t *TwilioClient) ObsIsBucketExist(regionId, bucketName string) (bool, error)

func (*TwilioClient) ObsListBuckets

func (t *TwilioClient) ObsListBuckets(regionId string) ([]string, error)

func (*TwilioClient) ObsListObjectKeys

func (t *TwilioClient) ObsListObjectKeys(regionId string, bucketName string) ([]string, error)

func (*TwilioClient) ObsNewBucket

func (t *TwilioClient) ObsNewBucket(regionId, bucketName string) error

func (*TwilioClient) ObsRenameObject

func (t *TwilioClient) ObsRenameObject(regionId, bucketName, oldObjectKey, newObjectKey string) error

func (*TwilioClient) ObsScanObjectKeys

func (t *TwilioClient) ObsScanObjectKeys(regionId, bucketName, pageToken string) ([]string, string, error)

func (*TwilioClient) ObsUpsertObject

func (t *TwilioClient) ObsUpsertObject(regionId, bucketName, objectKey string, objectVal []byte) error

func (*TwilioClient) SmsSendMsg

func (t *TwilioClient) SmsSendMsg(fromMobile, toMobile, message string) error

Send SMS.

func (*TwilioClient) SmsSendTmpl

func (t *TwilioClient) SmsSendTmpl(regionId string, mobiles []string, sign, tmpl string, params map[string]string) error

type VpsCreationTmpl

type VpsCreationTmpl struct {
	// Zone Id like "cn-hangzhou-c"
	ZoneId string
	// Start a spot instance.
	IsSpot bool
	// Open spot instance protection duration, only available on aliyun for now.
	// If open "OpenSpotDuration", price will be about a little (10% on aliyun) higher than closing it.
	OpenSpotDuration bool
	// "SwitchId" required in "vpc" network type, and now only "vpc" network type supported on aliyun,
	// "classic" network type is fading away, so "SwitchId" is required.
	SwitchId string
	// Instance specs like "ecs.g5.large".
	Specs string
	// Instance name like "my-instance-temp-name".
	Name string
	// OS image Id like "ubuntu_20_04_x64_20G_alibase_20201120.vhd".
	ImageId         string
	SecurityGroupId string
	KeyPair         string
	Password        string
	SystemDiskGB    int
	VpsCharge       ChargeType
	InternetCharge  InternetChargeType
	BandWidthMbIn   int
	BandWidthMbOut  int
	SpotStrategy    SpotStrategy
	SpotMaxPrice    gdecimal.Decimal
	// true: unlimited performance mode, false: limited performance mode.
	// Available param option on aliyun.
	UnlimitedPerformance bool
}

Create VPS template.

func (VpsCreationTmpl) Verify

func (t VpsCreationTmpl) Verify(platform Platform) error

type VpsInfo

type VpsInfo struct {
	Id                 string
	Name               string
	Specs              string // "ecs.g5.large"
	InstanceChargeType ChargeType
	InternetChargeType ChargeType
	SpotPriceLimit     float64
	SpotStrategy       string
	SpotStartTime      time.Time
	NetworkType        string // "classic", "vpc"
	PrivateIPs         []string
	PublicIPs          []string
	RegionId           string
	ZoneId             string
	SecurityGroupIds   []string
	ImageId            string
	Status             string
	KeyPairName        string
	PhysicalCpuNum     int
	LogicalCpuNum      int
	GpuNum             int
	CreationTime       time.Time
	AutoReleaseTime    time.Time
	MemorySize         gvolume.Volume
	SysImageId         string
	SysImageName       string
	SysImageOS         string
}

Instance is a nested struct in ecs response.

func GetAllVps

func GetAllVps(cloud Cloud) ([]VpsInfo, error)

type VpsSpec

type VpsSpec struct {
	RegionId         string
	Id               string
	IsCredit         bool // Is credit instance(突发性能实例) or normal instance.
	Currency         string
	LogicalCpuNum    int
	MemoryVolume     gvolume.Volume
	AvailableZoneIds []string
	OnDemandPrices   map[string]gdecimal.Decimal
	SpotPricePerHour map[string]gdecimal.Decimal
}

Instance specification.

type VpsSpecEx

type VpsSpecEx struct {
	RegionId         string
	ZoneId           string
	Id               string
	IsCredit         bool // Is credit instance(突发性能实例) or normal instance.
	Currency         string
	LogicalCpuNum    int
	MemoryVolume     gvolume.Volume
	Network          string
	OnDemandPrices   gdecimal.Decimal
	SpotPricePerHour gdecimal.Decimal
}

type VpsSpecExList

type VpsSpecExList struct {
	SpecExs []VpsSpecEx
}

func (*VpsSpecExList) Append

func (vl *VpsSpecExList) Append(newList *VpsSpecExList) *VpsSpecExList

func (VpsSpecExList) Len

func (vl VpsSpecExList) Len() int

func (VpsSpecExList) Less

func (vl VpsSpecExList) Less(i, j int) bool

func (*VpsSpecExList) RemoveCreditInstance

func (vl *VpsSpecExList) RemoveCreditInstance() *VpsSpecExList

func (*VpsSpecExList) Sort

func (vl *VpsSpecExList) Sort() *VpsSpecExList

func (VpsSpecExList) Swap

func (vl VpsSpecExList) Swap(i, j int)

type VpsSpecList

type VpsSpecList struct {
	Specs []VpsSpec
}

func (*VpsSpecList) ToSpecExList

func (vsl *VpsSpecList) ToSpecExList() *VpsSpecExList

Jump to

Keyboard shortcuts

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