aws

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package aws provides a standard way to create a virtual machine on AWS.

Index

Constants

View Source
const (

	// PublicIP is the index of the public IP address that GetIPs returns.
	PublicIP = 0
	// PrivateIP is the index of the private IP address that GetIPs returns.
	PrivateIP = 1

	// RegionEnv is the env var for the AWS region.
	RegionEnv = "AWS_DEFAULT_REGION"

	// ProvisionTimeout is the maximum seconds to wait before failing to
	// provision.
	ProvisionTimeout = 90
	// SSHTimeout is the maximum time to wait before failing to GetSSH.
	SSHTimeout = 5 * time.Minute

	// StateStarted is the state AWS reports when the VM is started.
	StateStarted = "running"
	// StateHalted is the state AWS reports when the VM is halted.
	StateHalted = "stopped"
	// StateDestroyed is the state AWS reports when the VM is destroyed.
	StateDestroyed = "terminated"
	// StatePending is the state AWS reports when the VM is pending.
	StatePending = "pending"
)

Variables

View Source
var (
	// ErrNoCreds is returned when no credentials are found in environment or
	// home directory.
	ErrNoCreds = errors.New("Missing AWS credentials")
	// ErrNoRegion is returned when a request was sent without a region.
	ErrNoRegion = errors.New("Missing AWS region")
	// ErrNoInstance is returned querying an instance, but none is found.
	ErrNoInstance = errors.New("Missing VM instance")
	// ErrNoInstanceID is returned when attempting to perform an operation on
	// an instance, but the ID is missing.
	ErrNoInstanceID = errors.New("Missing instance ID")
	// ErrProvisionTimeout is returned when the EC2 instance takes too long to
	// enter "running" state.
	ErrProvisionTimeout = errors.New("AWS provision timeout")
	// ErrNoIPs is returned when no IP addresses are found for an instance.
	ErrNoIPs = errors.New("Missing IPs for instance")
	// ErrNoSupportSuspend is returned when vm.Suspend() is called.
	ErrNoSupportSuspend = errors.New("Suspend action not supported by AWS")
	// ErrNoSupportResume is returned when vm.Resume() is called.
	ErrNoSupportResume = errors.New("Resume action not supported by AWS")
)

Functions

func ValidCredentials

func ValidCredentials(region string) error

ValidCredentials sends a dummy request to AWS to check if credentials are valid. An error is returned if credentials are missing or region is missing.

Types

type VM

type VM struct {
	Name         string
	Region       string // required
	AMI          string
	InstanceType string
	InstanceID   string
	KeyPair      string // required

	DeviceName                   string
	VolumeSize                   int
	VolumeType                   string
	KeepRootVolumeOnDestroy      bool
	DeleteNonRootVolumeOnDestroy bool

	VPC           string
	Subnet        string
	SecurityGroup string

	SSHCreds            ssh.Credentials // required
	DeleteKeysOnDestroy bool
}

VM represents an AWS EC2 virtual machine.

func (*VM) DeleteKeyPair

func (vm *VM) DeleteKeyPair() error

DeleteKeyPair deletes the key pair set for this VM.

func (*VM) Destroy

func (vm *VM) Destroy() error

Destroy terminates the VM on AWS. It returns an error if AWS credentials are missing or if there is no instance ID.

func (*VM) GetIPs

func (vm *VM) GetIPs() ([]net.IP, error)

GetIPs returns a slice of IP addresses assigned to the VM. The PublicIP or PrivateIP consts can be used to retrieve respective IP address type. It returns nil if there was an error obtaining the IPs.

func (*VM) GetName

func (vm *VM) GetName() string

GetName returns the name of the virtual machine

func (*VM) GetSSH

func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)

GetSSH returns an SSH client that can be used to connect to a VM. An error is returned if the VM has no IPs.

func (*VM) GetState

func (vm *VM) GetState() (string, error)

GetState returns the state of the VM, such as "running". An error is returned if the instance ID is missing, if there was a problem querying AWS, or if there are no instances.

func (*VM) Halt

func (vm *VM) Halt() error

Halt shuts down the VM on AWS.

func (*VM) Provision

func (vm *VM) Provision() error

Provision creates a virtual machine on AWS. It returns an error if there was a problem during creation, if there was a problem adding a tag, or if the VM takes too long to enter "running" state.

func (*VM) Resume

func (vm *VM) Resume() error

Resume always returns an error because this isn't supported by AWS.

func (*VM) SetTag

func (vm *VM) SetTag(key, value string) error

SetTag adds a tag to the VM and its attached volumes.

func (*VM) Start

func (vm *VM) Start() error

Start boots a stopped VM.

func (*VM) Suspend

func (vm *VM) Suspend() error

Suspend always returns an error because this isn't supported by AWS.

func (*VM) UseKeyPair

func (vm *VM) UseKeyPair(kp *ssh.KeyPair, name string) error

UseKeyPair uploads the public part of a keypair to AWS with a given name and sets the private part as the VM's private key. If the public key already exists, then the private key will still be assigned to this VM and the error will be nil.

Jump to

Keyboard shortcuts

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