digitalocean

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: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusOk is the first number of a successful HTTP return code
	StatusOk = '2'
	// StatusNotFound is the status code for a 404
	StatusNotFound = 404
)

Variables

View Source
var (
	// ErrNoInstanceID is returned when attempting to perform an operation on an instance, but the ID is missing.
	ErrNoInstanceID = errors.New("Missing droplet ID")
)

Functions

func BuildRequest

func BuildRequest(token, method, url string, body io.Reader) (*http.Request, error)

BuildRequest builds an http request for this provider.

func PrintDroplet

func PrintDroplet(droplet *Droplet)

PrintDroplet prints the basic droplet values

Types

type Config

type Config struct {
	Name              string   `json:"name,omitempty"`   // required
	Region            string   `json:"region,omitempty"` // required
	Size              string   `json:"size,omitempty"`   // required
	Image             string   `json:"image,omitempty"`  // required
	SSHKeys           []string `json:"ssh_keys,omitempty"`
	Backups           bool     `json:"backups,omitempty"`
	IPv6              bool     `json:"ipv6,omitempty"`
	PrivateNetworking bool     `json:"private_networking,omitempty"`
	UserData          string   `json:"user_data,omitempty"`
}

Config is the new droplet payload

type Droplet

type Droplet struct {
	ID          int       `json:"id,omitempty"`
	Name        string    `json:"name,omitempty"`
	Region      *Region   `json:"region,omitempty"`
	Image       *Image    `json:"image,omitempty"`
	Size        *Size     `json:"size,omitempty"`
	SizeSlug    string    `json:"size_slug,omitempty"`
	Locked      bool      `json:"locked,omitempty"`
	Status      string    `json:"status,omitempty"`
	Networks    *Networks `json:"networks,omitempty"`
	Kernel      *Kernel   `json:"kernel,omitempty"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
	BackupIds   []int64   `json:"backup_ids,omitempty"`
	SnapshotIds []int64   `json:"snapshot_ids,omitempty"`
	ActionIds   []int64   `json:"action_ids,omitempty"`
}

Droplet is the base VM type in DigitalOcean

func GetDroplet

func GetDroplet(token, id string) (*Droplet, error)

GetDroplet returns a single droplet

type DropletResponse

type DropletResponse struct {
	Droplet *Droplet `json:"droplet,omitempty"`
}

DropletResponse is the API response containing one droplet

type DropletsResponse

type DropletsResponse struct {
	Droplets []*Droplet `json:"droplets"`
	Meta     *Meta      `json:"meta,omitempty"`
}

DropletsResponse is the API response containing multiple droplets

func GetDroplets

func GetDroplets(token string) (*DropletsResponse, error)

GetDroplets returns and array of droplets

type Image

type Image struct {
	ID           int       `json:"id,omitempty"`
	Name         string    `json:"name,omitempty"`
	Distribution string    `json:"distribution,omitempty"`
	Slug         string    `json:"slug,omitempty"`
	Public       bool      `json:"public,omitempty"`
	Regions      []string  `json:"regions,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
}

Image contains droplet image information

type Kernel

type Kernel struct {
	ID      int64  `json:"id,omitempty"`
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
}

Kernel contains droplet kernel information

type Meta

type Meta struct {
	Total int `json:"total,omitempty"`
}

Meta contains metadata from API responses

type Networks

type Networks struct {
	V4 []*V4Network `json:"v4,omitempty"`
	V6 []*V6Network `json:"v6,omitempty"`
}

Networks contains information on all droplet networks

type Region

type Region struct {
	Slug      string   `json:"slug,omitempty"`
	Name      string   `json:"name,omitempty"`
	Sizes     []string `json:"sizes,omitempty"`
	Available bool     `json:"available,omitempty"`
	Features  []string `json:"features,omitempty"`
}

Region contains droplet region information

type Size

type Size struct {
	Slug          string      `json:"slug,omitempty"`
	Memory        int         `json:"memory,omitempty"`
	VCpus         int         `json:"v_cpus,omitempty"`
	Disk          int         `json:"disk,omitempty"`
	Transfer      interface{} `json:"transfer,omitempty"`
	PriceMonthley float64     `json:"price_monthley,omitempty"`
	PriceHourly   float64     `json:"price_hourly,omitempty"`
	Regions       []string    `json:"regions,omitempty"`
}

Size describes droplet sizing

type V4Network

type V4Network struct {
	IPAddress string `json:"ip_address,omitempty"`
	Netmask   string `json:"netmask,omitempty"`
	Gateway   string `json:"gateway,omitempty"`
	Type      string `json:"type,omitempty"`
}

V4Network contains an IPV4 network's values

type V6Network

type V6Network struct {
	IPAddress string `json:"ip_address,omitempty"`
	Netmask   int64  `json:"netmask,omitempty"`
	Gateway   string `json:"gateway,omitempty"`
	Type      string `json:"type,omitempty"`
}

V6Network contains an IPV6 network's values

type VM

type VM struct {
	APIToken    string // required
	Credentials libssh.Credentials
	Config      Config
	Droplet     *Droplet
}

VM struct represents a full DigitalOcean VM in libretto. It contains the droplet itself, along with authentication and SSH credential information. It also contains the original creation config.

func (*VM) Destroy

func (vm *VM) Destroy() error

Destroy powers off the VM and deletes its files from disk

func (*VM) GetIPs

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

GetIPs returns a list of ip addresses associated with the VM

func (*VM) GetName

func (vm *VM) GetName() string

GetName returns the name of the virtual machine

func (*VM) GetSSH

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

GetSSH returns an ssh client for the the vm.

func (*VM) GetState

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

GetState gets the running state of the VM through the DigitalOcean API Returns droplet state if available and 'not_found' if ID could not be located.

func (*VM) Halt

func (vm *VM) Halt() error

Halt powers off the VM without destroying it

func (*VM) Provision

func (vm *VM) Provision() error

Provision creates a new VM

func (*VM) Resume

func (vm *VM) Resume() error

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

func (*VM) Start

func (vm *VM) Start() error

Start powers on the VM

func (*VM) Suspend

func (vm *VM) Suspend() error

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

func (*VM) Update

func (vm *VM) Update() error

Update vm.Droplet values. This occurs in GetState(), so we call that and ignore the state string.

Jump to

Keyboard shortcuts

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