cloud

package
v0.0.0-...-29e6843 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2018 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Catch-all for unrecognized status codes
	StatusUnknown = CloudStatus(iota)

	//StatusPending indicates that it is not yet clear if the instance
	//has been successfully started or not (e.g., pending spot request)
	StatusPending

	//StatusInitializing means the instance request has been successfully
	//fulfilled, but it's not yet done booting up
	StatusInitializing

	//StatusFailed indicates that an attempt to start the instance has failed;
	//Could be due to billing, lack of capacity, etc.
	StatusFailed

	//StatusRunning means the machine is done booting, and active
	StatusRunning

	StatusStopped
	StatusTerminated
)
View Source
const (
	SpotStatusOpen     = "open"
	SpotStatusActive   = "active"
	SpotStatusClosed   = "closed"
	SpotStatusCanceled = "cancelled"
	SpotStatusFailed   = "failed"

	EC2ErrorSpotRequestNotFound = "InvalidSpotInstanceRequestID.NotFound"
)
View Source
const (
	EC2StatusPending      = "pending"
	EC2StatusRunning      = "running"
	EC2StatusShuttingdown = "shutting-down"
	EC2StatusTerminated   = "terminated"
	EC2StatusStopped      = "stopped"
	EC2ErrorNotFound      = "InvalidInstanceID.NotFound"
)

Valid values for EC2 instance states: pending | running | shutting-down | terminated | stopping | stopped see http://goo.gl/3OrCGn

View Source
const (
	// MinUptime is the minimum time to run a host before shutting it down.
	MinUptime = 30 * time.Minute
	// BufferTime is the time to leave an idle host running after it has completed
	// a task before shutting it down, given that it has already run for MinUptime.
	BufferTime = 10 * time.Minute
)
View Source
const (
	// OSStatusActive means the instance is currently running.
	OSStatusActive = "ACTIVE"
	// OSStatusInProgress means the instance is currently running and processing a request.
	OSStatusInProgress = "IN_PROGRESS"
	// OSStatusShutOff means the instance has been temporarily stopped.
	OSStatusShutOff = "SHUTOFF"
	// OSStatusBuilding means the instance is starting up.
	OSStatusBuilding = "BUILD"
)
View Source
const (
	MaxSpawnHostsPerUser                = 3
	DefaultSpawnHostExpiration          = 24 * time.Hour
	MaxSpawnHostExpirationDurationHours = 24 * time.Hour * 7 // 7 days
)
View Source
const (
	// ProviderName is used to distinguish between different cloud providers.
	ProviderName = "gce"
)

Variables

View Source
var (
	// bson fields for the EC2ProviderSettings struct
	AMIKey            = bsonutil.MustHaveTag(EC2ProviderSettings{}, "AMI")
	InstanceTypeKey   = bsonutil.MustHaveTag(EC2ProviderSettings{}, "InstanceType")
	SecurityGroupsKey = bsonutil.MustHaveTag(EC2ProviderSettings{}, "SecurityGroupIDs")
	KeyNameKey        = bsonutil.MustHaveTag(EC2ProviderSettings{}, "KeyName")
	MountPointsKey    = bsonutil.MustHaveTag(EC2ProviderSettings{}, "MountPoints")
)
View Source
var (
	// bson fields for the MountPoint struct
	VirtualNameKey = bsonutil.MustHaveTag(MountPoint{}, "VirtualName")
	DeviceNameKey  = bsonutil.MustHaveTag(MountPoint{}, "DeviceName")
	SizeKey        = bsonutil.MustHaveTag(MountPoint{}, "Size")
)
View Source
var (
	// bson fields for the StaticSettings struct
	HostsKey = bsonutil.MustHaveTag(StaticSettings{}, "Hosts")

	// bson fields for the Host struct
	NameKey = bsonutil.MustHaveTag(StaticHost{}, "Name")
)
View Source
var (
	// bson fields for the EC2SpotSettings struct
	BidPriceKey = bsonutil.MustHaveTag(EC2ProviderSettings{}, "BidPrice")
)

Functions

func CreateSpawnHost

func CreateSpawnHost(so SpawnOptions) (*host.Host, error)

CreateHost spawns a host with the given options.

func MakeExtendedSpawnHostExpiration

func MakeExtendedSpawnHostExpiration(host *host.Host, extendBy time.Duration) (time.Time, error)

func NewIntent

func NewIntent(d distro.Distro, instanceName, provider string, options HostOptions) *host.Host

NewIntent creates an IntentHost using the given host settings. An IntentHost is a host that does not exist yet but is intended to be picked up by the hostinit package and started. This function takes distro information, the name of the instance, the provider of the instance and a HostOptions and returns an IntentHost.

func SetHostRDPPassword

func SetHostRDPPassword(ctx context.Context, host *host.Host, password string) error

func TerminateSpawnHost

func TerminateSpawnHost(ctx context.Context, host *host.Host, settings *evergreen.Settings, user string) error

func ValidateRDPPassword

func ValidateRDPPassword(password string) bool

XXX: if modifying any of the password validation logic, you changes must also be ported into public/static/js/directives/directives.spawn.js

Types

type AWSClient

type AWSClient interface {
	// Create a new aws-sdk-client or mock if one does not exist, otherwise no-op.
	Create(*credentials.Credentials, string) error

	// Close an aws-sdk-client or mock.
	Close()

	// RunInstances is a wrapper for ec2.RunInstances.
	RunInstances(context.Context, *ec2.RunInstancesInput) (*ec2.Reservation, error)

	// DescribeInstances is a wrapper for ec2.DescribeInstances.
	DescribeInstances(context.Context, *ec2.DescribeInstancesInput) (*ec2.DescribeInstancesOutput, error)

	// CreateTags is a wrapper for ec2.CreateTags.
	CreateTags(context.Context, *ec2.CreateTagsInput) (*ec2.CreateTagsOutput, error)

	// TerminateInstances is a wrapper for ec2.TerminateInstances.
	TerminateInstances(context.Context, *ec2.TerminateInstancesInput) (*ec2.TerminateInstancesOutput, error)

	// RequestSpotInstances is a wrapper for ec2.RequestSpotInstances.
	RequestSpotInstances(context.Context, *ec2.RequestSpotInstancesInput) (*ec2.RequestSpotInstancesOutput, error)

	// DescribeSpotInstanceRequests is a wrapper for ec2.DescribeSpotInstanceRequests.
	DescribeSpotInstanceRequests(ctx context.Context, input *ec2.DescribeSpotInstanceRequestsInput) (*ec2.DescribeSpotInstanceRequestsOutput, error)

	// DescribeSpotRequestsAndSave is a wrapper for DescribeSpotInstanceRequests that also saves instance IDs to the db.
	DescribeSpotRequestsAndSave(context.Context, []*host.Host) (*ec2.DescribeSpotInstanceRequestsOutput, error)

	// GetSpotInstanceId returns the instance ID if already saved, otherwise looks it up.
	GetSpotInstanceId(context.Context, *host.Host) (string, error)

	// CancelSpotInstanceRequests is a wrapper for ec2.CancelSpotInstanceRequests.
	CancelSpotInstanceRequests(context.Context, *ec2.CancelSpotInstanceRequestsInput) (*ec2.CancelSpotInstanceRequestsOutput, error)

	// DescribeVolumes is a wrapper for ec2.DescribeVolumes.
	DescribeVolumes(context.Context, *ec2.DescribeVolumesInput) (*ec2.DescribeVolumesOutput, error)

	// DescribeSpotPriceHistory is a wrapper for ec2.DescribeSpotPriceHistory.
	DescribeSpotPriceHistory(context.Context, *ec2.DescribeSpotPriceHistoryInput) (*ec2.DescribeSpotPriceHistoryOutput, error)

	// DescribeSubnets is a wrapper for ec2.DescribeSubnets.
	DescribeSubnets(context.Context, *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error)

	// DescribeVpcs is a wrapper for ec2.DescribeVpcs.
	DescribeVpcs(context.Context, *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error)

	GetInstanceInfo(context.Context, string) (*ec2.Instance, error)
}

AWSClient is a wrapper for aws-sdk-go so we can use a mock in testing.

type BatchManager

type BatchManager interface {
	// GetInstanceStatuses gets the status of a slice of instances.
	GetInstanceStatuses(context.Context, []host.Host) ([]CloudStatus, error)
}

BatchManager is an interface for cloud providers that support batch operations.

type CloudHost

type CloudHost struct {
	Host     *host.Host
	KeyPath  string
	CloudMgr Manager
}

CloudHost is a provider-agnostic host object that delegates methods like status checks, ssh options, DNS name checks, termination, etc. to the underlying provider's implementation.

func GetCloudHost

func GetCloudHost(ctx context.Context, host *host.Host, settings *evergreen.Settings) (*CloudHost, error)

GetCloudHost returns an instance of CloudHost wrapping the given model.Host, giving access to the provider-specific methods to manipulate on the host.

func (*CloudHost) GetDNSName

func (cloudHost *CloudHost) GetDNSName(ctx context.Context) (string, error)

func (*CloudHost) GetInstanceStatus

func (cloudHost *CloudHost) GetInstanceStatus(ctx context.Context) (CloudStatus, error)

func (*CloudHost) GetSSHOptions

func (cloudHost *CloudHost) GetSSHOptions() ([]string, error)

func (*CloudHost) IsUp

func (cloudHost *CloudHost) IsUp(ctx context.Context) (bool, error)

func (*CloudHost) TerminateInstance

func (cloudHost *CloudHost) TerminateInstance(ctx context.Context, user string) error

type CloudStatus

type CloudStatus int

func (CloudStatus) String

func (stat CloudStatus) String() string

type ContainerManager

type ContainerManager interface {
	Manager

	// GetContainers returns the IDs of all running containers on a specified host
	GetContainers(context.Context, *host.Host) ([]string, error)
}

func ConvertContainerManager

func ConvertContainerManager(m Manager) (ContainerManager, error)

ConvertContainerManager converts a regular manager into a container manager, errors if type conversion not possible.

type CostCalculator

type CostCalculator interface {
	CostForDuration(context.Context, *host.Host, time.Time, time.Time) (float64, error)
}

CostCalculator is an interface for cloud providers that can estimate what a span of time on a given host costs.

type EC2ManagerOptions

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

EC2ManagerOptions are used to construct a new ec2Manager.

type EC2ProviderSettings

type EC2ProviderSettings struct {
	// AMI is the AMI ID.
	AMI string `mapstructure:"ami" json:"ami,omitempty" bson:"ami,omitempty"`

	// If set, overrides key from credentials
	AWSKeyID string `mapstructure:"aws_access_key_id" bson:"aws_access_key_id,omitempty"`

	// If set, overrides secret from credentials
	AWSSecret string `mapstructure:"aws_secret_access_key" bson:"aws_secret_access_key,omitempty"`

	// InstanceType is the EC2 instance type.
	InstanceType string `mapstructure:"instance_type" json:"instance_type,omitempty" bson:"instance_type,omitempty"`

	// KeyName is the AWS SSH key name.
	KeyName string `mapstructure:"key_name" json:"key_name,omitempty" bson:"key_name,omitempty"`

	// MountPoints are the disk mount points for EBS volumes.
	MountPoints []MountPoint `mapstructure:"mount_points" json:"mount_points,omitempty" bson:"mount_points,omitempty"`

	// SecurityGroupIDs is a list of security group IDs.
	SecurityGroupIDs []string `mapstructure:"security_group_ids" json:"security_group_ids,omitempty" bson:"security_group_ids,omitempty"`

	// SubnetId is only set in a VPC. Either subnet id or vpc name must set.
	SubnetId string `mapstructure:"subnet_id" json:"subnet_id,omitempty" bson:"subnet_id,omitempty"`

	// VpcName is used to get the subnet ID automatically. Either subnet id or vpc name must set.
	VpcName string `mapstructure:"vpc_name" json:"vpc_name,omitempty" bson:"vpc_name,omitempty"`

	// IsVpc is set to true if the security group is part of a VPC.
	IsVpc bool `mapstructure:"is_vpc" json:"is_vpc,omitempty" bson:"is_vpc,omitempty"`

	// BidPrice is the price we are willing to pay for a spot instance.
	BidPrice float64 `mapstructure:"bid_price" json:"bid_price,omitempty" bson:"bid_price,omitempty"`

	// UserData are commands to run after the instance starts.
	UserData string `mapstructure:"user_data" json:"user_data" bson:"user_data,omitempty"`

	// Region is the EC2 region in which the instance will start. If empty,
	// the ec2Manager will spawn in "us-east-1".
	Region string `mapstructure:"region" json:"region" bson:"region,omitempty"`
}

EC2ProviderSettings describes properties of managed instances.

func (*EC2ProviderSettings) Validate

func (s *EC2ProviderSettings) Validate() error

Validate that essential EC2ProviderSettings fields are not empty.

type GCESettings

type GCESettings struct {
	Project string `mapstructure:"project_id"`
	Zone    string `mapstructure:"zone"`

	ImageName   string `mapstructure:"image_name"`
	ImageFamily string `mapstructure:"image_family"`

	MachineName string `mapstructure:"instance_type"`
	NumCPUs     int64  `mapstructure:"num_cpus"`
	MemoryMB    int64  `mapstructure:"memory_mb"`

	DiskType   string `mapstructure:"disk_type"`
	DiskSizeGB int64  `mapstructure:"disk_size_gb"`

	// Network tags are used to configure network firewalls.
	NetworkTags []string `mapstructure:"network_tags"`

	// By default, GCE uses project-wide SSH keys. Project-wide keys should be manually
	// added to the project metadata. These SSH keys are optional instance-wide keys.
	SSHKeys sshKeyGroup `mapstructure:"ssh_keys"`
}

GCESettings specifies the settings used to configure a host instance.

func (*GCESettings) Validate

func (opts *GCESettings) Validate() error

Validate verifies a set of GCESettings.

type HostOptions

type HostOptions struct {
	ProvisionOptions   *host.ProvisionOptions
	ExpirationDuration *time.Duration
	UserName           string
	UserHost           bool

	HasContainers         bool
	ParentID              string
	ContainerPoolSettings *evergreen.ContainerPool
	SpawnOptions          host.SpawnOptions
}

HostOptions is a struct of options that are commonly passed around when creating a new cloud host.

type Manager

type Manager interface {
	// Returns a pointer to the manager's configuration settings struct
	GetSettings() ProviderSettings

	//Load credentials or other settings from the config file
	Configure(context.Context, *evergreen.Settings) error

	// SpawnHost attempts to create a new host by requesting one from the
	// provider's API.
	SpawnHost(context.Context, *host.Host) (*host.Host, error)

	// get the status of an instance
	GetInstanceStatus(context.Context, *host.Host) (CloudStatus, error)

	// TerminateInstances destroys the host in the underlying provider
	TerminateInstance(context.Context, *host.Host, string) error

	//IsUp returns true if the underlying provider has not destroyed the
	//host (in other words, if the host "should" be reachable. This does not
	//necessarily mean that the host actually *is* reachable via SSH
	IsUp(context.Context, *host.Host) (bool, error)

	//Called by the hostinit process when the host is actually up. Used
	//to set additional provider-specific metadata
	OnUp(context.Context, *host.Host) error

	// GetDNSName returns the DNS name of a host.
	GetDNSName(context.Context, *host.Host) (string, error)

	// GetSSHOptions generates the command line args to be passed to ssh to
	// allow connection to the machine
	GetSSHOptions(*host.Host, string) ([]string, error)

	// TimeTilNextPayment returns how long there is until the next payment
	// is due for a particular host
	TimeTilNextPayment(*host.Host) time.Duration
}

Manager is an interface which handles creating new hosts or modifying them via some third-party API.

func GetManager

func GetManager(ctx context.Context, providerName string, settings *evergreen.Settings) (Manager, error)

GetManager returns an implementation of Manager for the given provider name. It returns an error if the provider name doesn't have a known implementation.

func NewEC2Manager

func NewEC2Manager(opts *EC2ManagerOptions) Manager

NewEC2Manager creates a new manager of EC2 spot and on-demand instances.

type MockInstance

type MockInstance struct {
	IsUp               bool
	IsSSHReachable     bool
	Status             CloudStatus
	SSHOptions         []string
	TimeTilNextPayment time.Duration
	DNSName            string
	OnUpRan            bool
}

MockInstance mocks a running server that Evergreen knows about. It contains fields that can be set to change the response the cloud manager returns when this mock instance is queried for.

type MockProvider

type MockProvider interface {
	Len() int
	Reset()
	Get(string) MockInstance
	Set(string, MockInstance)
	IterIDs() <-chan string
	IterInstances() <-chan MockInstance
}

func GetMockProvider

func GetMockProvider() MockProvider

type MountPoint

type MountPoint struct {
	VirtualName string `mapstructure:"virtual_name" json:"virtual_name,omitempty" bson:"virtual_name,omitempty"`
	DeviceName  string `mapstructure:"device_name" json:"device_name,omitempty" bson:"device_name,omitempty"`
	Size        int64  `mapstructure:"size" json:"size,omitempty" bson:"size,omitempty"`
	Iops        int64  `mapstructure:"iops" json:"iops,omitempty" bson:"iops,omitempty"`
	SnapshotID  string `mapstructure:"snapshot_id" json:"snapshot_id,omitempty" bson:"snapshot_id,omitempty"`
}

type ProviderSettings

type ProviderSettings interface {
	Validate() error
}

ProviderSettings exposes provider-specific configuration settings for a Manager.

type SpawnOptions

type SpawnOptions struct {
	Distro    string
	UserName  string
	PublicKey string
	TaskId    string
	Owner     *user.DBUser
}

Options holds the required parameters for spawning a host.

type StaticHost

type StaticHost struct {
	Name string `mapstructure:"name" json:"name" bson:"name"`
}

type StaticSettings

type StaticSettings struct {
	Hosts []StaticHost `mapstructure:"hosts" json:"hosts" bson:"hosts"`
}

func (*StaticSettings) Validate

func (s *StaticSettings) Validate() error

Validate checks that the settings from the configuration are valid.

type Terms

type Terms struct {
	OnDemand map[string]map[string]struct {
		PriceDimensions map[string]struct {
			PricePerUnit struct {
				USD string
			}
		}
	}
}

Terms is an internal type for loading price API results into.

Jump to

Keyboard shortcuts

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