paperspace

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Off          = "off"
	Starting     = "starting"
	Stopping     = "stopping"
	Restarting   = "restarting"
	ServiceReady = "serviceReady"
	Ready        = "ready"
	Upgrading    = "upgrading"
	Provisioning = "provisioning"
)

MachineState represents the state of a Paperspace machine

Variables

View Source
var DefaultBaseURL = "https://api.paperspace.io"

Functions

func Create

func Create(paperspaceProvider *PaperspaceProvider) error

func Delete

func Delete(paperspaceProvider *PaperspaceProvider) error

func GetPrivateKey added in v0.0.15

func GetPrivateKey(paperspaceProvider *PaperspaceProvider) (string, error)

GetPublicKey returns the public key of the Paperspace provider

func GetPrivateKeyBase added in v0.0.15

func GetPrivateKeyBase(paperspaceProvider *PaperspaceProvider) ([]byte, error)

GetPrivateKeyBase returns the private key of the Paperspace provider in a byte slice

func GetPublicKey added in v0.0.15

func GetPublicKey(paperspaceProvider *PaperspaceProvider) (string, error)

GetPublicKey returns the public key of the Paperspace provider

func GetPublicKeyBase added in v0.0.15

func GetPublicKeyBase(paperspaceProvider *PaperspaceProvider) (string, error)

GetPublicKeyBase returns the public key of the Paperspace provider in Base64 string

func Init

func Init(paperspaceProvider *PaperspaceProvider) error

func Start

func Start(paperspaceProvider *PaperspaceProvider) error

func Status

func Status(paperspaceProvider *PaperspaceProvider) (client.Status, error)

func Stop

func Stop(paperspaceProvider *PaperspaceProvider) error

Types

type APIBackend

type APIBackend struct {
	BaseURL    string
	Debug      bool
	DebugBody  bool
	HTTPClient *http.Client
	RetryCount int
}

func NewAPIBackend

func NewAPIBackend() *APIBackend

func (*APIBackend) Request

func (c *APIBackend) Request(method string, url string,
	params, result interface{}, requestParams RequestParams) (res *http.Response, err error)

type Backend

type Backend interface {
	Request(method string, url string, params, result interface{}, requestParams RequestParams) (*http.Response, error)
}

type Client

type Client struct {
	APIKey  string
	Backend Backend
}

func NewClient

func NewClient(apiKey string) *Client

client that makes requests to Gradient API

func NewClientWithBackend

func NewClientWithBackend(apiKey string, backend Backend) *Client

func (Client) CreateMachine

func (c Client) CreateMachine(params CreateMachineParams) (Machine, error)

CreateMachine creates a machine

func (Client) CreateScript added in v0.0.15

func (c Client) CreateScript(params CreateScriptParams) (Script, error)

CreateScript creates a script

func (Client) DestroyMachine

func (c Client) DestroyMachine(params DestroyMachineParams) (Machine, error)

DestroyMachine destroys a machine

func (Client) DestroyScript added in v0.0.15

func (c Client) DestroyScript(params DestroyScriptParams) (Script, error)

DestroyScript destroys a script

func (Client) GetMachine

func (c Client) GetMachine(params GetMachineParams) (GetMachineResponse, error)

CreateMachine creates a machine

func (Client) GetMachines

func (c Client) GetMachines(params GetMachinesParams) ([]Machine, error)

GetMachines gets a list of machines

func (*Client) Request

func (c *Client) Request(method string, url string, params, result interface{}, requestParams RequestParams) (*http.Response, error)

func (Client) RestartMachine

func (c Client) RestartMachine(params RestartMachineParams) (Machine, error)

RestartMachine restarts a machine

func (Client) StartMachine

func (c Client) StartMachine(params StartMachineParams) (Machine, error)

StartMachine starts a machine

func (Client) StopMachine

func (c Client) StopMachine(params StopMachineParams) (Machine, error)

StopMachine stops a machine

func (Client) UpdateMachine

func (c Client) UpdateMachine(params UpdateMachineParams) (Machine, error)

UpdateMachine updates a machine

type CreateMachineParams

type CreateMachineParams struct {
	RequestParams
	MachineName           string `json:"machineName"` // required
	MachineType           string `json:"machineType"` // required
	TemplateID            string `json:"templateId"`  // required
	Region                string `json:"region"`      // required
	Size                  int    `json:"size"`        // required
	BillingType           string `json:"billingType"` // required
	NetworkId             string `json:"networkId,omitempty"`
	AssignPublicIP        bool   `json:"assignPublicIp,omitempty"`
	DynamicPublicIP       bool   `json:"dynamicPublicIp,omitempty"`
	StartOnCreate         bool   `json:"startOnCreate,omitempty"`
	StartupScriptId       string `json:"startupScriptId,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"`
	TakeInitialSnapshot   bool   `json:"takeInitialSnapshot,omitempty"`
	RestorePointEnabled   bool   `json:"restorePointEnabled,omitempty"`
	RestorePointFrequency string `json:"restorePointFrequency,omitempty"`
	EnableNvlink          bool   `json:"enableNvlink,omitempty"`
}

CreateMachineParams represents the parameters for CreateMachine method

type CreateScriptParams added in v0.0.15

type CreateScriptParams struct {
	RequestParams
	ScriptName        string `json:"scriptName"`
	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"`
	MachineID         string `json:"machineId,omitempty"`
}

CreateScriptParams are the parameters for creating a script

type DestroyMachineParams

type DestroyMachineParams struct {
	RequestParams
	MachineID       string `json:"machineId"` // required
	ReleasePublicIP bool   `json:"releasePublicIp,omitempty"`
}

DestroyMachineParams represents the parameters for StopMachine method

type DestroyScriptParams added in v0.0.15

type DestroyScriptParams struct {
	RequestParams
	ScriptID string `json:"machineId,omitempty"`
}

DestroyScriptParams are the parameters for destroying a script

type Event

type Event struct {
	Name       string    `json:"name"`
	State      string    `json:"state"`
	ErrorMsg   string    `json:"errorMsg"`
	Handle     string    `json:"handle"`
	DtModified time.Time `json:"dtModified"`
	DtFinished time.Time `json:"dtFinished"`
	DtCreated  time.Time `json:"dtCreated"`
}

type GetMachineParams

type GetMachineParams struct {
	RequestParams
	MachineID string `json:"machineId" url:"machineId"` // required
}

GetMachineParams represents the parameters for GetMachine method

type GetMachineResponse

type GetMachineResponse struct {
	ID                     string    `json:"id"`
	Name                   string    `json:"name"`
	OS                     string    `json:"os"`
	RAM                    int64     `json:"ram,string"`
	CPUs                   int       `json:"cpus"`
	GPU                    string    `json:"gpu"`
	StorageTotal           int64     `json:"storageTotal,string"`
	StorageUsed            int64     `json:"storageUsed,string"`
	MachineType            string    `json:"machineType"`
	UsageRate              string    `json:"usageRate"`
	ShutdownTimeoutInHours int       `json:"shutdownTimeoutInHours"`
	ShutdownTimeoutForces  bool      `json:"shutdownTimeoutForces"`
	PerformAutoSnapshot    bool      `json:"performAutoSnapshot"`
	AutoSnapshotFrequency  string    `json:"autoSnapshotFrequency"`
	AutoSnapshotSaveCount  int       `json:"autoSnapshotSaveCount"`
	DynamicPublicIP        bool      `json:"dynamicPublicIp"`
	AgentType              string    `json:"agentType"`
	DtCreated              time.Time `json:"dtCreated"`
	State                  string    `json:"state"`
	UpdatesPending         bool      `json:"updatesPending"`
	NetworkID              string    `json:"networkId"`
	PrivateIPAddress       string    `json:"privateIpAddress"`
	PublicIPAddress        string    `json:"publicIpAddress"`
	Region                 string    `json:"region"`
	ScriptID               string    `json:"scriptId"`               // pointer to handle null value
	DtLastRun              time.Time `json:"dtLastRun"`              // pointer to handle null value
	RestorePointSnapshotID string    `json:"restorePointSnapshotId"` // pointer to handle null value
	RestorePointFrequency  string    `json:"restorePointFrequency"`  // pointer to handle null value
	Events                 []Event   `json:"events"`                 // slice of Event structs
}

func GetDevpodInstance

func GetDevpodInstance(paperspaceProvider *PaperspaceProvider) (*GetMachineResponse, error)

type GetMachinesParams

type GetMachinesParams struct {
	RequestParams
	Limit                  string `json:"limit,omitempty" url:"limit,omitempty"`
	Skip                   string `json:"skip,omitempty" url:"skip,omitempty"`
	MachineID              string `json:"machineId,omitempty" url:"machineId,omitempty"`
	Name                   string `json:"name,omitempty" url:"name,omitempty"`
	OS                     string `json:"os,omitempty" url:"os,omitempty"`
	RAM                    string `json:"ram,omitempty" url:"ram,omitempty"`
	CPUs                   int    `json:"cpu,omitempty" url:"cpu,omitempty"`
	GPU                    string `json:"gpu,omitempty" url:"gpu,omitempty"`
	StorageTotal           string `json:"storageTotal,omitempty" url:"storageTotal,omitempty"`
	StorageUsed            string `json:"storageUsed,omitempty" url:"storageUsed,omitempty"`
	UsageRate              string `json:"usageRate,omitempty" url:"usageRate,omitempty"`
	ShutdownTimeoutInHours int    `json:"shutdownTimeoutInHours,omitempty" url:"shutdownTimeoutInHours,omitempty"`
	PerformAutoSnapshot    bool   `json:"performAutoSnapshot,omitempty" url:"performAutoSnapshot,omitempty"`
	AutoSnapshotFrequency  string `json:"autoSnapshotFrequency,omitempty" url:"autoSnapshotFrequency,omitempty"`
	AutoSnapshotSaveCount  int    `json:"autoSnapshotSaveCount,omitempty" url:"autoSnapshotSaveCount,omitempty"`
	AgentType              string `json:"agentType,omitempty" url:"agentType,omitempty"`
	DtCreated              string `json:"dtCreated,omitempty" url:"dtCreated,omitempty"`
	State                  string `json:"state,omitempty" url:"state,omitempty"`
	UpdatesPending         string `json:"updatesPending,omitempty" url:"updatesPending,omitempty"`
	NetworkID              string `json:"networkId,omitempty" url:"networkId,omitempty"`
	PrivateIPAddress       string `json:"privateIpAddress,omitempty" url:"privateIpAddress,omitempty"`
	PublicIPAddress        string `json:"publicIpAddress,omitempty" url:"publicIpAddress,omitempty"`
	Region                 string `json:"region,omitempty" url:"region,omitempty"`
	UserID                 string `json:"userId,omitempty" url:"userId,omitempty"`
	TeamID                 string `json:"teamId,omitempty" url:"teamId,omitempty"`
	ScriptID               string `json:"scriptId,omitempty" url:"scriptId,omitempty"`
	DtLastRun              string `json:"dtLastRun,omitempty" url:"dtLastRun,omitempty"`
}

ListMachinesParams represents the parameters object for ListMachines method

type Machine

type Machine struct {
	ID                     string `json:"id"`
	Name                   string `json:"name"`
	OS                     string `json:"os"`
	RAM                    string `json:"ram"`
	CPUs                   int    `json:"cpus"`
	GPU                    string `json:"gpu"`
	StorageTotal           string `json:"storageTotal"`
	StorageUsed            string `json:"storageUsed"`
	MachineType            string `json:"machineType"`
	UsageRate              string `json:"usageRate"`
	ShutdownTimeoutInHours int    `json:"shutdownTimeoutInHours"`
	ShutdownTimeoutForces  bool   `json:"shutdownTimeoutForces"`
	PerformAutoSnapshot    bool   `json:"performAutoSnapshot"`
	AutoSnapshotFrequency  string `json:"autoSnapshotFrequency"`
	AutoSnapshotSaveCount  int    `json:"autoSnapshotSaveCount"`
	DynamicPublicIP        bool   `json:"dynamicPublicIp"`
	AgentType              string `json:"agentType"`
	DtCreated              string `json:"dtCreated"`
	State                  string `json:"state"`
	UpdatesPending         bool   `json:"updatesPending"`
	NetworkID              string `json:"networkId"`
	PrivateIPAddress       string `json:"privateIpAddress"`
	PublicIPAddress        string `json:"publicIpAddress"`
	Region                 string `json:"region"`
	ScriptID               string `json:"scriptId"`
	DtLastRun              string `json:"dtLastRun"`
	RestorePointSnapshotID string `json:"restorePointSnapshotId"`
	RestorePointFrequency  string `json:"restorePointFrequency"`
	InternalID             int    `json:"internalId"`
}

Machine represents a Paperspace machine

type PaperspaceError

type PaperspaceError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Status  int    `json:"status"`
}

func (PaperspaceError) Error

func (e PaperspaceError) Error() string

type PaperspaceErrorResponse

type PaperspaceErrorResponse struct {
	Error *PaperspaceError `json:"error"`
}

type PaperspaceProvider

type PaperspaceProvider struct {
	Config *options.Options
	Client *Client
}

func NewProvider

func NewProvider(logs log.Logger, init bool) (*PaperspaceProvider, error)

type RequestParams

type RequestParams struct {
	Context context.Context   `json:"-,omitempty" url:"-,omitempty"`
	Headers map[string]string `json:"--,omitempty" url:"--,omitempty"`
}

type RestartMachineParams

type RestartMachineParams struct {
	RequestParams
	MachineID string `json:"machineId"` // required
}

RestartMachineParams represents the parameters for StopMachine method

type Script added in v0.0.15

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

Script is the structure of a script

type StartMachineParams

type StartMachineParams struct {
	RequestParams
	MachineID string `json:"machineId"` // required
}

StartMachineParams represents the parameters for StartMachine method

type StopMachineParams

type StopMachineParams struct {
	RequestParams
	MachineID string `json:"machineId"` // required
}

StopMachineParams represents the parameters for StopMachine method

type UpdateMachineParams

type UpdateMachineParams struct {
	RequestParams
	MachineID              string `json:"machineId"`                        // required
	MachineName            string `json:"machineName,omitempty"`            // optional
	ShutdownTimeoutInHours int    `json:"shutdownTimeoutInHours,omitempty"` // optional
	ShutdownTimeoutForces  int    `json:"shutdownTimeoutForces,omitempty"`  // optional
	PerformAutoSnapshot    bool   `json:"performAutoSnapshot,omitempty"`    // optional
	AutoSnapshotFrequency  string `json:"autoSnapshotFrequency,omitempty"`  // optional
	AutoSnapshotSaveCount  int    `json:"autoSnapshotSaveCount,omitempty"`  // optional
	DynamicPublicIP        bool   `json:"dynamicPublicIp,omitempty"`        // optional
	AssignPublicIP         bool   `json:"assignPublicIp,omitempty"`         // optional
}

UpdateMachineParams represents the parameters for UpdateMachine method

Jump to

Keyboard shortcuts

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