aws

package
v0.0.0-...-6054725 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SnapshotBlockDataLength define block length 512K
	SnapshotBlockDataLength = 524288

	// PutSnapshotBlockLimit define limit requests per snapshot, each supported Region: 1,000 per second
	// https://docs.aws.amazon.com/general/latest/gr/ebs-service.html#limits_ebs
	// We config 80% of max for smooth concurrent
	PutSnapshotBlockLimit = 800
)
View Source
const ProviderName = "aws"

ProviderName of the cloud platform provider

Variables

View Source
var (
	// Architectures define architecture from instance family
	Architectures = map[string]string{
		"a1":      "arm64",
		"c1":      "x86_64",
		"c3":      "x86_64",
		"c4":      "x86_64",
		"c5":      "x86_64",
		"c5a":     "x86_64",
		"c5ad":    "x86_64",
		"c5d":     "x86_64",
		"c5n":     "x86_64",
		"c6a":     "x86_64",
		"c6g":     "arm64",
		"c6gd":    "arm64",
		"c6gn":    "arm64",
		"c6i":     "x86_64",
		"c7g":     "arm64",
		"cc2":     "x86_64",
		"d3":      "x86_64",
		"d3en":    "x86_64",
		"dl1":     "x86_64",
		"f1":      "x86_64",
		"g2":      "x86_64",
		"g3":      "x86_64",
		"g3s":     "x86_64",
		"g4ad":    "x86_64",
		"g4dn":    "x86_64",
		"g5":      "x86_64",
		"g5g":     "arm64",
		"h1":      "x86_64",
		"i2":      "x86_64",
		"i3":      "x86_64",
		"i3en":    "x86_64",
		"im4gn":   "arm64",
		"inf1":    "x86_64",
		"is4gen":  "arm64",
		"m1":      "x86_64",
		"m2":      "x86_64",
		"m3":      "x86_64",
		"m4":      "x86_64",
		"m5":      "x86_64",
		"m5a":     "x86_64",
		"m5ad":    "x86_64",
		"m5d":     "x86_64",
		"m5dn":    "x86_64",
		"m5n":     "x86_64",
		"m5zn":    "x86_64",
		"m6a":     "x86_64",
		"m6g":     "arm64",
		"m6gd":    "arm64",
		"m7g":     "arm64",
		"m7gd":    "arm64",
		"m6i":     "x86_64",
		"mac1":    "x86_64_mac",
		"p2":      "x86_64",
		"p3":      "x86_64",
		"p3dn":    "x86_64",
		"p4d":     "x86_64",
		"r3":      "x86_64",
		"r4":      "x86_64",
		"r5":      "x86_64",
		"r5a":     "x86_64",
		"r5ad":    "x86_64",
		"r5b":     "x86_64",
		"r5d":     "x86_64",
		"r5dn":    "x86_64",
		"r5n":     "x86_64",
		"r6g":     "arm64",
		"r6gd":    "arm64",
		"r7g":     "arm64",
		"r7gd":    "arm64",
		"r6i":     "x86_64",
		"t1":      "i386,",
		"t2":      "x86_64",
		"t3":      "x86_64",
		"t3a":     "x86_64",
		"t4g":     "arm64",
		"u-12tb1": "x86_64",
		"u-6tb1":  "x86_64",
		"u-9tb1":  "x86_64",
		"vt1":     "x86_64",
		"x1":      "x86_64",
		"x1e":     "x86_64",
		"x2gd":    "arm64",
		"x2iezn":  "x86_64",
		"z1d":     "x86_64",
	}
)

Functions

func VerifyRole

func VerifyRole(zone string, bucket string)

VerifyRole ensures we have a role and attached policy for the vmie service to hit our bucket.

Types

type AWS

type AWS struct {
	Storage *S3
	// contains filtered or unexported fields
}

AWS Provider to interact with AWS cloud infrastructure

func NewProvider

func NewProvider() *AWS

NewProvider AWS

func (*AWS) AttachVolume

func (a *AWS) AttachVolume(ctx *lepton.Context, instanceName, name string, attachID int) error

AttachVolume attaches a volume to an instance

func (*AWS) BuildImage

func (p *AWS) BuildImage(ctx *lepton.Context) (string, error)

BuildImage to be upload on AWS

func (*AWS) BuildImageWithPackage

func (p *AWS) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (string, error)

BuildImageWithPackage to upload on AWS

func (*AWS) CreateImage

func (p *AWS) CreateImage(ctx *lepton.Context, imagePath string) error

CreateImage creates image on AWS using nanos images. First a snapshot in AWS is created from a image in local machine and, then the snapshot is used to create an AMI.

func (*AWS) CreateInstance

func (p *AWS) CreateInstance(ctx *lepton.Context) error

CreateInstance - Creates instance on AWS Platform

func (*AWS) CreateSG

func (p *AWS) CreateSG(ctx *lepton.Context, svc *ec2.EC2, iname string, vpcID string) (sg *ec2.SecurityGroup, err error)

CreateSG - Create security group instance specific

func (*AWS) CreateSubnet

func (p *AWS) CreateSubnet(ctx *lepton.Context, vpc *ec2.Vpc) (subnet *ec2.Subnet, err error)

CreateSubnet creates a subnet on vpc

func (*AWS) CreateVPC

func (p *AWS) CreateVPC(ctx *lepton.Context, svc *ec2.EC2) (vpc *ec2.Vpc, err error)

CreateVPC creates a virtual network

func (*AWS) CreateVolume

func (a *AWS) CreateVolume(ctx *lepton.Context, name, data, provider string) (lepton.NanosVolume, error)

CreateVolume creates a snapshot and use it to create a volume

func (*AWS) CreateZoneRecord

func (p *AWS) CreateZoneRecord(config *types.Config, zoneID string, record *lepton.DNSRecord) error

CreateZoneRecord creates a record in a DNS zone

func (*AWS) CustomizeImage

func (p *AWS) CustomizeImage(ctx *lepton.Context) (string, error)

CustomizeImage returns image path with adaptations needed by cloud provider

func (*AWS) DeleteImage

func (p *AWS) DeleteImage(ctx *lepton.Context, imagename string) error

DeleteImage deletes image from AWS by ami name

func (*AWS) DeleteInstance

func (p *AWS) DeleteInstance(ctx *lepton.Context, instanceName string) error

DeleteInstance deletes instance from AWS if deleting sgs created by ops it can take a while so might be worth optionally making this go into the background

func (*AWS) DeleteSG

func (p *AWS) DeleteSG(groupID *string)

DeleteSG deletes a security group

func (*AWS) DeleteVolume

func (a *AWS) DeleteVolume(ctx *lepton.Context, name string) error

DeleteVolume deletes a volume

func (*AWS) DeleteZoneRecordIfExists

func (p *AWS) DeleteZoneRecordIfExists(config *types.Config, zoneID string, recordName string) error

DeleteZoneRecordIfExists deletes a record from a DNS zone if it exists

func (*AWS) DetachVolume

func (a *AWS) DetachVolume(ctx *lepton.Context, instanceName, name string) error

DetachVolume detachs a volume from an instance

func (*AWS) FindOrCreateZoneIDByName

func (p *AWS) FindOrCreateZoneIDByName(config *types.Config, dnsName string) (string, error)

FindOrCreateZoneIDByName searches for a DNS zone with the name passed by argument and if it doesn't exist it creates one

func (*AWS) GetAllVolumes

func (a *AWS) GetAllVolumes(ctx *lepton.Context) (*[]lepton.NanosVolume, error)

GetAllVolumes finds and returns all volumes

func (*AWS) GetImages

func (p *AWS) GetImages(ctx *lepton.Context) ([]lepton.CloudImage, error)

GetImages return all images on AWS

func (*AWS) GetInstanceByName

func (p *AWS) GetInstanceByName(ctx *lepton.Context, name string) (*lepton.CloudInstance, error)

GetInstanceByName returns instance with given name

func (*AWS) GetInstanceLogs

func (p *AWS) GetInstanceLogs(ctx *lepton.Context, instanceName string) (string, error)

GetInstanceLogs gets instance related logs

func (*AWS) GetInstances

func (p *AWS) GetInstances(ctx *lepton.Context) ([]lepton.CloudInstance, error)

GetInstances return all instances on AWS

func (*AWS) GetSecurityGroup

func (p *AWS) GetSecurityGroup(ctx *lepton.Context, svc *ec2.EC2, vpc *ec2.Vpc) (sg *ec2.SecurityGroup, err error)

GetSecurityGroup checks whether the configuration security group exists and has the configuration VPC assigned

func (*AWS) GetStorage

func (p *AWS) GetStorage() lepton.Storage

GetStorage returns storage interface for cloud provider

func (*AWS) GetSubnet

func (p *AWS) GetSubnet(ctx *lepton.Context, svc *ec2.EC2, vpcID string) (*ec2.Subnet, error)

GetSubnet returns a subnet with the context subnet name or the default subnet of vpc passed by argument

func (*AWS) GetVPC

func (p *AWS) GetVPC(ctx *lepton.Context, svc *ec2.EC2) (*ec2.Vpc, error)

GetVPC returns a vpc with the context vpc name or the default vpc

func (*AWS) Initialize

func (p *AWS) Initialize(config *types.ProviderConfig) error

Initialize AWS related things

func (*AWS) ListImages

func (p *AWS) ListImages(ctx *lepton.Context) error

ListImages lists images on AWS

func (*AWS) ListInstances

func (p *AWS) ListInstances(ctx *lepton.Context) error

ListInstances lists instances on AWS

func (*AWS) MirrorImage

func (p *AWS) MirrorImage(ctx *lepton.Context, imageName, srcRegion, dstRegion string) (string, error)

MirrorImage copies an image using its imageName from one region to another

func (*AWS) PrintInstanceLogs

func (p *AWS) PrintInstanceLogs(ctx *lepton.Context, instancename string, watch bool) error

PrintInstanceLogs writes instance logs to console

func (*AWS) RebootInstance

func (p *AWS) RebootInstance(ctx *lepton.Context, instanceName string) error

RebootInstance reboots the instance.

func (*AWS) ResizeImage

func (p *AWS) ResizeImage(ctx *lepton.Context, imagename string, hbytes string) error

ResizeImage is not supported on AWS.

func (*AWS) StartInstance

func (p *AWS) StartInstance(ctx *lepton.Context, instanceName string) error

StartInstance stops instance from AWS by ami name

func (*AWS) StopInstance

func (p *AWS) StopInstance(ctx *lepton.Context, instanceName string) error

StopInstance stops instance from AWS by ami name

func (*AWS) SyncImage

func (p *AWS) SyncImage(config *types.Config, target lepton.Provider, image string) error

SyncImage syncs image from provider to another provider

type LaunchTemplateInput

type LaunchTemplateInput struct {
	AutoScalingGroup         string
	ImageID                  string
	InstanceNetworkInterface *ec2.InstanceNetworkInterfaceSpecification
	InstanceProfileName      string
	InstanceType             string
	LaunchTemplateName       string
	Tags                     []*ec2.Tag
}

LaunchTemplateInput The parameters for a launch template.

type PutSnapshotBlockResult

type PutSnapshotBlockResult struct {
	Error      error
	BlockIndex int64
}

PutSnapshotBlockResult define result from PutSnapshotBlock

type PutSnapshotBlockResults

type PutSnapshotBlockResults struct {
	Data []PutSnapshotBlockResult

	// sync.Mutex to lock the slice
	sync.Mutex
}

PutSnapshotBlockResults define array of PutSnapshotBlockResult

func (*PutSnapshotBlockResults) Len

func (psb *PutSnapshotBlockResults) Len() int

Len get len of data

func (*PutSnapshotBlockResults) Set

Set a PutSnapshotBlockResult to slice Data

type ResourceWrapper

type ResourceWrapper struct {
	Everything bool
	List       []string
}

ResourceWrapper wraps the resource block as it can be 2 types, an array of strings or wildcard.

func (ResourceWrapper) MarshalJSON

func (w ResourceWrapper) MarshalJSON() ([]byte, error)

MarshalJSON is a custom unmarshaller to support multiple types for Resource.

func (*ResourceWrapper) UnmarshalJSON

func (w *ResourceWrapper) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is a custom unmarshaller to support multiple types for Resource.

type RolePolicy

type RolePolicy struct {
	Version   string
	Statement []RoleStatement
}

RolePolicy is the representation of an aws role policy.

type RoleStatement

type RoleStatement struct {
	Effect   string
	Action   []string
	Resource ResourceWrapper
}

RoleStatement is the representation of a statement of a RolePolicy.

type S3

type S3 struct{}

S3 provides AWS storage related operations

func (*S3) CopyToBucket

func (s *S3) CopyToBucket(config *types.Config, archPath string) error

CopyToBucket copies archive to bucket

func (*S3) DeleteFromBucket

func (s *S3) DeleteFromBucket(config *types.Config, key string) error

DeleteFromBucket deletes key from config's bucket

Jump to

Keyboard shortcuts

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