gotsw

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 13 Imported by: 0

README

GoTSW

The official Teraswitch Go client.

Install

go get -u github.com/teraswitch/gotsw

Usage

import "github.com/teraswitch/gotsw"
Authentication
package main

import (
    "github.com/teraswitch/gotsw"
)

func main() {
    client := gotsw.NewFromToken("id:secret")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

func CheckResponse

func CheckResponse(r *http.Response) error

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

func DoRequestWithClient

func DoRequestWithClient(
	ctx context.Context,
	client *http.Client,
	req *http.Request) (*http.Response, error)

func Int

func Int(v int) *int

func StreamToString

func StreamToString(stream io.Reader) string

func String

func String(v string) *string

Types

type Client

type Client struct {

	// BASE URL for APIs
	BaseURL *url.URL

	// User Agent for the client
	UserAgent string

	ImageService  ImageService
	RegionService RegionService
	SshKeyService SshKeyService
	MetalService  MetalService
	// contains filtered or unexported fields
}

func New

func New(httpClient *http.Client, opts ...ClientOpt) (*Client, error)

New returns a new API client instance.

func NewClient

func NewClient(httpClient *http.Client) *Client

func NewFromToken

func NewFromToken(token string) *Client

func (*Client) Do

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

func (*Client) NewRequest

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

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the API request completion callback

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetRequestHeaders

func SetRequestHeaders(headers map[string]string) ClientOpt

SetRequestHeaders sets optional HTTP headers on the client that are sent on each HTTP request.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type ErrorResponse

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

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

	Success bool `json:"success"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Image

type Image struct {
	Id                         string `json:"id"`
	DisplayName                string `json:"displayName"`
	OperatingSystemName        string `json:"operatingSystemName"`
	OperatingSystemVersion     string `json:"operatingSystemVersion"`
	DisableCustomizableStorage bool   `json:"disableCustomizableStorage"`
}

type ImageService

type ImageService interface {
	List(ctx context.Context) ([]Image, error)
}

type ImagesServiceHandler

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

func (*ImagesServiceHandler) List

func (s *ImagesServiceHandler) List(ctx context.Context) ([]Image, error)

type Metadata

type Metadata struct {
	Total int `json:"total"`
}

Meta describes generic information about a response.

type Metal

type Metal struct {
	Id          uint64    `json:"id"`
	ProjectId   uint64    `json:"projectId"`
	Status      string    `json:"status"`
	RegionId    string    `json:"regionId"`
	TierId      string    `json:"tierId"`
	DisplayName string    `json:"displayName"`
	PowerState  string    `json:"powerState"`
	CurrentTask string    `json:"currentTask"`
	ImageId     string    `json:"imageId"`
	IpAddresses []string  `json:"ipAddresses"`
	Region      Region    `json:"region"`
	Tier        MetalTier `json:"tier"`
	Image       Image     `json:"image"`
}

type MetalCreateRequest

type MetalCreateRequest struct {
	RegionId    string      `json:"regionId"`
	TierId      string      `json:"tierId"`
	DisplayName string      `json:"displayName"`
	ImageId     string      `json:"imageId"`
	Partitions  []Partition `json:"partitions"`
	RaidArrays  []RaidArray `json:"raidArrays"`
	SshKeyId    uint64      `json:"sshKeyId"`
	TemplateId  uint64      `json:"templateId"`
	Tags        []string    `json:"tags"`
}

type MetalListOptions

type MetalListOptions struct {
	RegionId string `url:"region,omitempty"`
	TierId   string `url:"tier,omitempty"`
	Tag      string `url:"tag,omitempty"`
	Limit    int    `url:"limit,omitempty"`
	Skip     int    `url:"skip,omitempty"`
}

type MetalRecommendedStorageLayout

type MetalRecommendedStorageLayout struct {
	Description string      `json:"description"`
	Partitions  []Partition `json:"partitions"`
	RaidArrays  []RaidArray `json:"raidArrays"`
}

type MetalService

type MetalService interface {
	List(ctx context.Context, options *MetalListOptions) ([]Metal, error)
	Create(ctx context.Context, metalReq *MetalCreateRequest) (*Metal, error)
	Get(ctx context.Context, id uint64) (*Metal, error)

	PowerOff(ctx context.Context, id uint64) (*Metal, error)
	PowerOn(ctx context.Context, id uint64) (*Metal, error)
	Reset(ctx context.Context, id uint64) (*Metal, error)

	ListTemplates(ctx context.Context) ([]MetalTemplate, error)
	ListTiers(ctx context.Context) ([]MetalTier, error)
}

type MetalServiceHandler

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

func (*MetalServiceHandler) Create

func (s *MetalServiceHandler) Create(ctx context.Context, createRequest *MetalCreateRequest) (*Metal, error)

func (*MetalServiceHandler) Get

func (s *MetalServiceHandler) Get(ctx context.Context, id uint64) (*Metal, error)

func (*MetalServiceHandler) List

func (s *MetalServiceHandler) List(ctx context.Context, options *MetalListOptions) ([]Metal, error)

func (*MetalServiceHandler) ListTemplates

func (s *MetalServiceHandler) ListTemplates(ctx context.Context) ([]MetalTemplate, error)

func (*MetalServiceHandler) ListTiers

func (s *MetalServiceHandler) ListTiers(ctx context.Context) ([]MetalTier, error)

func (*MetalServiceHandler) PowerOff

func (s *MetalServiceHandler) PowerOff(ctx context.Context, id uint64) (*Metal, error)

func (*MetalServiceHandler) PowerOn

func (s *MetalServiceHandler) PowerOn(ctx context.Context, id uint64) (*Metal, error)

func (*MetalServiceHandler) Reset

func (s *MetalServiceHandler) Reset(ctx context.Context, id uint64) (*Metal, error)

type MetalStorageDevice

type MetalStorageDevice struct {
	Name          string `json:"name"`
	Type          string `json:"type"`
	CapacityBytes uint64 `json:"capacityBytes"`
}

type MetalTemplate

type MetalTemplate struct {
	Id           uint64               `json:"id"`
	ProjectId    uint64               `json:"projectId"`
	DisplayName  string               `json:"displayName"`
	CreateModels []MetalCreateRequest `json:"createModel"`
	CloudInit    string               `json:"cloudInit"`
}

type MetalTier

type MetalTier struct {
	Id             string               `json:"id"`
	Cpu            string               `json:"cpu"`
	MemoryGb       int                  `json:"memoryGb"`
	StorageDevices []MetalStorageDevice `json:"storageDevices"`
}

type Partition

type Partition struct {
	Name       string `json:"name"`
	Device     string `json:"device"`
	SizeBytes  uint64 `json:"sizeBytes"`
	FileSystem string `json:"fileSystem"`
	MountPoint string `json:"mountPoint"`
}

type PowerCommandRequest

type PowerCommandRequest struct {
	Command string `json:"command"`
}

type RaidArray

type RaidArray struct {
	Name    string   `json:"name"`
	Type    string   `json:"raidType"`
	Members []string `json:"members"`

	Partitions []Partition `json:"partitions"`

	SizeBytes  uint64 `json:"sizeBytes"`
	FileSystem string `json:"fileSystem"`
	MountPoint string `json:"mountPoint"`
}

type Region

type Region struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type RegionService

type RegionService interface {
	List(ctx context.Context) ([]Region, error)
}

type RegionsServiceHandler

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

func (*RegionsServiceHandler) List

func (s *RegionsServiceHandler) List(ctx context.Context) ([]Region, error)

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

type Response

type Response struct {
	*http.Response

	Metadata *Metadata
}

type SshKey

type SshKey struct {
	Id        uint64 `json:"id"`
	ProjectId string `json:"projectId"`
	Key       string `json:"key"`
}

type SshKeyCreateRequest

type SshKeyCreateRequest struct {
	Name      string `json:"displayName"`
	PublicKey string `json:"key"`
}

type SshKeyService

type SshKeyService interface {
	List(ctx context.Context) ([]SshKey, error)
	Create(ctx context.Context, sshKeyReq *SshKeyCreateRequest) (*SshKey, error)
}

type SshKeyServiceHandler

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

func (*SshKeyServiceHandler) Create

func (s *SshKeyServiceHandler) Create(ctx context.Context, createRequest *SshKeyCreateRequest) (*SshKey, error)

func (*SshKeyServiceHandler) List

func (s *SshKeyServiceHandler) List(ctx context.Context) ([]SshKey, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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