build: golang.org/x/build/internal/cloud Index | Files

package cloud

import "golang.org/x/build/internal/cloud"

Index

Package Files

aws.go aws_interceptor.go fake_aws.go

Constants

const (
    // QuotaCodeCPUOnDemand is the quota code for on-demand CPUs.
    QuotaCodeCPUOnDemand = "L-1216C47A"
    // QuotaServiceEC2 is the service code for the EC2 service.
    QuotaServiceEC2 = "ec2"
)

Variables

var DefaultEC2LimitConfig = &EC2LimitConfig{
    MutatingRate:                    5,
    MutatingRateBucket:              200,
    NonMutatingRate:                 20,
    NonMutatingRateBucket:           100,
    RunInstanceRate:                 2,
    RunInstanceRateBucket:           5,
    RunInstanceResource:             2,
    RunInstanceResourceBucket:       1000,
    TerminateInstanceResource:       20,
    TerminateInstanceResourceBucket: 1000,
}

DefaultEC2LimitConfig sets limits defined in https://docs.aws.amazon.com/AWSEC2/latest/APIReference/throttling.html

type AWSClient Uses

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

AWSClient is a client for AWS services.

func NewAWSClient Uses

func NewAWSClient(region, keyID, accessKey string, opts ...AWSOpt) (*AWSClient, error)

NewAWSClient creates a new AWS client.

func (*AWSClient) CreateInstance Uses

func (ac *AWSClient) CreateInstance(ctx context.Context, config *EC2VMConfiguration) (*Instance, error)

CreateInstance creates an EC2 VM instance.

func (*AWSClient) DestroyInstances Uses

func (ac *AWSClient) DestroyInstances(ctx context.Context, instIDs ...string) error

DestroyInstances terminates EC2 VM instances.

func (*AWSClient) Instance Uses

func (ac *AWSClient) Instance(ctx context.Context, instID string) (*Instance, error)

Instance retrieves an EC2 instance by instance ID.

func (*AWSClient) InstanceTypesARM Uses

func (ac *AWSClient) InstanceTypesARM(ctx context.Context) ([]*InstanceType, error)

InstanceTypesARM retrieves all EC2 instance types in a region which support the ARM64 architecture.

func (*AWSClient) Quota Uses

func (ac *AWSClient) Quota(ctx context.Context, service, code string) (int64, error)

Quota retrieves the requested service quota for the service.

func (*AWSClient) RunningInstances Uses

func (ac *AWSClient) RunningInstances(ctx context.Context) ([]*Instance, error)

RunningInstances retrieves all EC2 instances in a region which have not been terminated or stopped.

func (*AWSClient) WaitUntilInstanceRunning Uses

func (ac *AWSClient) WaitUntilInstanceRunning(ctx context.Context, instID string) error

WaitUntilInstanceRunning waits until a stopping condition is met. The stopping conditions are: - The requested instance state is `running`. - The passed in context is cancelled or the deadline expires. - 40 requests are made made with a 15 second delay between each request.

type AWSOpt Uses

type AWSOpt func(*AWSClient)

AWSOpt is an optional configuration setting for the AWSClient.

func WithRateLimiter Uses

func WithRateLimiter(config *EC2LimitConfig) AWSOpt

WithRateLimiter adds a rate limiter to the AWSClient.

type EC2LimitConfig Uses

type EC2LimitConfig struct {
    // MutatingRate sets the refill rate for mutating requests.
    MutatingRate float64
    // MutatingRateBucket sets the bucket size for mutating requests.
    MutatingRateBucket int
    // NonMutatingRate sets the refill rate for non-mutating requests.
    NonMutatingRate float64
    // NonMutatingRateBucket sets the bucket size for non-mutating requests.
    NonMutatingRateBucket int
    // RunInstanceRate sets the refill rate for run instance rate requests.
    RunInstanceRate float64
    // RunInstanceRateBucket sets the bucket size for run instance rate requests.
    RunInstanceRateBucket int
    // RunInstanceResource sets the refill rate for run instance rate resources.
    RunInstanceResource float64
    // RunInstanceResourceBucket sets the bucket size for run instance rate resources.
    RunInstanceResourceBucket int
    // TerminateInstanceResource sets the refill rate for terminate instance rate resources.
    TerminateInstanceResource float64
    // TerminateInstanceResourceBucket sets the bucket size for terminate instance resources.
    TerminateInstanceResourceBucket int
}

EC2LimitConfig contains the desired rate and resource rate limit configurations.

type EC2RateLimitInterceptor Uses

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

EC2RateLimitInterceptor implements an interceptor that will rate limit requests to the AWS API and allow calls to the appropriate clients to proceed.

func (*EC2RateLimitInterceptor) DescribeInstanceTypesPagesWithContext Uses

func (i *EC2RateLimitInterceptor) DescribeInstanceTypesPagesWithContext(ctx context.Context, in *ec2.DescribeInstanceTypesInput, fn func(*ec2.DescribeInstanceTypesOutput, bool) bool, opts ...request.Option) error

DescribeInstanceTypesPagesWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline.

func (*EC2RateLimitInterceptor) DescribeInstancesPagesWithContext Uses

func (i *EC2RateLimitInterceptor) DescribeInstancesPagesWithContext(ctx context.Context, in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error

DescribeInstancesPagesWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline.

func (*EC2RateLimitInterceptor) DescribeInstancesWithContext Uses

func (i *EC2RateLimitInterceptor) DescribeInstancesWithContext(ctx context.Context, in *ec2.DescribeInstancesInput, opts ...request.Option) (*ec2.DescribeInstancesOutput, error)

DescribeInstancesWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline.

func (*EC2RateLimitInterceptor) RunInstancesWithContext Uses

func (i *EC2RateLimitInterceptor) RunInstancesWithContext(ctx context.Context, in *ec2.RunInstancesInput, opts ...request.Option) (*ec2.Reservation, error)

RunInstancesWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline. An error is returned if either the rate or resource limiter returns an error.

func (*EC2RateLimitInterceptor) TerminateInstancesWithContext Uses

func (i *EC2RateLimitInterceptor) TerminateInstancesWithContext(ctx context.Context, in *ec2.TerminateInstancesInput, opts ...request.Option) (*ec2.TerminateInstancesOutput, error)

TerminateInstancesWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline. An error is returned if either the rate or resource limiter returns an error.

func (*EC2RateLimitInterceptor) WaitUntilInstanceRunningWithContext Uses

func (i *EC2RateLimitInterceptor) WaitUntilInstanceRunningWithContext(ctx context.Context, in *ec2.DescribeInstancesInput, opts ...request.WaiterOption) error

WaitUntilInstanceRunningWithContext rate limits calls. The rate limiter will return an error if the request exceeds the bucket size, the Context is canceled, or the expected wait time exceeds the Context's Deadline.

type EC2UserData Uses

type EC2UserData struct {
    // BuildletBinaryURL is the url to the buildlet binary stored on GCS.
    BuildletBinaryURL string `json:"buildlet_binary_url,omitempty"`
    // BuildletHostType is the host type used by the buildlet. For example, `host-linux-arm64-aws`.
    BuildletHostType string `json:"buildlet_host_type,omitempty"`
    // BuildletImageURL is the url for the buildlet container image.
    BuildletImageURL string `json:"buildlet_image_url,omitempty"`
    // BuildletName is the name which should be passed onto the buildlet.
    BuildletName string `json:"buildlet_name,omitempty"`
    // Metadata provides a location for arbitrary metadata to be stored.
    Metadata map[string]string `json:"metadata,omitempty"`
    // TLSCert is the TLS certificate used by the buildlet.
    TLSCert string `json:"tls_cert,omitempty"`
    // TLSKey is the TLS key used by the buildlet.
    TLSKey string `json:"tls_key,omitempty"`
    // TLSPassword contains the SHA1 of the TLS key used by the buildlet for basic authentication.
    TLSPassword string `json:"tls_password,omitempty"`
}

EC2UserData is stored in the user data for each EC2 instance. This is used to store metadata about the running instance. The buildlet will retrieve this on EC2 instances before allowing connections from the coordinator.

func (*EC2UserData) EncodedString Uses

func (ud *EC2UserData) EncodedString() string

EncodedString converts `EC2UserData` into JSON which is base64 encoded. User data must be base64 encoded upon creation.

type EC2VMConfiguration Uses

type EC2VMConfiguration struct {
    // Description is a user defined description of the instance. It is displayed
    // on the AWS UI. It is an optional field.
    Description string
    // ImageID is the ID of the image used to launch the instance. It is a required field.
    ImageID string
    // Name is a user defined name for the instance. It is displayed on the AWS UI. It is
    // is an optional field.
    Name string
    // SSHKeyID is the name of the SSH key pair to use for access. It is a required field.
    SSHKeyID string
    // SecurityGroups contains the names of the security groups to be applied to the VM. If none
    // are provided the default security group will be used.
    SecurityGroups []string
    // Tags the tags to apply to the resources during launch.
    Tags map[string]string
    // Type is the type of instance.
    Type string
    // UserData is the user data to make available to the instance. This data is available
    // on the VM via the metadata endpoints. It must be a base64-encoded string. User
    // data is limited to 16 KB.
    UserData string
    // Zone the Availability Zone of the instance.
    Zone string
}

EC2VMConfiguration is the configuration needed for an EC2 instance.

type FakeAWSClient Uses

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

FakeAWSClient provides a fake AWS Client used to test the AWS client functionality.

func NewFakeAWSClient Uses

func NewFakeAWSClient() *FakeAWSClient

NewFakeAWSClient crates a fake AWS client.

func (*FakeAWSClient) CreateInstance Uses

func (f *FakeAWSClient) CreateInstance(ctx context.Context, config *EC2VMConfiguration) (*Instance, error)

CreateInstance creates an EC2 VM instance.

func (*FakeAWSClient) DestroyInstances Uses

func (f *FakeAWSClient) DestroyInstances(ctx context.Context, instIDs ...string) error

DestroyInstances terminates EC2 VM instances.

func (*FakeAWSClient) Instance Uses

func (f *FakeAWSClient) Instance(ctx context.Context, instID string) (*Instance, error)

Instance returns the `Instance` record for the rquested instance. The instance record will return records for recently terminated instances. If an instance is not found an error will be returned.

func (*FakeAWSClient) InstanceTypesARM Uses

func (f *FakeAWSClient) InstanceTypesARM(ctx context.Context) ([]*InstanceType, error)

InstanceTypesArm retrieves all EC2 instance types in a region which support the ARM64 architecture.

func (*FakeAWSClient) Quota Uses

func (f *FakeAWSClient) Quota(ctx context.Context, service, code string) (int64, error)

Quota retrieves the requested service quota for the service.

func (*FakeAWSClient) RunningInstances Uses

func (f *FakeAWSClient) RunningInstances(ctx context.Context) ([]*Instance, error)

Instances retrieves all EC2 instances in a region which have not been terminated or stopped.

func (*FakeAWSClient) WaitUntilInstanceRunning Uses

func (f *FakeAWSClient) WaitUntilInstanceRunning(ctx context.Context, instID string) error

WaitUntilInstanceRunning returns when an instance has transitioned into the running state.

type Instance Uses

type Instance struct {
    // CPUCount is the number of VCPUs the instance is configured with.
    CPUCount int64
    // CreatedAt is the time when the instance was launched.
    CreatedAt time.Time
    // Description is a user defined descripton of the instance.
    Description string
    // ID is the instance ID.
    ID  string
    // IPAddressExternal is the public IPv4 address assigned to the instance.
    IPAddressExternal string
    // IPAddressInternal is the private IPv4 address assigned to the instance.
    IPAddressInternal string
    // ImageID is The ID of the AMI(image)  used to launch the instance.
    ImageID string
    // Name is a user defined name for the instance instance.
    Name string
    // SSHKeyID is the name of the SSH key pair to use for access. It is a required field.
    SSHKeyID string
    // SecurityGroups is the security groups for the instance.
    SecurityGroups []string
    // State contains the state of the instance.
    State string
    // Tags contains tags assigned to the instance.
    Tags map[string]string
    // Type is the name of instance type.
    Type string
    // Zone is the availability zone where the instance is deployed.
    Zone string
}

Instance is a virtual machine.

type InstanceType Uses

type InstanceType struct {
    // Type is the textual label used to describe an instance type.
    Type string
    // CPU is the Default vCPU count.
    CPU int64
}

InstanceType contains information about an EC2 vm instance type.

Package cloud imports 18 packages (graph) and is imported by 8 packages. Updated 2021-01-15. Refresh now. Tools for package owners.