packngo

package module
v0.0.0-...-bc067ae Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2018 License: BSD-3-Clause, MIT Imports: 14 Imported by: 1

README

packngo

Packet Go Api Client

Installation

go get github.com/packethost/packngo

Usage

To authenticate to the Packet API, you must have your API token exported in env var PACKET_API_TOKEN.

This code snippet initializes Packet API client, and lists your Projects:

package main

import (
	"log"

	"github.com/packethost/packngo"
)

func main() {
	c, err := packngo.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	ps, _, err := c.Projects.List()
	if err != nil {
		log.Fatal(err)
	}
	for _, p := range ps {
		log.Println(p.ID, p.Name)
	}
}

This lib is used by the official terraform-provider-packet.

You can also learn a lot from the *_test.go sources. Almost all out tests touch the Packet API, so you can see how auth, querying and POSTing works. For example devices_test.go.

Acceptance Tests

If you want to run tests against the actual Packet API, you must set envvar PACKET_TEST_ACTUAL_API to non-empty string for the go test. The device tests wait for the device creation, so it's best to run a few in parallel.

To run a particular test, you can do

$ PACKNGO_TEST_ACTUAL_API=1 go test -v -run=TestAccDeviceBasic

If you want to see HTTP requests, set the PACKNGO_DEBUG env var to non-empty string, for example:

$ PACKNGO_DEBUG=1 PACKNGO_TEST_ACTUAL_API=1 go test -v -run=TestAccVolumeUpdate

Committing

Before committing, it's a good idea to run gofmt -w *.go. (gofmt)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func Stringify

func Stringify(message interface{}) string

Stringify creates a string representation of the provided message

Types

type Address

type Address struct {
	ID string `json:"id,omitempty"`
}

Address - the physical address of the facility

func (Address) String

func (a Address) String() string

type AddressRequest

type AddressRequest struct {
	AddressFamily int  `json:"address_family"`
	Public        bool `json:"public"`
}

type AddressStruct

type AddressStruct struct {
	Address string `json:"address"`
}

AddressStruct is a helper type for request/response with dict like {"address": ... }

type AvailableRequest

type AvailableRequest struct {
	CIDR int `json:"cidr"`
}

AvailableRequest is a type for listing available addresses from a reserved block.

type AvailableResponse

type AvailableResponse struct {
	Available []string `json:"available"`
}

AvailableResponse is a type for listing of available addresses from a reserved block.

type BackToL3Request

type BackToL3Request struct {
	RequestIPs []AddressRequest `json:"request_ips"`
}

type BillingAddress

type BillingAddress struct {
	StreetAddress string `json:"street_address,omitempty"`
	PostalCode    string `json:"postal_code,omitempty"`
	CountryCode   string `json:"country_code_alpha2,omitempty"`
}

type BondRequest

type BondRequest struct {
	PortID     string `json:"id"`
	BulkEnable bool   `json:"bulk_enable"`
}

type Client

type Client struct {
	BaseURL *url.URL

	UserAgent     string
	ConsumerToken string
	APIKey        string

	RateLimit Rate

	// Packet Api Objects
	Plans                  PlanService
	Users                  UserService
	Emails                 EmailService
	SSHKeys                SSHKeyService
	Devices                DeviceService
	Projects               ProjectService
	Facilities             FacilityService
	OperatingSystems       OSService
	DeviceIPs              DeviceIPService
	DevicePorts            DevicePortService
	ProjectIPs             ProjectIPService
	ProjectVirtualNetworks ProjectVirtualNetworkService
	Volumes                VolumeService
	VolumeAttachments      VolumeAttachmentService
	SpotMarket             SpotMarketService
	Organizations          OrganizationService
	// contains filtered or unexported fields
}

Client is the base API Client

func NewClient

func NewClient() (*Client, error)

func NewClientWithAuth

func NewClientWithAuth(consumerToken string, apiKey string, httpClient *http.Client) *Client

NewClientWithAuth initializes and returns a Client, use this to get an API Client to operate on N.B.: Packet's API certificate requires Go 1.5+ to successfully parse. If you are using an older version of Go, pass in a custom http.Client with a custom TLS configuration that sets "InsecureSkipVerify" to "true"

func NewClientWithBaseURL

func NewClientWithBaseURL(consumerToken string, apiKey string, httpClient *http.Client, apiBaseURL string) (*Client, error)

NewClientWithBaseURL returns a Client pointing to nonstandard API URL, e.g. for mocking the remote API

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do executes the http request

func (*Client) DoRequest

func (c *Client) DoRequest(method, path string, body, v interface{}) (*Response, error)

DoRequest is a convenience method, it calls NewRequest followed by Do v is the interface to unmarshal the response JSON into

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error)

NewRequest inits a new http request with the proper headers

type Cpus

type Cpus struct {
	Count int    `json:"count,omitempty"`
	Type  string `json:"type,omitempty"`
}

Cpus - the CPU config details for specs on a plan

func (Cpus) String

func (c Cpus) String() string

type Device

type Device struct {
	ID                  string                 `json:"id"`
	Href                string                 `json:"href,omitempty"`
	Hostname            string                 `json:"hostname,omitempty"`
	State               string                 `json:"state,omitempty"`
	Created             string                 `json:"created_at,omitempty"`
	Updated             string                 `json:"updated_at,omitempty"`
	Locked              bool                   `json:"locked,omitempty"`
	BillingCycle        string                 `json:"billing_cycle,omitempty"`
	Storage             map[string]interface{} `json:"storage,omitempty"`
	Tags                []string               `json:"tags,omitempty"`
	Network             []*IPAddressAssignment `json:"ip_addresses"`
	Volumes             []*Volume              `json:"volumes"`
	OS                  *OS                    `json:"operating_system,omitempty"`
	Plan                *Plan                  `json:"plan,omitempty"`
	Facility            *Facility              `json:"facility,omitempty"`
	Project             *Project               `json:"project,omitempty"`
	ProvisionEvents     []*ProvisionEvent      `json:"provisioning_events,omitempty"`
	ProvisionPer        float32                `json:"provisioning_percentage,omitempty"`
	UserData            string                 `json:"userdata,omitempty"`
	RootPassword        string                 `json:"root_password,omitempty"`
	IPXEScriptURL       string                 `json:"ipxe_script_url,omitempty"`
	AlwaysPXE           bool                   `json:"always_pxe,omitempty"`
	HardwareReservation Href                   `json:"hardware_reservation,omitempty"`
	SpotInstance        bool                   `json:"spot_instance,omitempty"`
	SpotPriceMax        float64                `json:"spot_price_max,omitempty"`
	TerminationTime     *Timestamp             `json:"termination_time,omitempty"`
	NetworkPorts        []Port                 `json:"network_ports,omitempty"`
	CustomData          map[string]interface{} `json:"customdata,omitempty"`
}

Device represents a Packet device

func (Device) String

func (d Device) String() string

type DeviceActionRequest

type DeviceActionRequest struct {
	Type string `json:"type"`
}

DeviceActionRequest type used to execute actions on devices

func (DeviceActionRequest) String

func (d DeviceActionRequest) String() string

type DeviceCreateRequest

type DeviceCreateRequest struct {
	Hostname              string     `json:"hostname"`
	Plan                  string     `json:"plan"`
	Facility              string     `json:"facility"`
	OS                    string     `json:"operating_system"`
	BillingCycle          string     `json:"billing_cycle"`
	ProjectID             string     `json:"project_id"`
	UserData              string     `json:"userdata"`
	Storage               string     `json:"storage,omitempty"`
	Tags                  []string   `json:"tags"`
	IPXEScriptURL         string     `json:"ipxe_script_url,omitempty"`
	PublicIPv4SubnetSize  int        `json:"public_ipv4_subnet_size,omitempty"`
	AlwaysPXE             bool       `json:"always_pxe,omitempty"`
	HardwareReservationID string     `json:"hardware_reservation_id,omitempty"`
	SpotInstance          bool       `json:"spot_instance,omitempty"`
	SpotPriceMax          float64    `json:"spot_price_max,omitempty,string"`
	TerminationTime       *Timestamp `json:"termination_time,omitempty"`
	CustomData            string     `json:"customdata,omitempty"`
}

DeviceCreateRequest type used to create a Packet device

func (DeviceCreateRequest) String

func (d DeviceCreateRequest) String() string

type DeviceIPService

type DeviceIPService interface {
	Assign(deviceID string, assignRequest *AddressStruct) (*IPAddressAssignment, *Response, error)
	Unassign(assignmentID string) (*Response, error)
	Get(assignmentID string) (*IPAddressAssignment, *Response, error)
}

DeviceIPService handles assignment of addresses from reserved blocks to instances in a project.

type DeviceIPServiceOp

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

DeviceIPServiceOp is interface for IP-address assignment methods.

func (*DeviceIPServiceOp) Assign

func (i *DeviceIPServiceOp) Assign(deviceID string, assignRequest *AddressStruct) (*IPAddressAssignment, *Response, error)

Assign assigns an IP address to a device. The IP address must be in one of the IP ranges assigned to the device’s project.

func (*DeviceIPServiceOp) Get

func (i *DeviceIPServiceOp) Get(assignmentID string) (*IPAddressAssignment, *Response, error)

Get returns assignment by ID.

func (*DeviceIPServiceOp) Unassign

func (i *DeviceIPServiceOp) Unassign(assignmentID string) (*Response, error)

Unassign unassigns an IP address from the device to which it is currently assigned. This will remove the relationship between an IP and the device and will make the IP address available to be assigned to another device.

type DevicePortService

type DevicePortService interface {
	Assign(*PortAssignRequest) (*Port, *Response, error)
	Unassign(*PortAssignRequest) (*Port, *Response, error)
	Bond(*BondRequest) (*Port, *Response, error)
	Disbond(*DisbondRequest) (*Port, *Response, error)
	PortToLayerTwo(string) (*Port, *Response, error)
	PortToLayerThree(string) (*Port, *Response, error)
	DeviceToLayerTwo(string) (*Device, error)
	DeviceToLayerThree(string) (*Device, error)
	DeviceNetworkType(string) (NetworkType, error)
	GetBondPort(string) (*Port, error)
	GetPortByName(string, string) (*Port, error)
}

DevicePortService handles operations on a port which belongs to a particular device

type DevicePortServiceOp

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

func (*DevicePortServiceOp) Assign

func (*DevicePortServiceOp) Bond

func (i *DevicePortServiceOp) Bond(br *BondRequest) (*Port, *Response, error)

func (*DevicePortServiceOp) DeviceNetworkType

func (i *DevicePortServiceOp) DeviceNetworkType(deviceID string) (NetworkType, error)

func (*DevicePortServiceOp) DeviceToLayerThree

func (i *DevicePortServiceOp) DeviceToLayerThree(deviceID string) (*Device, error)

func (*DevicePortServiceOp) DeviceToLayerTwo

func (i *DevicePortServiceOp) DeviceToLayerTwo(deviceID string) (*Device, error)

DeviceToLayerTwo converts device to L2 networking. Use bond0 to attach VLAN.

func (*DevicePortServiceOp) Disbond

func (i *DevicePortServiceOp) Disbond(dr *DisbondRequest) (*Port, *Response, error)

func (*DevicePortServiceOp) GetBondPort

func (i *DevicePortServiceOp) GetBondPort(deviceID string) (*Port, error)

func (*DevicePortServiceOp) GetPortByName

func (i *DevicePortServiceOp) GetPortByName(deviceID, name string) (*Port, error)

func (*DevicePortServiceOp) PortToLayerThree

func (i *DevicePortServiceOp) PortToLayerThree(portID string) (*Port, *Response, error)

func (*DevicePortServiceOp) PortToLayerTwo

func (i *DevicePortServiceOp) PortToLayerTwo(portID string) (*Port, *Response, error)

func (*DevicePortServiceOp) Unassign

func (i *DevicePortServiceOp) Unassign(par *PortAssignRequest) (*Port, *Response, error)

type DeviceService

type DeviceService interface {
	List(ProjectID string, listOpt *ListOptions) ([]Device, *Response, error)
	Get(string) (*Device, *Response, error)
	GetExtra(deviceID string, includes, excludes []string) (*Device, *Response, error)
	Create(*DeviceCreateRequest) (*Device, *Response, error)
	Update(string, *DeviceUpdateRequest) (*Device, *Response, error)
	Delete(string) (*Response, error)
	Reboot(string) (*Response, error)
	PowerOff(string) (*Response, error)
	PowerOn(string) (*Response, error)
	Lock(string) (*Response, error)
	Unlock(string) (*Response, error)
}

DeviceService interface defines available device methods

type DeviceServiceOp

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

DeviceServiceOp implements DeviceService

func (*DeviceServiceOp) Create

func (s *DeviceServiceOp) Create(createRequest *DeviceCreateRequest) (*Device, *Response, error)

Create creates a new device

func (*DeviceServiceOp) Delete

func (s *DeviceServiceOp) Delete(deviceID string) (*Response, error)

Delete deletes a device

func (*DeviceServiceOp) Get

func (s *DeviceServiceOp) Get(deviceID string) (*Device, *Response, error)

Get returns a device by id

func (*DeviceServiceOp) GetExtra

func (s *DeviceServiceOp) GetExtra(deviceID string, includes, excludes []string) (*Device, *Response, error)

GetExtra returns a device by id. Specifying either includes/excludes provides more or less desired detailed information about resources which would otherwise be represented with an href link

func (*DeviceServiceOp) List

func (s *DeviceServiceOp) List(projectID string, listOpt *ListOptions) (devices []Device, resp *Response, err error)

List returns devices on a project

func (*DeviceServiceOp) Lock

func (s *DeviceServiceOp) Lock(deviceID string) (*Response, error)

Lock sets a device to "locked"

func (*DeviceServiceOp) PowerOff

func (s *DeviceServiceOp) PowerOff(deviceID string) (*Response, error)

PowerOff powers on a device

func (*DeviceServiceOp) PowerOn

func (s *DeviceServiceOp) PowerOn(deviceID string) (*Response, error)

PowerOn powers on a device

func (*DeviceServiceOp) Reboot

func (s *DeviceServiceOp) Reboot(deviceID string) (*Response, error)

Reboot reboots on a device

func (*DeviceServiceOp) Unlock

func (s *DeviceServiceOp) Unlock(deviceID string) (*Response, error)

Unlock sets a device to "unlocked"

func (*DeviceServiceOp) Update

func (s *DeviceServiceOp) Update(deviceID string, updateRequest *DeviceUpdateRequest) (*Device, *Response, error)

Update updates an existing device

type DeviceUpdateRequest

type DeviceUpdateRequest struct {
	Hostname      *string   `json:"hostname,omitempty"`
	Description   *string   `json:"description,omitempty"`
	UserData      *string   `json:"userdata,omitempty"`
	Locked        *bool     `json:"locked,omitempty"`
	Tags          *[]string `json:"tags,omitempty"`
	AlwaysPXE     *bool     `json:"always_pxe,omitempty"`
	IPXEScriptURL *string   `json:"ipxe_script_url,omitempty"`
	CustomData    *string   `json:"customdata,omitempty"`
}

DeviceUpdateRequest type used to update a Packet device

type DisbondRequest

type DisbondRequest struct {
	PortID      string `json:"id"`
	BulkDisable bool   `json:"bulk_disable"`
}

type Drives

type Drives struct {
	Count int    `json:"count,omitempty"`
	Size  string `json:"size,omitempty"`
	Type  string `json:"type,omitempty"`
}

Drives - the storage config details for specs on a plan

func (Drives) String

func (d Drives) String() string

type Email

type Email struct {
	ID      string `json:"id"`
	Address string `json:"address"`
	Default bool   `json:"default,omitempty"`
	URL     string `json:"href,omitempty"`
}

Email represents a user's email address

func (Email) String

func (e Email) String() string

type EmailService

type EmailService interface {
	Get(string) (*Email, *Response, error)
}

EmailService interface defines available email methods

type EmailServiceOp

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

EmailServiceOp implements EmailService

func (*EmailServiceOp) Get

func (s *EmailServiceOp) Get(emailID string) (*Email, *Response, error)

Get retrieves an email by id

type ErrorResponse

type ErrorResponse struct {
	Response    *http.Response
	Errors      []string `json:"errors"`
	SingleError string   `json:"error"`
}

ErrorResponse is the http response used on errors

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Facility

type Facility struct {
	ID       string   `json:"id"`
	Name     string   `json:"name,omitempty"`
	Code     string   `json:"code,omitempty"`
	Features []string `json:"features,omitempty"`
	Address  *Address `json:"address,omitempty"`
	URL      string   `json:"href,omitempty"`
}

Facility represents a Packet facility

func (Facility) String

func (f Facility) String() string

type FacilityService

type FacilityService interface {
	List() ([]Facility, *Response, error)
}

FacilityService interface defines available facility methods

type FacilityServiceOp

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

FacilityServiceOp implements FacilityService

func (*FacilityServiceOp) List

func (s *FacilityServiceOp) List() ([]Facility, *Response, error)

List returns all available Packet facilities

type Features

type Features struct {
	Raid bool `json:"raid,omitempty"`
	Txt  bool `json:"txt,omitempty"`
}

Features - other features in the specs for a plan

func (Features) String

func (f Features) String() string

type Href

type Href struct {
	Href string `json:"href"`
}

Href is an API link

type IPAddressAssignment

type IPAddressAssignment struct {
	AssignedTo Href `json:"assigned_to"`
	// contains filtered or unexported fields
}

IPAddressAssignment is created when an IP address from reservation block is assigned to a device.

func (IPAddressAssignment) String

func (i IPAddressAssignment) String() string

type IPAddressReservation

type IPAddressReservation struct {
	Assignments []Href   `json:"assignments"`
	Facility    Facility `json:"facility,omitempty"`
	Available   string   `json:"available"`
	Addon       bool     `json:"addon"`
	Bill        bool     `json:"bill"`
	// contains filtered or unexported fields
}

IPAddressReservation is created when user sends IP reservation request for a project (considering it's within quota).

func (IPAddressReservation) String

func (i IPAddressReservation) String() string

type IPReservationRequest

type IPReservationRequest struct {
	Type     string `json:"type"`
	Quantity int    `json:"quantity"`
	Comments string `json:"comments"`
	Facility string `json:"facility"`
}

IPReservationRequest represents the body of a reservation request.

type ListOptions

type ListOptions struct {
	// for paginated result sets, page of results to retrieve
	Page int `url:"page,omitempty"`

	// for paginated result sets, the number of results to return per page
	PerPage int `url:"per_page,omitempty"`

	// specify which resources you want to return as collections instead of references
	Includes string
}

ListOptions specifies optional global API parameters

type Memory

type Memory struct {
	Total string `json:"total,omitempty"`
}

Memory - the RAM config details for specs on a plan

func (Memory) String

func (m Memory) String() string

type NetworkType

type NetworkType int
const (
	NetworkL3 NetworkType = iota
	NetworkHybrid
	NetworkL2Bonded
	NetworkL2Individual
	NetworkUnknown
)

type Nics

type Nics struct {
	Count int    `json:"count,omitempty"`
	Type  string `json:"type,omitempty"`
}

Nics - the network hardware details for specs on a plan

func (Nics) String

func (n Nics) String() string

type OS

type OS struct {
	Name    string `json:"name"`
	Slug    string `json:"slug"`
	Distro  string `json:"distro"`
	Version string `json:"version"`
}

OS represents a Packet operating system

func (OS) String

func (o OS) String() string

type OSService

type OSService interface {
	List() ([]OS, *Response, error)
}

OSService interface defines available operating_systems methods

type OSServiceOp

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

OSServiceOp implements OSService

func (*OSServiceOp) List

func (s *OSServiceOp) List() ([]OS, *Response, error)

List returns all available operating systems

type Organization

type Organization struct {
	ID           string    `json:"id"`
	Name         string    `json:"name,omitempty"`
	Description  string    `json:"description,omitempty"`
	Website      string    `json:"website,omitempty"`
	Twitter      string    `json:"twitter,omitempty"`
	Created      string    `json:"created_at,omitempty"`
	Updated      string    `json:"updated_at,omitempty"`
	Address      Address   `json:"address,omitempty"`
	TaxID        string    `json:"tax_id,omitempty"`
	MainPhone    string    `json:"main_phone,omitempty"`
	BillingPhone string    `json:"billing_phone,omitempty"`
	CreditAmount float64   `json:"credit_amount,omitempty"`
	LogoThumb    string    `json:"logo_thumb,omitempty"`
	Projects     []Project `json:"projects,omitempty"`
	URL          string    `json:"href,omitempty"`
	Users        []User    `json:"members,omitempty"`
	Owners       []User    `json:"owners,omitempty"`
}

Organization represents a Packet organization

func (Organization) String

func (o Organization) String() string

type OrganizationCreateRequest

type OrganizationCreateRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Website     string `json:"website"`
	Twitter     string `json:"twitter"`
}

OrganizationCreateRequest type used to create a Packet organization

func (OrganizationCreateRequest) String

func (o OrganizationCreateRequest) String() string

type OrganizationService

type OrganizationService interface {
	List() ([]Organization, *Response, error)
	Get(string) (*Organization, *Response, error)
	Create(*OrganizationCreateRequest) (*Organization, *Response, error)
	Update(string, *OrganizationUpdateRequest) (*Organization, *Response, error)
	Delete(string) (*Response, error)
	ListPaymentMethods(string) ([]PaymentMethod, *Response, error)
}

OrganizationService interface defines available organization methods

type OrganizationServiceOp

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

OrganizationServiceOp implements OrganizationService

func (*OrganizationServiceOp) Create

Create creates a new organization

func (*OrganizationServiceOp) Delete

func (s *OrganizationServiceOp) Delete(organizationID string) (*Response, error)

Delete deletes an organizationID

func (*OrganizationServiceOp) Get

func (s *OrganizationServiceOp) Get(organizationID string) (*Organization, *Response, error)

Get returns a organization by id

func (*OrganizationServiceOp) List

List returns the user's organizations

func (*OrganizationServiceOp) ListPaymentMethods

func (s *OrganizationServiceOp) ListPaymentMethods(organizationID string) ([]PaymentMethod, *Response, error)

ListPaymentMethods returns PaymentMethods for an organization

func (*OrganizationServiceOp) Update

Update updates an organization

type OrganizationUpdateRequest

type OrganizationUpdateRequest struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
	Website     *string `json:"website,omitempty"`
	Twitter     *string `json:"twitter,omitempty"`
}

OrganizationUpdateRequest type used to update a Packet organization

func (OrganizationUpdateRequest) String

func (o OrganizationUpdateRequest) String() string

type PaymentMethod

type PaymentMethod struct {
	ID             string         `json:"id"`
	Name           string         `json:"name,omitempty"`
	Created        string         `json:"created_at,omitempty"`
	Updated        string         `json:"updated_at,omitempty"`
	Nonce          string         `json:"nonce,omitempty"`
	Default        bool           `json:"default,omitempty"`
	Organization   Organization   `json:"organization,omitempty"`
	Projects       []Project      `json:"projects,omitempty"`
	Type           string         `json:"type,omitempty"`
	CardholderName string         `json:"cardholder_name,omitempty"`
	ExpMonth       string         `json:"expiration_month,omitempty"`
	ExpYear        string         `json:"expiration_year,omitempty"`
	Last4          string         `json:"last_4,omitempty"`
	BillingAddress BillingAddress `json:"billing_address,omitempty"`
	URL            string         `json:"href,omitempty"`
}

PaymentMethod represents a Packet payment method of an organization

func (PaymentMethod) String

func (pm PaymentMethod) String() string

type PaymentMethodCreateRequest

type PaymentMethodCreateRequest struct {
	Name           string `json:"name"`
	Nonce          string `json:"name"`
	CardholderName string `json:"cardholder_name,omitempty"`
	ExpMonth       string `json:"expiration_month,omitempty"`
	ExpYear        string `json:"expiration_year,omitempty"`
	BillingAddress string `json:"billing_address,omitempty"`
}

PaymentMethodCreateRequest type used to create a Packet payment method of an organization

func (PaymentMethodCreateRequest) String

func (pm PaymentMethodCreateRequest) String() string

type PaymentMethodService

type PaymentMethodService interface {
	List() ([]PaymentMethod, *Response, error)
	Get(string) (*PaymentMethod, *Response, error)
	Create(*PaymentMethodCreateRequest) (*PaymentMethod, *Response, error)
	Update(string, *PaymentMethodUpdateRequest) (*PaymentMethod, *Response, error)
	Delete(string) (*Response, error)
}

ProjectService interface defines available project methods

type PaymentMethodServiceOp

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

PaymentMethodServiceOp implements PaymentMethodService

type PaymentMethodUpdateRequest

type PaymentMethodUpdateRequest struct {
	Name           *string `json:"name,omitempty"`
	CardholderName *string `json:"cardholder_name,omitempty"`
	ExpMonth       *string `json:"expiration_month,omitempty"`
	ExpYear        *string `json:"expiration_year,omitempty"`
	BillingAddress *string `json:"billing_address,omitempty"`
}

PaymentMethodUpdateRequest type used to update a Packet payment method of an organization

func (PaymentMethodUpdateRequest) String

func (pm PaymentMethodUpdateRequest) String() string

type Plan

type Plan struct {
	ID          string   `json:"id"`
	Slug        string   `json:"slug,omitempty"`
	Name        string   `json:"name,omitempty"`
	Description string   `json:"description,omitempty"`
	Line        string   `json:"line,omitempty"`
	Specs       *Specs   `json:"specs,omitempty"`
	Pricing     *Pricing `json:"pricing,omitempty"`
}

Plan represents a Packet service plan

func (Plan) String

func (p Plan) String() string

type PlanService

type PlanService interface {
	List() ([]Plan, *Response, error)
}

PlanService interface defines available plan methods

type PlanServiceOp

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

PlanServiceOp implements PlanService

func (*PlanServiceOp) List

func (s *PlanServiceOp) List() ([]Plan, *Response, error)

List method returns all available plans

type Port

type Port struct {
	ID                      string           `json:"id"`
	Type                    string           `json:"type"`
	Name                    string           `json:"name"`
	Data                    PortData         `json:"data"`
	AttachedVirtualNetworks []VirtualNetwork `json:"virtual_networks"`
}

type PortAssignRequest

type PortAssignRequest struct {
	PortID           string `json:"id"`
	VirtualNetworkID string `json:"vnid"`
}

type PortData

type PortData struct {
	MAC    string `json:"mac"`
	Bonded bool   `json:"bonded"`
}

type PriceMap

type PriceMap map[string]map[string]float64

PriceMap is a map of [facility][plan]-> float Price

type Pricing

type Pricing struct {
	Hourly  float32 `json:"hourly,omitempty"`
	Monthly float32 `json:"monthly,omitempty"`
}

Pricing - the pricing options on a plan

func (Pricing) String

func (p Pricing) String() string

type Project

type Project struct {
	ID            string        `json:"id"`
	Name          string        `json:"name,omitempty"`
	Organization  Organization  `json:"organization,omitempty"`
	Created       string        `json:"created_at,omitempty"`
	Updated       string        `json:"updated_at,omitempty"`
	Users         []User        `json:"members,omitempty"`
	Devices       []Device      `json:"devices,omitempty"`
	SSHKeys       []SSHKey      `json:"ssh_keys,omitempty"`
	URL           string        `json:"href,omitempty"`
	PaymentMethod PaymentMethod `json:"payment_method,omitempty"`
}

Project represents a Packet project

func (Project) String

func (p Project) String() string

type ProjectCreateRequest

type ProjectCreateRequest struct {
	Name            string `json:"name"`
	PaymentMethodID string `json:"payment_method_id,omitempty"`
	OrganizationID  string `json:"organization_id,omitempty"`
}

ProjectCreateRequest type used to create a Packet project

func (ProjectCreateRequest) String

func (p ProjectCreateRequest) String() string

type ProjectIPService

type ProjectIPService interface {
	Get(reservationID string) (*IPAddressReservation, *Response, error)
	List(projectID string) ([]IPAddressReservation, *Response, error)
	Request(projectID string, ipReservationReq *IPReservationRequest) (*IPAddressReservation, *Response, error)
	Remove(ipReservationID string) (*Response, error)
	AvailableAddresses(ipReservationID string, r *AvailableRequest) ([]string, *Response, error)
}

ProjectIPService handles reservation of IP address blocks for a project.

type ProjectIPServiceOp

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

ProjectIPServiceOp is interface for IP assignment methods.

func (*ProjectIPServiceOp) AvailableAddresses

func (i *ProjectIPServiceOp) AvailableAddresses(ipReservationID string, r *AvailableRequest) ([]string, *Response, error)

AvailableAddresses lists addresses available from a reserved block

func (*ProjectIPServiceOp) Get

func (i *ProjectIPServiceOp) Get(reservationID string) (*IPAddressReservation, *Response, error)

Get returns reservation by ID.

func (*ProjectIPServiceOp) List

func (i *ProjectIPServiceOp) List(projectID string) ([]IPAddressReservation, *Response, error)

List provides a list of IP resevations for a single project.

func (*ProjectIPServiceOp) Remove

func (i *ProjectIPServiceOp) Remove(ipReservationID string) (*Response, error)

Remove removes an IP reservation from the project.

func (*ProjectIPServiceOp) Request

func (i *ProjectIPServiceOp) Request(projectID string, ipReservationReq *IPReservationRequest) (*IPAddressReservation, *Response, error)

Request requests more IP space for a project in order to have additional IP addresses to assign to devices.

type ProjectService

type ProjectService interface {
	List() ([]Project, *Response, error)
	Get(string) (*Project, *Response, error)
	Create(*ProjectCreateRequest) (*Project, *Response, error)
	Update(string, *ProjectUpdateRequest) (*Project, *Response, error)
	Delete(string) (*Response, error)
}

ProjectService interface defines available project methods

type ProjectServiceOp

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

ProjectServiceOp implements ProjectService

func (*ProjectServiceOp) Create

func (s *ProjectServiceOp) Create(createRequest *ProjectCreateRequest) (*Project, *Response, error)

Create creates a new project

func (*ProjectServiceOp) Delete

func (s *ProjectServiceOp) Delete(projectID string) (*Response, error)

Delete deletes a project

func (*ProjectServiceOp) Get

func (s *ProjectServiceOp) Get(projectID string) (*Project, *Response, error)

Get returns a project by id

func (*ProjectServiceOp) List

func (s *ProjectServiceOp) List() ([]Project, *Response, error)

List returns the user's projects

func (*ProjectServiceOp) Update

func (s *ProjectServiceOp) Update(id string, updateRequest *ProjectUpdateRequest) (*Project, *Response, error)

Update updates a project

type ProjectUpdateRequest

type ProjectUpdateRequest struct {
	Name            *string `json:"name,omitempty"`
	PaymentMethodID *string `json:"payment_method_id,omitempty"`
}

ProjectUpdateRequest type used to update a Packet project

func (ProjectUpdateRequest) String

func (p ProjectUpdateRequest) String() string

type ProjectVirtualNetworkService

type ProjectVirtualNetworkService interface {
	List(projectID string) (*VirtualNetworkListResponse, *Response, error)
	Create(*VirtualNetworkCreateRequest) (*VirtualNetwork, *Response, error)
	Delete(virtualNetworkID string) (*Response, error)
}

DevicePortService handles operations on a port which belongs to a particular device

type ProjectVirtualNetworkServiceOp

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

func (*ProjectVirtualNetworkServiceOp) Create

func (*ProjectVirtualNetworkServiceOp) Delete

func (i *ProjectVirtualNetworkServiceOp) Delete(virtualNetworkID string) (*Response, error)

func (*ProjectVirtualNetworkServiceOp) List

type ProvisionEvent

type ProvisionEvent struct {
	ID            string     `json:"id"`
	Body          string     `json:"body"`
	CreatedAt     *Timestamp `json:"created_at,omitempty"`
	Href          string     `json:"href"`
	Interpolated  string     `json:"interpolated"`
	Relationships []Href     `json:"relationships"`
	State         string     `json:"state"`
	Type          string     `json:"type"`
}

type Rate

type Rate struct {
	RequestLimit      int       `json:"request_limit"`
	RequestsRemaining int       `json:"requests_remaining"`
	Reset             Timestamp `json:"rate_reset"`
}

Rate provides the API request rate limit details

func (Rate) String

func (r Rate) String() string

type Response

type Response struct {
	*http.Response
	Rate
}

Response is the http response from api calls

type SSHKey

type SSHKey struct {
	ID          string `json:"id"`
	Label       string `json:"label"`
	Key         string `json:"key"`
	FingerPrint string `json:"fingerprint"`
	Created     string `json:"created_at"`
	Updated     string `json:"updated_at"`
	User        User   `json:"user,omitempty"`
	URL         string `json:"href,omitempty"`
}

SSHKey represents a user's ssh key

func (SSHKey) String

func (s SSHKey) String() string

type SSHKeyCreateRequest

type SSHKeyCreateRequest struct {
	Label     string `json:"label"`
	Key       string `json:"key"`
	ProjectID string `json:"-"`
}

SSHKeyCreateRequest type used to create an ssh key

func (SSHKeyCreateRequest) String

func (s SSHKeyCreateRequest) String() string

type SSHKeyService

type SSHKeyService interface {
	List() ([]SSHKey, *Response, error)
	ProjectList(string) ([]SSHKey, *Response, error)
	Get(string) (*SSHKey, *Response, error)
	Create(*SSHKeyCreateRequest) (*SSHKey, *Response, error)
	Update(string, *SSHKeyUpdateRequest) (*SSHKey, *Response, error)
	Delete(string) (*Response, error)
}

SSHKeyService interface defines available device methods

type SSHKeyServiceOp

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

SSHKeyServiceOp implements SSHKeyService

func (*SSHKeyServiceOp) Create

func (s *SSHKeyServiceOp) Create(createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error)

Create creates a new ssh key

func (*SSHKeyServiceOp) Delete

func (s *SSHKeyServiceOp) Delete(sshKeyID string) (*Response, error)

Delete deletes an ssh key

func (*SSHKeyServiceOp) Get

func (s *SSHKeyServiceOp) Get(sshKeyID string) (*SSHKey, *Response, error)

Get returns an ssh key by id

func (*SSHKeyServiceOp) List

func (s *SSHKeyServiceOp) List() ([]SSHKey, *Response, error)

List returns a user's ssh keys

func (*SSHKeyServiceOp) ProjectList

func (s *SSHKeyServiceOp) ProjectList(projectID string) ([]SSHKey, *Response, error)

ProjectList lists ssh keys of a project

func (*SSHKeyServiceOp) Update

func (s *SSHKeyServiceOp) Update(id string, updateRequest *SSHKeyUpdateRequest) (*SSHKey, *Response, error)

Update updates an ssh key

type SSHKeyUpdateRequest

type SSHKeyUpdateRequest struct {
	Label *string `json:"label,omitempty"`
	Key   *string `json:"key,omitempty"`
}

SSHKeyUpdateRequest type used to update an ssh key

func (SSHKeyUpdateRequest) String

func (s SSHKeyUpdateRequest) String() string

type SnapshotPolicy

type SnapshotPolicy struct {
	ID                string `json:"id"`
	Href              string `json:"href"`
	SnapshotFrequency string `json:"snapshot_frequency,omitempty"`
	SnapshotCount     int    `json:"snapshot_count,omitempty"`
}

SnapshotPolicy used to execute actions on volume

type Specs

type Specs struct {
	Cpus     []*Cpus   `json:"cpus,omitempty"`
	Memory   *Memory   `json:"memory,omitempty"`
	Drives   []*Drives `json:"drives,omitempty"`
	Nics     []*Nics   `json:"nics,omitempty"`
	Features *Features `json:"features,omitempty"`
}

Specs - the server specs for a plan

func (Specs) String

func (s Specs) String() string

type SpotMarketService

type SpotMarketService interface {
	Prices() (PriceMap, *Response, error)
}

SpotMarketService expooses Spot Market methods

type SpotMarketServiceOp

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

SpotMarketServiceOp implements SpotMarketService

func (*SpotMarketServiceOp) Prices

func (s *SpotMarketServiceOp) Prices() (PriceMap, *Response, error)

Prices gets current PriceMap from the API

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type User

type User struct {
	ID                    string  `json:"id"`
	FirstName             string  `json:"first_name,omitempty"`
	LastName              string  `json:"last_name,omitempty"`
	FullName              string  `json:"full_name,omitempty"`
	Email                 string  `json:"email,omitempty"`
	TwoFactor             string  `json:"two_factor_auth,omitempty"`
	DefaultOrganizationID string  `json:"default_organization_id,omitempty"`
	AvatarURL             string  `json:"avatar_url,omitempty"`
	Facebook              string  `json:"twitter,omitempty"`
	Twitter               string  `json:"facebook,omitempty"`
	LinkedIn              string  `json:"linkedin,omitempty"`
	Created               string  `json:"created_at,omitempty"`
	Updated               string  `json:"updated_at,omitempty"`
	TimeZone              string  `json:"timezone,omitempty"`
	Emails                []Email `json:"emails,omitempty"`
	PhoneNumber           string  `json:"phone_number,omitempty"`
	URL                   string  `json:"href,omitempty"`
}

User represents a Packet user

func (User) String

func (u User) String() string

type UserService

type UserService interface {
	Get(string) (*User, *Response, error)
	Current() (*User, *Response, error)
}

UserService interface defines available user methods

type UserServiceOp

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

UserServiceOp implements UserService

func (*UserServiceOp) Current

func (s *UserServiceOp) Current() (*User, *Response, error)

Returns the user object for the currently logged-in user.

func (*UserServiceOp) Get

func (s *UserServiceOp) Get(userID string) (*User, *Response, error)

Get method gets a user by userID

type VirtualNetwork

type VirtualNetwork struct {
	ID           string `json:"id"`
	Description  string `json:"description,omitempty"`
	VXLAN        int    `json:"vxlan,omitempty"`
	FacilityCode string `json:"facility_code,omitempty"`
	CreatedAt    string `json:"created_at,omitempty"`
	Href         string `json:"href"`
}

type VirtualNetworkCreateRequest

type VirtualNetworkCreateRequest struct {
	ProjectID   string `json:"project_id"`
	Description string `json:"description"`
	Facility    string `json:"facility"`
	VXLAN       int    `json:"vxlan"`
	VLAN        int    `json:"vlan"`
}

type VirtualNetworkCreateResponse

type VirtualNetworkCreateResponse struct {
	VirtualNetwork VirtualNetwork `json:"virtual_networks"`
}

type VirtualNetworkListResponse

type VirtualNetworkListResponse struct {
	VirtualNetworks []VirtualNetwork `json:"virtual_networks"`
}

type Volume

type Volume struct {
	Attachments      []*VolumeAttachment `json:"attachments,omitempty"`
	BillingCycle     string              `json:"billing_cycle,omitempty"`
	Created          string              `json:"created_at,omitempty"`
	Description      string              `json:"description,omitempty"`
	Facility         *Facility           `json:"facility,omitempty"`
	Href             string              `json:"href,omitempty"`
	ID               string              `json:"id"`
	Locked           bool                `json:"locked,omitempty"`
	Name             string              `json:"name,omitempty"`
	Plan             *Plan               `json:"plan,omitempty"`
	Project          *Project            `json:"project,omitempty"`
	Size             int                 `json:"size,omitempty"`
	SnapshotPolicies []*SnapshotPolicy   `json:"snapshot_policies,omitempty"`
	State            string              `json:"state,omitempty"`
	Updated          string              `json:"updated_at,omitempty"`
}

Volume represents a volume

func (Volume) String

func (v Volume) String() string

type VolumeAttachment

type VolumeAttachment struct {
	Href   string `json:"href"`
	ID     string `json:"id"`
	Volume Volume `json:"volume"`
	Device Device `json:"device"`
}

VolumeAttachment is a type from Packet API

type VolumeAttachmentService

type VolumeAttachmentService interface {
	Get(string) (*VolumeAttachment, *Response, error)
	Create(string, string) (*VolumeAttachment, *Response, error)
	Delete(string) (*Response, error)
}

VolumeAttachmentService defines attachment methdods

type VolumeAttachmentServiceOp

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

VolumeAttachmentServiceOp implements VolumeService

func (*VolumeAttachmentServiceOp) Create

func (v *VolumeAttachmentServiceOp) Create(volumeID, deviceID string) (*VolumeAttachment, *Response, error)

Create Attachment, i.e. attach volume to a device

func (*VolumeAttachmentServiceOp) Delete

func (v *VolumeAttachmentServiceOp) Delete(attachmentID string) (*Response, error)

Delete deletes attachment by id

func (*VolumeAttachmentServiceOp) Get

func (v *VolumeAttachmentServiceOp) Get(attachmentID string) (*VolumeAttachment, *Response, error)

Get gets attachment by id

type VolumeCreateRequest

type VolumeCreateRequest struct {
	BillingCycle     string            `json:"billing_cycle"`
	Description      string            `json:"description,omitempty"`
	Locked           bool              `json:"locked,omitempty"`
	Size             int               `json:"size"`
	PlanID           string            `json:"plan_id"`
	FacilityID       string            `json:"facility_id"`
	SnapshotPolicies []*SnapshotPolicy `json:"snapshot_policies,omitempty"`
}

VolumeCreateRequest type used to create a Packet volume

func (VolumeCreateRequest) String

func (v VolumeCreateRequest) String() string

type VolumeService

type VolumeService interface {
	List(string, *ListOptions) ([]Volume, *Response, error)
	Get(string) (*Volume, *Response, error)
	Update(string, *VolumeUpdateRequest) (*Volume, *Response, error)
	Delete(string) (*Response, error)
	Create(*VolumeCreateRequest, string) (*Volume, *Response, error)
	Lock(string) (*Response, error)
	Unlock(string) (*Response, error)
}

VolumeService interface defines available Volume methods

type VolumeServiceOp

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

VolumeServiceOp implements VolumeService

func (*VolumeServiceOp) Create

func (v *VolumeServiceOp) Create(createRequest *VolumeCreateRequest, projectID string) (*Volume, *Response, error)

Create creates a new volume for a project

func (*VolumeServiceOp) Delete

func (v *VolumeServiceOp) Delete(volumeID string) (*Response, error)

Delete deletes a volume

func (*VolumeServiceOp) Get

func (v *VolumeServiceOp) Get(volumeID string) (*Volume, *Response, error)

Get returns a volume by id

func (*VolumeServiceOp) List

func (v *VolumeServiceOp) List(projectID string, listOpt *ListOptions) (volumes []Volume, resp *Response, err error)

List returns the volumes for a project

func (*VolumeServiceOp) Lock

func (s *VolumeServiceOp) Lock(id string) (*Response, error)

Lock sets a volume to "locked"

func (*VolumeServiceOp) Unlock

func (s *VolumeServiceOp) Unlock(id string) (*Response, error)

Unlock sets a volume to "unlocked"

func (*VolumeServiceOp) Update

func (v *VolumeServiceOp) Update(id string, updateRequest *VolumeUpdateRequest) (*Volume, *Response, error)

Update updates a volume

type VolumeUpdateRequest

type VolumeUpdateRequest struct {
	Description  *string `json:"description,omitempty"`
	PlanID       *string `json:"plan_id,omitempty"`
	Size         *int    `json:"size,omitempty"`
	BillingCycle *string `json:"billing_cycle,omitempty"`
}

VolumeUpdateRequest type used to update a Packet volume

func (VolumeUpdateRequest) String

func (v VolumeUpdateRequest) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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