awsprovider

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSpotInstancesInRegion

func CreateSpotInstancesInRegion(
	ctx context.Context,
	region string,
	orchestrators []string,
	token string,
	instancesPerRegion int,
	config SpotInstanceConfig,
) ([]string, error)

CreateSpotInstancesInRegion creates spot instances in the specified AWS region

func GetAllStatuses

func GetAllStatuses() map[string]*models.DisplayStatus

GetAllStatuses retrieves all statuses from the allStatuses map

func LoadAWSConfig

func LoadAWSConfig(ctx context.Context, region string) (aws.Config, error)

LoadAWSConfig loads the AWS configuration for the specified region

func UpdateAllStatuses

func UpdateAllStatuses(status *models.DisplayStatus)

UpdateAllStatuses updates the global allStatuses map in a thread-safe manner

Types

type AWSProvider

type AWSProvider struct {
	Config    *aws.Config
	EC2Client EC2Clienter
}

AWSProvider wraps the AWS deployment functionality

func NewAWSProvider

func NewAWSProvider(viper *viper.Viper) (*AWSProvider, error)

NewAWSProvider creates a new AWSProvider instance

func (*AWSProvider) CreateDeployment

func (p *AWSProvider) CreateDeployment(ctx context.Context) error

func (*AWSProvider) DestroyDeployment

func (p *AWSProvider) DestroyDeployment(ctx context.Context) error

func (*AWSProvider) DestroyResources

func (p *AWSProvider) DestroyResources(ctx context.Context, vpcID string) error

DestroyResources deletes the specified AWS VPC and associated resources

func (*AWSProvider) GetAllAWSRegions

func (p *AWSProvider) GetAllAWSRegions(ctx context.Context) ([]string, error)

func (*AWSProvider) GetEC2Client

func (p *AWSProvider) GetEC2Client() (EC2Clienter, error)

GetEC2Client returns the current EC2 client

func (*AWSProvider) GetLatestUbuntuImage

func (p *AWSProvider) GetLatestUbuntuImage(
	ctx context.Context,
	region string,
) (*types.Image, error)

GetLatestUbuntuImage gets the latest Ubuntu AMI for the specified region

func (*AWSProvider) ListDeployments

func (p *AWSProvider) ListDeployments(ctx context.Context) ([]*types.Instance, error)

func (*AWSProvider) SetEC2Client

func (p *AWSProvider) SetEC2Client(client EC2Clienter)

SetEC2Client sets a new EC2 client

type AWSProviderFunc

type AWSProviderFunc func(ctx context.Context) (AWSProviderer, error)

AWSProviderFunc is a function type that returns an AWSProviderInterface

var MockAWSProviderFunc AWSProviderFunc = func(ctx context.Context) (AWSProviderer, error) {
	mockAWSProvider := new(MockAWSProvider)
	mockAWSProvider.On("GetEC2Client").Return(&ec2.Client{}, nil)
	mockAWSProvider.On("GetConfig").Return(&aws.Config{})
	mockAWSProvider.On("GetLatestUbuntuImage").Return(&types.Image{}, nil)
	return mockAWSProvider, nil
}
var NewAWSProviderFunc AWSProviderFunc = func(ctx context.Context) (AWSProviderer, error) {
	log := logger.Get()
	client, err := NewEC2Client(ctx)
	if err != nil {
		return nil, err
	}
	awsProvider, err := NewAWSProvider(viper.GetViper())
	if err != nil {
		log.Fatalf("Unable to create AWS Provider: %s", err)
		return nil, err
	}
	awsProvider.SetEC2Client(client)
	return awsProvider, nil
}

NewAWSProviderFunc is a variable holding the function that instantiates a new AWSProvider. By default, it points to a function that creates a new EC2 client and returns a new AWSProvider instance.

type AWSProviderer

type AWSProviderer interface {
	GetEC2Client() (EC2Clienter, error)
	SetEC2Client(EC2Clienter)

	GetLatestUbuntuImage(context.Context, string) (*types.Image, error)
}

type ConfigInterfacer

type ConfigInterfacer interface {
	GetString(key string) string
}

ConfigInterface defines the interface for configuration operations

type ConfigWrapper

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

ConfigWrapper wraps the AWS config to implement ConfigInterface

func NewConfigWrapper

func NewConfigWrapper(config aws.Config) *ConfigWrapper

func (*ConfigWrapper) GetString

func (cw *ConfigWrapper) GetString(key string) string

type EC2Clienter

type EC2Clienter interface {
	DescribeImages(
		ctx context.Context,
		params *ec2.DescribeImagesInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DescribeImagesOutput, error)
	CreateVpc(
		ctx context.Context,
		params *ec2.CreateVpcInput,
		optFns ...func(*ec2.Options),
	) (*ec2.CreateVpcOutput, error)
	CreateSubnet(
		ctx context.Context,
		params *ec2.CreateSubnetInput,
		optFns ...func(*ec2.Options),
	) (*ec2.CreateSubnetOutput, error)
	//CreateSecurityGroup(ctx context.Context, params *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error)
	//AuthorizeSecurityGroupIngress(ctx context.Context, params *ec2.AuthorizeSecurityGroupIngressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupIngressOutput, error)
	RunInstances(
		ctx context.Context,
		params *ec2.RunInstancesInput,
		optFns ...func(*ec2.Options),
	) (*ec2.RunInstancesOutput, error)
	DescribeInstances(
		ctx context.Context,
		params *ec2.DescribeInstancesInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DescribeInstancesOutput, error)
	DescribeVpcs(
		ctx context.Context,
		params *ec2.DescribeVpcsInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DescribeVpcsOutput, error)
	DescribeSubnets(
		ctx context.Context,
		params *ec2.DescribeSubnetsInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DescribeSubnetsOutput, error)
	DescribeSecurityGroups(
		ctx context.Context,
		params *ec2.DescribeSecurityGroupsInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DescribeSecurityGroupsOutput, error)
	TerminateInstances(
		ctx context.Context,
		params *ec2.TerminateInstancesInput,
		optFns ...func(*ec2.Options),
	) (*ec2.TerminateInstancesOutput, error)
	DeleteSecurityGroup(
		ctx context.Context,
		params *ec2.DeleteSecurityGroupInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DeleteSecurityGroupOutput, error)
	DeleteSubnet(
		ctx context.Context,
		params *ec2.DeleteSubnetInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DeleteSubnetOutput, error)
	DeleteVpc(
		ctx context.Context,
		params *ec2.DeleteVpcInput,
		optFns ...func(*ec2.Options),
	) (*ec2.DeleteVpcOutput, error)
}

func NewEC2Client

func NewEC2Client(ctx context.Context) (EC2Clienter, error)

NewEC2Client creates a new EC2 client

type MockAWSProvider

type MockAWSProvider struct {
	mock.Mock
	Config    aws.Config
	EC2Client EC2Clienter
}

func (*MockAWSProvider) GetEC2Client

func (m *MockAWSProvider) GetEC2Client() (EC2Clienter, error)

GetEC2Client mocks the GetEC2Client method

func (*MockAWSProvider) GetLatestUbuntuImage

func (m *MockAWSProvider) GetLatestUbuntuImage(
	ctx context.Context,
	region string,
) (*types.Image, error)

func (*MockAWSProvider) SetEC2Client

func (m *MockAWSProvider) SetEC2Client(client EC2Clienter)

SetEC2Client mocks the SetEC2Client method

type MockEC2Client

type MockEC2Client struct {
	mock.Mock
}

func (*MockEC2Client) AuthorizeSecurityGroupIngress

func (m *MockEC2Client) AuthorizeSecurityGroupIngress(
	ctx context.Context,
	params *ec2.AuthorizeSecurityGroupIngressInput,
	optFns ...func(*ec2.Options),
) (*ec2.AuthorizeSecurityGroupIngressOutput, error)

func (*MockEC2Client) CreateSecurityGroup

func (m *MockEC2Client) CreateSecurityGroup(
	ctx context.Context,
	params *ec2.CreateSecurityGroupInput,
	optFns ...func(*ec2.Options),
) (*ec2.CreateSecurityGroupOutput, error)

func (*MockEC2Client) CreateSubnet

func (m *MockEC2Client) CreateSubnet(
	ctx context.Context,
	params *ec2.CreateSubnetInput,
	optFns ...func(*ec2.Options),
) (*ec2.CreateSubnetOutput, error)

func (*MockEC2Client) CreateVpc

func (m *MockEC2Client) CreateVpc(
	ctx context.Context,
	params *ec2.CreateVpcInput,
	optFns ...func(*ec2.Options),
) (*ec2.CreateVpcOutput, error)

func (*MockEC2Client) DeleteSecurityGroup

func (m *MockEC2Client) DeleteSecurityGroup(
	ctx context.Context,
	params *ec2.DeleteSecurityGroupInput,
	optFns ...func(*ec2.Options),
) (*ec2.DeleteSecurityGroupOutput, error)

func (*MockEC2Client) DeleteSubnet

func (m *MockEC2Client) DeleteSubnet(
	ctx context.Context,
	params *ec2.DeleteSubnetInput,
	optFns ...func(*ec2.Options),
) (*ec2.DeleteSubnetOutput, error)

func (*MockEC2Client) DeleteVpc

func (m *MockEC2Client) DeleteVpc(
	ctx context.Context,
	params *ec2.DeleteVpcInput,
	optFns ...func(*ec2.Options),
) (*ec2.DeleteVpcOutput, error)

func (*MockEC2Client) DescribeImages

func (m *MockEC2Client) DescribeImages(
	ctx context.Context,
	params *ec2.DescribeImagesInput,
	optFns ...func(*ec2.Options),
) (*ec2.DescribeImagesOutput, error)

func (*MockEC2Client) DescribeInstances

func (m *MockEC2Client) DescribeInstances(
	ctx context.Context,
	params *ec2.DescribeInstancesInput,
	optFns ...func(*ec2.Options),
) (*ec2.DescribeInstancesOutput, error)

func (*MockEC2Client) DescribeSecurityGroups

func (m *MockEC2Client) DescribeSecurityGroups(
	ctx context.Context,
	params *ec2.DescribeSecurityGroupsInput,
	optFns ...func(*ec2.Options),
) (*ec2.DescribeSecurityGroupsOutput, error)

func (*MockEC2Client) DescribeSubnets

func (m *MockEC2Client) DescribeSubnets(
	ctx context.Context,
	params *ec2.DescribeSubnetsInput,
	optFns ...func(*ec2.Options),
) (*ec2.DescribeSubnetsOutput, error)

func (*MockEC2Client) DescribeVpcs

func (m *MockEC2Client) DescribeVpcs(
	ctx context.Context,
	params *ec2.DescribeVpcsInput,
	optFns ...func(*ec2.Options),
) (*ec2.DescribeVpcsOutput, error)

func (*MockEC2Client) GetLatestUbuntuImage

func (m *MockEC2Client) GetLatestUbuntuImage(
	ctx context.Context,
	region string,
) (*types.Image, error)

func (*MockEC2Client) RunInstances

func (m *MockEC2Client) RunInstances(
	ctx context.Context,
	params *ec2.RunInstancesInput,
	optFns ...func(*ec2.Options),
) (*ec2.RunInstancesOutput, error)

func (*MockEC2Client) TerminateInstances

func (m *MockEC2Client) TerminateInstances(
	ctx context.Context,
	params *ec2.TerminateInstancesInput,
	optFns ...func(*ec2.Options),
) (*ec2.TerminateInstancesOutput, error)

type ResourceInfo

type ResourceInfo struct {
	ID         string
	Type       string
	Region     string
	Zone       string
	Status     string
	InstanceID string
	PublicIP   string
	PrivateIP  string
}

Status represents the status of an instance

type SpotInstanceConfig

type SpotInstanceConfig struct {
	KeyPairName  string
	InstanceType string
	VPCCIDRBlock string
	VPCTagKey    string
	VPCTagValue  string
}

SpotInstanceConfig holds the configuration for creating spot instances

type Status

type Status struct {
	ID string
	ResourceInfo
}

Jump to

Keyboard shortcuts

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