Documentation ¶
Overview ¶
Package aws provides a standard way to create a virtual machine on AWS.
Index ¶
- Constants
- Variables
- func ValidCredentials(region string) error
- type VM
- func (vm *VM) DeleteKeyPair() error
- func (vm *VM) Destroy() error
- func (vm *VM) GetIPs() ([]net.IP, error)
- func (vm *VM) GetName() string
- func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)
- func (vm *VM) GetState() (string, error)
- func (vm *VM) Halt() error
- func (vm *VM) Provision() error
- func (vm *VM) Resume() error
- func (vm *VM) SetTag(key, value string) error
- func (vm *VM) Start() error
- func (vm *VM) Suspend() error
- func (vm *VM) UseKeyPair(kp *ssh.KeyPair, name string) error
Constants ¶
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 ¶
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 ¶
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 ¶
DeleteKeyPair deletes the key pair set for this VM.
func (*VM) Destroy ¶
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 ¶
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) GetSSH ¶
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 ¶
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) Provision ¶
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) UseKeyPair ¶
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.