paperspace

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

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

Go to latest
Published: Dec 11, 2018 License: MIT Imports: 10 Imported by: 0

README ¶

go-paperspace

GoDoc

go-paperspace is a Go client library for accessing the Paperspace API.

Usage

import "github.com/timdurward/go-paperspace"

Construct a new Paperspace client, then use the various services on the client to access different parts of the Paperspace API. For example:

config := &paperspace.Config{
  APIKey: "<API KEY>",
}

// Default http.Client
client, _ := paperspace.NewClient(config, nil)

// Create Machine
// https://paperspace.github.io/paperspace-node/machines.html#.create
m := &paperspace.MachinesRequest{
  Region:      "West Coast (CA1)",
  MachineType: "Air",
  Size:        50,
  BillingType: "monthly",
  MachineName: "Provisioned using Go API client.",
  TemplateID:  "<template_id>",
}
  
machine, _, err := client.Machines.Create(m)

🔨 WIP 🔧

Client v1 Coverage
  • Base Paperspace Client
  • Machines Service
  • Networks Service
  • Scripts Service
  • Templates Service
  • Jobs Service
  • Tests
  • Versioning

Contributing

Feel free to submit a Github issue in regards to questions.

If you submit a pull request, please keep the following guidelines in mind:

  1. Code should be go fmt compliant.
  2. Types, structs and funcs should be documented.

Getting set up

Assuming your $GOPATH is set up according to your desires, run:

go get github.com/timdurward/go-paperspace

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func CheckResponse ¶

func CheckResponse(r *http.Response) error

CheckResponse checks the Paperpspace API response for a non-2xx status code.

Types ¶

type Client ¶

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// UserAgent for client.
	UserAgent string

	// Config for client.
	Config *Config

	// Services used for talking to different parts of the Paperspace API.
	Scripts  *ScriptsService
	Machines *MachinesService
	Networks *NetworksService
	// contains filtered or unexported fields
}

Client manages communication with Paperspace API.

func NewClient ¶

func NewClient(config *Config, httpClient *http.Client) (*Client, error)

NewClient returns a new Paperspace API client.

func (*Client) Do ¶

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

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest ¶

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

NewRequest creates a new Paperspace API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. If specified, the value pointed to by body is JSON encoded and included as the request body.

type Config ¶

type Config struct {
	// API Key for client authorization.
	APIKey string
}

Config manages Authorization with Paperspace API.

type ErrorResponse ¶

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"message"`
}

ErrorResponse reports the error caused by an API request.

type Events ¶

type Events struct {
	Name       string `json:"name,omitempty"`
	State      string `json:"state,omitempty"`
	ErrorMsg   string `json:"errorMsg,omitempty"`
	Handle     string `json:"handle,omitempty"`
	DtModified string `json:"dtModified,omitempty"`
	DtFinished string `json:"dtFinished,omitempty"`
	DtCreated  string `json:"dtCreated,omitempty"`
}

Events represents a Paperspace machine event.

type MachineOptions ¶

type MachineOptions struct {
	MachineID   string `url:"machineId,omitempty"`
	Region      string `url:"region,omitempty"`
	MachineType string `url:"machineType,omitempty"`
}

MachineOptions specifies the optional parameters to the MachinesService.Availability & MachinesService.Show methods.

type Machines ¶

type Machines struct {
	ID                     string `json:"id,omitempty"`
	MachineID              string `json:"machineId,omityempty"`
	Name                   string `json:"name,omitempty"`
	OS                     string `json:"os,omitempty"`
	RAM                    string `json:"ram,omitempty"`
	GPU                    string `json:"gpu,omitempty"`
	Cpus                   int    `json:"cpus,omitempty"`
	StorageTotal           string `json:"storageTotal,omitempty"`
	StorageUsed            string `json:"storageUsed,omitempty"`
	UsageRate              string `json:"usageRate,omitempty"`
	ShutdownTimeoutInHours int    `json:"shutdownTimeoutInHours,omitempty"`
	ShutdownTimeoutForces  bool   `json:"shutdownTimeoutForces,omitempty"`
	PerformAutoSnapshot    bool   `json:"performAutoSnapshot,omitempty"`
	AutoSnapshotFrequency  int    `json:"autoSnapshotFrequency,omitempty"`
	AutoSnapshotSaveCount  int    `json:"autoSnapshotSaveCount,omitempty"`
	AgentType              string `json:"agentType,omitempty"`
	State                  string `json:"state,omitempty"`
	UpdatesPending         bool   `json:"updatesPending,omitempty"`
	NetworkID              string `json:"networkId,omitempty"`
	PrivateIPAddress       string `json:"privateIpAddress,omitempty"`
	PublicIPAddress        string `json:"publicIpAddress,omitempty"`
	DynamicPublicIP        bool   `json:"dynamicPublicIp,omitempty"`
	Region                 string `json:"region,omitempty"`
	UserID                 string `json:"userId,omitempty"`
	TeamID                 string `json:"teamId,omitempty"`
	ScriptID               string `json:"scriptId,omitempty"`
	DtCreated              string `json:"dtCreated,omitempty"`
	DtLastRun              string `json:"dtLastRun,omitempty"`
	Available              bool   `json:"available,omitempty"`
	Events                 []Events
}

Machines represents a Paperspace Machine.

type MachinesRequest ¶

type MachinesRequest struct {
	Region            string `json:"region,omitempty"`
	MachineType       string `json:"machineType,omitempty"`
	Size              int    `json:"size,omitempty"`
	BillingType       string `json:"billingType,omitempty"`
	MachineName       string `json:"machineName,omitempty"`
	TemplateID        string `json:"templateId,omitempty"`
	AssignPublicID    bool   `json:"assignPublicIp,omitempty"`
	DynamicPublicID   bool   `json:"dynamicPublicIp,omitempty"`
	NetworkID         string `json:"networkId,omitempty"`
	TeamID            string `json:"teamId,omitempty"`
	UserID            string `json:"userId,omitempty"`
	Email             string `json:"email,omitempty"`
	Password          string `json:"password,omitempty"`
	FirstName         string `json:"firstName,omitempty"`
	LastName          string `json:"lastName,omitempty"`
	NotificationEmail string `json:"notificationEmail,omitempty"`
	ScriptID          string `json:"scriptId,omitempty"`
}

MachinesRequest represents a request to create a Paperspace Machine.

type MachinesService ¶

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

MachinesService manages Machines for the Paperspace API. Paperspace API docs: https://paperspace.github.io/paperspace-node/machines.html

func (*MachinesService) Availability ¶

func (s *MachinesService) Availability(opt *MachineOptions) (*Machines, *Response, error)

Availability gets machine availability for the given region and machine type. https://paperspace.github.io/paperspace-node/machines.html#.availability

func (*MachinesService) Create ¶

func (s *MachinesService) Create(mr *MachinesRequest) (*Machines, *Response, error)

Create creates new a virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.create

func (*MachinesService) Destroy ¶

func (s *MachinesService) Destroy(machineID string) (*Response, error)

Destroy destroys an existing virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.destroy

func (*MachinesService) List ¶

func (s *MachinesService) List() ([]*Machines, *Response, error)

List lists information about all machines available to the authenticated user or team. https://paperspace.github.io/paperspace-node/machines.html#.list

func (*MachinesService) Restart ¶

func (s *MachinesService) Restart(machineID string) (*Response, error)

Restart restarts an existing virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.restart

func (*MachinesService) Show ¶

Show shows machine information. https://paperspace.github.io/paperspace-node/machines.html#.show

func (*MachinesService) Start ¶

func (s *MachinesService) Start(machineID string) (*Response, error)

Start starts an existing virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.start

func (*MachinesService) Stop ¶

func (s *MachinesService) Stop(machineID string) (*Response, error)

Stop stops an existing virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.stop

func (*MachinesService) Update ¶

func (s *MachinesService) Update(m *Machines) (*Response, error)

Update updates attributes of a virtual machine. https://paperspace.github.io/paperspace-node/machines.html#.update

type Network ¶

type Network struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Region    string    `json:"region"`
	DtCreated time.Time `json:"dtCreated"`
	Network   string    `json:"network"`
	Netmask   string    `json:"netmask"`
	TeamID    string    `json:"teamId"`
}

Network represents a Paperspace Network.

type NetworksService ¶

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

NetworksService manages Networks for the Paperspace API. https://paperspace.github.io/paperspace-node/networks.html

func (*NetworksService) List ¶

func (s *NetworksService) List() ([]*Network, *Response, error)

List lists information about all machines available to the authenticated user or team. https://paperspace.github.io/paperspace-node/machines.html#.list

type Response ¶

type Response struct {
	*http.Response
}

Response is a Paperspace response. This wraps the standard http.Response returned from Paperspace.

type Scripts ¶

type Scripts struct {
	ID          string    `json:"id,omitempty"`
	Name        string    `json:"name,omitempty"`
	OwnerType   string    `json:"ownerType,omitempty"`
	OwnerID     string    `json:"ownerId,omitempty"`
	Description string    `json:"description,omitempty"`
	DtCreated   time.Time `json:"dtCreated,omitempty"`
	IsEnabled   bool      `json:"isEnabled,omitempty"`
	RunOnce     bool      `json:"runOnce,omitempty"`
}

Scripts represents a Paperspace Script.

type ScriptsRequest ¶

type ScriptsRequest struct {
	MachineID         string `json:"machineId,omitempty"`
	ScriptName        string `json:"scriptName,omitempty"`
	ScriptFile        string `json:"scriptFile,omitempty"`
	ScriptText        string `json:"scriptText,omitempty"`
	ScriptDescription string `json:"scriptDescription,omitempty"`
	IsEnabled         bool   `json:"isEnabled,omitempty"`
	RunOnce           bool   `json:"runOnce,omitempty"`
}

ScriptsRequest represents a request to create a Paperspace Script.

type ScriptsService ¶

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

ScriptsService manages Scripts for the Paperspace API. Paperspace API docs: https://paperspace.github.io/paperspace-node/scripts.html

func (*ScriptsService) Create ¶

func (s *ScriptsService) Create(options *ScriptsRequest) (*Scripts, *Response, error)

Create creates a new Paperspace Script based on given parameters. https://paperspace.github.io/paperspace-node/scripts.html#.create

func (*ScriptsService) List ¶

func (s *ScriptsService) List() (*Scripts, *Response, error)

List lists all scripts from Paperspace. https://paperspace.github.io/paperspace-node/scripts.html#.list

Jump to

Keyboard shortcuts

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