vultr

package
v0.0.0-...-d5b31fc Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 15 Imported by: 0

README

See More:

Vultr OpenAPI Docs

https://www.vultr.com/api/

Refs

https://github.com/JamesClonk/vultr

Documentation

Overview

Package vultr ... this file rewrap existing methods to implement the cloudsvr.Handler interface

Package vultr ... Most borrowed from:

https://github.com/JamesClonk/vultr/blob/master/lib/servers.go

Index

Constants

This section is empty.

Variables

View Source
var (
	// OsImage is exported
	OsImage = 167 // CentOS 7 x64
	// NodeLabelPrefix is exported
	NodeLabelPrefix = "inf-agent-vultr-node"
)
View Source
var (
	// CloudType is exported
	CloudType = "vultr"
)
View Source
var (
	// DefaultAPIEndPoint is exported
	DefaultAPIEndPoint = "https://api.vultr.com/v1"
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Balance           float64 `json:"balance,string"`
	PendingCharges    float64 `json:"pending_charges,string"`
	LastPaymentDate   string  `json:"last_payment_date"`
	LastPaymentAmount float64 `json:"last_payment_amount,string"`
}

Account is exported

type Config

type Config struct {
	EndPoint  string `json:"endpoint,omitempty"`
	AccessKey string `json:"access_key"`
}

Config is exported

func (*Config) Valid

func (cfg *Config) Valid() error

Valid is exported

type CreateServerInput

type CreateServerInput struct {
	DCID                 int // must
	VPSPLANID            int // must
	OSID                 int // must
	ISOID                string
	SCRIPTID             string
	SNAPSHOTID           string
	EnableIPv6           bool
	EnablePrivateNetwork bool
	NETWORKID            string
	Label                string // label text
	SSHKEYID             string
	AutoBackups          bool
	APPID                string
	Userdata             string
	NotifyActivate       bool
	DdosProtection       bool
	ReservedIPv4         string
	Hostname             string
	Tag                  string
	FIREWALLGROUPID      string
}

CreateServerInput is exported See: https://www.vultr.com/api/#server_create

func (*CreateServerInput) ToURLValues

func (req *CreateServerInput) ToURLValues() url.Values

ToURLValues is exported TODO more ...

func (*CreateServerInput) Validate

func (req *CreateServerInput) Validate() error

Validate is exported

type Plan

type Plan struct {
	ID        int     `json:"VPSPLANID,string"`
	Name      string  `json:"name"` // Starter, Basic ...
	VCpus     int     `json:"vcpu_count,string"`
	RAM       int     `json:"ram,string"`             // by MiB
	Disk      int     `json:"disk,string"`            // by GiB
	Bandwidth float64 `json:"bandwidth,string"`       // by MiB
	Price     float64 `json:"price_per_month,string"` // by $
	Type      string  `json:"plan_type"`              // SSD SATA
	Regions   []int   `json:"available_locations"`
}

Plan is exported

type Region

type Region struct {
	ID           int    `json:"DCID,string"`
	Name         string `json:"name"`
	Country      string `json:"country"`
	Continent    string `json:"continent"`
	State        string `json:"state"`
	Ddos         bool   `json:"ddos_protection"`
	BlockStorage bool   `json:"block_storage"`
	Code         string `json:"regioncode"`
}

Region is exported

type SDK

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

SDK is an implement of CloudSvr

func Setup

func Setup(cfg *Config) (*SDK, error)

Setup is exported

func (*SDK) APIEndPoint

func (sdk *SDK) APIEndPoint() string

APIEndPoint is exported

func (*SDK) AccessKey

func (sdk *SDK) AccessKey() string

AccessKey is exported

func (*SDK) AccountInfo

func (sdk *SDK) AccountInfo() (*Account, error)

AccountInfo is exported

func (*SDK) InspectEcs

func (sdk *SDK) InspectEcs(id int) (*Server, error)

InspectEcs show details of a given ecs instance

func (*SDK) InspectNode

func (sdk *SDK) InspectNode(id, regionOrZone string) (interface{}, error)

InspectNode show details of one given ecs instance

func (*SDK) ListCloudRegions

func (sdk *SDK) ListCloudRegions() ([]*cloudsvr.CloudRegion, error)

ListCloudRegions implement cloudsvr.Handler

func (*SDK) ListCloudTypes

func (sdk *SDK) ListCloudTypes(region string) ([]*cloudsvr.CloudNodeType, error)

ListCloudTypes implement cloudsvr.Handler

func (*SDK) ListEcses

func (sdk *SDK) ListEcses() (map[string]*Server, error)

ListEcses show all of ecs instances

func (*SDK) ListNodes

func (sdk *SDK) ListNodes() ([]*cloudsvr.CloudNode, error)

ListNodes list all vultr ecs instances with label prefix: NodeLabelPrefix the nodes listed does NOT have any auth fields `User` `Password`

func (*SDK) ListPlans

func (sdk *SDK) ListPlans(minCPU, maxCPU, minMem, maxMem int) (map[string]*Plan, error)

ListPlans show all of instance plans support cpu / memory minimal/maximize filter parameters note: public api, do NOT require auth

func (*SDK) ListRegions

func (sdk *SDK) ListRegions() (map[string]*Region, error)

ListRegions show all of regions vultr supported note: public api, do NOT require auth

func (*SDK) NewEcs

func (sdk *SDK) NewEcs(req *CreateServerInput) (int, error)

NewEcs create a new ecs instance with given settings

func (*SDK) NewNode

func (sdk *SDK) NewNode(prefer *cloudsvr.PreferAttrs) (*cloudsvr.CloudNode, *cloudsvr.PreferAttrs, error)

NewNode create vultr ecs instance, try to use prefered attributes firstly

func (*SDK) Ping

func (sdk *SDK) Ping() error

Ping verify the cloudsvr settings could be working fine

func (*SDK) RemoveEcs

func (sdk *SDK) RemoveEcs(id int) error

RemoveEcs remove the specified ecs instance

func (*SDK) RemoveNode

func (sdk *SDK) RemoveNode(node *cloudsvr.CloudNode) error

RemoveNode remove vultr ecs instance

func (*SDK) Type

func (sdk *SDK) Type() string

Type implement cloudsvr.Handler

func (*SDK) Verify

func (sdk *SDK) Verify() error

Verify verifies configs about vultr endpoint & access id & access key

func (*SDK) WaitEcs

func (sdk *SDK) WaitEcs(id int, expectStatus string, maxWait time.Duration) error

WaitEcs wait ecs instance status reached to expected status until maxWait timeout note: vultr server status should be wait for at least 3 consecutive status

type Server

type Server struct {
	ID               string      `json:"SUBID"`
	Label            string      `json:"label"`
	OS               string      `json:"os"`
	RAM              string      `json:"ram"`
	Disk             string      `json:"disk"`
	MainIP           string      `json:"main_ip"`
	VCpus            int         `json:"vcpu_count,string"`
	Location         string      `json:"location"`
	RegionID         int         `json:"DCID,string"`
	DefaultPassword  string      `json:"default_password"`
	Created          string      `json:"date_created"`
	PendingCharges   float64     `json:"pending_charges"`
	Status           string      `json:"status"` // pending | active | suspended | closed
	Cost             string      `json:"cost_per_month"`
	CurrentBandwidth float64     `json:"current_bandwidth_gb"`
	AllowedBandwidth float64     `json:"allowed_bandwidth_gb,string"`
	NetmaskV4        string      `json:"netmask_v4"`
	GatewayV4        string      `json:"gateway_v4"`
	PowerStatus      string      `json:"power_status"` // running, stopped ...
	ServerState      string      `json:"server_state"` // none | locked | installingbooting | isomounting | ok
	PlanID           int         `json:"VPSPLANID,string"`
	V6Networks       []V6Network `json:"v6_networks"`
	InternalIP       string      `json:"internal_ip"`
	KVMUrl           string      `json:"kvm_url"`
	AutoBackups      string      `json:"auto_backups"`
	Tag              string      `json:"tag"`
	OSID             string      `json:"OSID"`
	AppID            string      `json:"APPID"`
	FirewallGroupID  string      `json:"FIREWALLGROUPID"`
}

Server is exported

func (*Server) UnmarshalJSON

func (s *Server) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements json.Unmarshaller on Server. This is needed because the Vultr API is inconsistent in it's JSON responses for servers. Some fields can change type, from JSON number to JSON string and vice-versa.

type V6Network

type V6Network struct {
	Network     string `json:"v6_network"`
	MainIP      string `json:"v6_main_ip"`
	NetworkSize string `json:"v6_network_size"`
}

V6Network represents a IPv6 network of a Vultr server

Jump to

Keyboard shortcuts

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