aws

package
v0.0.0-...-d5b31fc Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 17 Imported by: 0

README

See More:

AWS OpenAPI Docs

https://aws.amazon.com/cn/documentation/
https://docs.aws.amazon.com/AWSEC2/latest/APIReference/

Refs

https://docs.aws.amazon.com/sdk-for-go/api/

EC2

Limits

绝大部分限制配额都可以提交工单进行提高

每个可用区正在按需运行的EC2实例个数为20个
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html
https://ap-southeast-1.console.aws.amazon.com/ec2/v2/home?region=ap-southeast-1#Limits:

Using Centos7 AMI:

Offical CentOS is being distributed as a marketplace AMI rather than a community AMI, so you can't use it through API,
it will cause an error like this:

In order to use this AWS Marketplace product you need to accept terms and subscribe.
blabla ...

so we use Amazon Linux 2 AMI instead (also yum based)
https://aws.amazon.com/cn/amazon-linux-2/release-notes/

Documentation

Overview

Package aws ... this file rewrap existing methods to implement the cloudsvr.Handler interface

Index

Constants

This section is empty.

Variables

View Source
var (

	// NodeName is exported to make pass golint
	NodeName = "inf-agent-aws-node"
	// NodeLabels is exported to make pass golint
	NodeLabels = map[string]string{cloudsvr.CLOUDFLAGKEY: CloudType}
	// SSHKeyNamePrefix is exported
	SSHKeyNamePrefix = "inf-agent-aws-sshkey"
	// SecurityGrouopNamePrefix is exported
	SecurityGrouopNamePrefix = "inf-agent-aws-servicegroup"
)
View Source
var (
	// CloudType is exported
	CloudType = "aws"
)
View Source
var (
	// DefaultAPIEndPoint is exported
	// nouse actually, Amazon VPC directs your request to the us-east-1
	DefaultAPIEndPoint = "https://ec2.amazonaws.com"
)

Functions

This section is empty.

Types

type Config

type Config struct {
	EndPoint  string `json:"endpoint,omitempty"`
	AccessID  string `json:"access_id"`
	AccessKey string `json:"access_key"`
}

Config is exported

func (*Config) Valid

func (cfg *Config) Valid() error

Valid is exported

type ImageSorter

type ImageSorter []*ec2.Image

ImageSorter sort the ec2.Image by CreationDate

func (ImageSorter) Len

func (s ImageSorter) Len() int

func (ImageSorter) Less

func (s ImageSorter) Less(i, j int) bool

func (ImageSorter) Swap

func (s ImageSorter) Swap(i, j int)

type InstanceTypeSpec

type InstanceTypeSpec struct {
	CPU    int     `json:"cpu"`
	Memory float64 `json:"memory"` // by GB
}

InstanceTypeSpec is exported

type Region

type Region struct {
	Location string `json:"location"`
	City     string `json:"city"`
}

Region is exported

type SDK

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

SDK is an implement of CloudSvr

func Setup

func Setup(cfg *Config) (*SDK, error)

Setup is exported

func (*SDK) APIEndPoint

func (sdk *SDK) APIEndPoint() string

APIEndPoint is exported

func (*SDK) AccessID

func (sdk *SDK) AccessID() string

AccessID is exported

func (*SDK) AccessKey

func (sdk *SDK) AccessKey() string

AccessKey is exported

func (*SDK) CreateSSHKey

func (sdk *SDK) CreateSSHKey(region, suffix string) (string, string, error)

CreateSSHKey import a new ssh key on given aws region

func (*SDK) CreateSecurityGroup

func (sdk *SDK) CreateSecurityGroup(region, suffix string) (string, error)

CreateSecurityGroup is exported

func (*SDK) InspectEcs

func (sdk *SDK) InspectEcs(region, ecsID string) (*ec2.Instance, error)

InspectEcs show details of a given ecs instance

func (*SDK) InspectNode

func (sdk *SDK) InspectNode(id, regionOrZone string) (interface{}, error)

InspectNode show details of one given ecs instance

func (*SDK) ListCloudRegions

func (sdk *SDK) ListCloudRegions() ([]*cloudsvr.CloudRegion, error)

ListCloudRegions implement cloudsvr.Handler

func (*SDK) ListCloudTypes

func (sdk *SDK) ListCloudTypes(region string) ([]*cloudsvr.CloudNodeType, error)

ListCloudTypes implement cloudsvr.Handler

func (*SDK) ListEcses

func (sdk *SDK) ListEcses(region string, lbs map[string]string) ([]*ec2.Instance, error)

ListEcses show all of ecs instances for a specified region (regionID parameter set) or all of regions (regionID parameter empty)

func (*SDK) ListInstanceTypes

func (sdk *SDK) ListInstanceTypes(minCPU, maxCPU, minMem, maxMem int) (map[string]*InstanceTypeSpec, error)

ListInstanceTypes show all of instance types aws supported support cpu / memory minimal/maximize filter parameters

func (*SDK) ListNodes

func (sdk *SDK) ListNodes() ([]*cloudsvr.CloudNode, error)

ListNodes list all aws ecs instances with labels key: CLOUDFLAGKEY the nodes listed does NOT have any auth fields `User` `Password`

func (*SDK) ListRegions

func (sdk *SDK) ListRegions() ([]*ec2.Region, error)

ListRegions show all of regions aws supported

func (*SDK) ListZones

func (sdk *SDK) ListZones(region string) ([]*ec2.AvailabilityZone, error)

ListZones list available zones under one given region

func (*SDK) NewEcs

func (sdk *SDK) NewEcs(region string, req *ec2.RunInstancesInput) (string, error)

NewEcs create a new ecs instance with given settings

func (*SDK) NewNode

func (sdk *SDK) NewNode(prefer *cloudsvr.PreferAttrs) (*cloudsvr.CloudNode, *cloudsvr.PreferAttrs, error)

NewNode create aws ecs instance, try to use prefered attributes firstly Note: count of (each type of) instances are limited per-region / per-user See: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html

func (*SDK) PickupCentos7AMI

func (sdk *SDK) PickupCentos7AMI(region string) (string, error)

PickupCentos7AMI pick up the first avaliable centos7 AMI under a specified region

func (*SDK) PickupZone

func (sdk *SDK) PickupZone(region string) string

PickupZone pick up the first avaliable zone under a specified region

func (*SDK) Ping

func (sdk *SDK) Ping() error

Ping verify the cloudsvr settings could be working fine

func (*SDK) RemoveEcs

func (sdk *SDK) RemoveEcs(region, ecsID string) error

RemoveEcs remove the specified ecs instance

func (*SDK) RemoveNode

func (sdk *SDK) RemoveNode(node *cloudsvr.CloudNode) error

RemoveNode remove aws ecs instance

func (*SDK) RemoveSSHKey

func (sdk *SDK) RemoveSSHKey(region, name string) error

RemoveSSHKey remove a given ssh key on given aws region

func (*SDK) RemoveSecurityGroup

func (sdk *SDK) RemoveSecurityGroup(region, sgid string) error

RemoveSecurityGroup is exported

func (*SDK) SwitchRegion

func (sdk *SDK) SwitchRegion(region string) *ec2.EC2

SwitchRegion switch to new region and return a new ec2.EC2 client

func (*SDK) Type

func (sdk *SDK) Type() string

Type implement Handler

func (*SDK) Verify

func (sdk *SDK) Verify() error

Verify verifies configs about aliyun endpoint & access id & access key See: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html

func (*SDK) WaitEcs

func (sdk *SDK) WaitEcs(region, ecsID, expectStatus string, maxWait time.Duration) error

WaitEcs wait ecs instance status reached to expected status until maxWait timeout expectStatus could be:

0 : pending

16 : running 32 : shutting-down 48 : terminated 64 : stopping 80 : stopped

Jump to

Keyboard shortcuts

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