gosigma

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

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

Go to latest
Published: Apr 8, 2015 License: AGPL-3.0 Imports: 14 Imported by: 9

README

gosigma

CloudSigma API client library for Go.

This library serves as a minimal client for communicating with the CloudSigma web API in Go program.

Documentation

Overview

CloudSigma API client library for Go.

This library serves as a minimal client for communicating with the CloudSigma web API in Go program.

See: https://cloudsigma-docs.readthedocs.org/

Index

Constants

View Source
const (
	// Kilobyte defines constant for specifying kilobytes
	Kilobyte = 1024
	// Megabyte defines constant for specifying megabytes
	Megabyte = 1024 * 1024
	// Gigabyte defines constant for specifying gigabytes
	Gigabyte = 1024 * 1024 * 1024
	// Terabyte defines constant for specifying terabytes
	Terabyte = 1024 * 1024 * 1024 * 1024
)
View Source
const (
	// ModelVirtio defines constant for "virtio" driver model
	ModelVirtio = "virtio"
	// ModelE1000 defines constant for "e1000" driver model
	ModelE1000 = "e1000"
)
View Source
const (
	// DriveUnmounted defines constant for unmounted drive status
	DriveUnmounted = "unmounted"
	// DriveCreating defines constant for creating drive status
	DriveCreating = "creating"
	// DriveResizing defines constant for resizing drive status
	DriveResizing = "resizing"
	// DriveCloningDst defines constant for drive cloning status
	DriveCloningDst = "cloning_dst"
)
View Source
const (
	// MediaCdrom defines media type for cdrom drives
	MediaCdrom = "cdrom"
	// MediaDisk defines media type for disk drives
	MediaDisk = "disk"
)
View Source
const (
	// JobStateStarted defines constant for started job state
	JobStateStarted = "started"
	// JobStateSuccess defines constant for success job state
	JobStateSuccess = "success"
)
View Source
const (
	// ServerStopped defines constant for stopped instance state
	ServerStopped = "stopped"
	// ServerStarting defines constant for starting instance state
	ServerStarting = "starting"
	// ServerRunning defines constant for running instance state
	ServerRunning = "running"
	// ServerStopping defines constant for stopping instance state
	ServerStopping = "stopping"
	// ServerUnavailable defines constant for unavailable instance state
	ServerUnavailable = "unavailable"
)
View Source
const (
	// RecurseNothing defines constant to remove server and leave all attached disks and CDROMs.
	RecurseNothing = ""
	// RecurseAllDrives defines constant to remove server and all attached drives regardless of media type they have.
	RecurseAllDrives = "all_drives"
	// RecurseDisks defines constant to remove server and all attached drives having media type "disk".
	RecurseDisks = "disks"
	// RecurseCDROMs defines constant to remove server and all attached drives having media type "cdrom".
	RecurseCDROMs = "cdroms"
)
View Source
const DefaultRegion string = "zrh"

Default CloudSigma region

Variables

View Source
var ErrOperationTimeout = errors.New("operation timeout")

ErrOperationTimeout defines error for operation timeout

Functions

func ResolveEndpoint

func ResolveEndpoint(endpoint string) string

ResolveEndpoint returns endpoint for given region code

func VerifyEndpoint

func VerifyEndpoint(e string) error

VerifyEndpoint verifies CloudSigma endpoint URL

func Version

func Version() string

Version returns string with current library version

Types

type Client

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

A Client sends and receives requests to CloudSigma endpoint

func NewClient

func NewClient(endpoint string, username, password string,
	tlsConfig *tls.Config) (*Client, error)

NewClient returns new CloudSigma client object

func (*Client) CloneDrive

func (c *Client) CloneDrive(uuid string, libspec LibrarySpec, params CloneParams, avoid []string) (Drive, error)

CloneDrive clones given drive by uuid

func (Client) ConnectTimeout

func (c Client) ConnectTimeout(timeout time.Duration)

ConnectTimeout sets connection timeout

func (*Client) CreateServer

func (c *Client) CreateServer(components Components) (Server, error)

CreateServer in CloudSigma user account

func (*Client) Drive

func (c *Client) Drive(uuid string, libspec LibrarySpec) (Drive, error)

Drive returns given drive by uuid

func (*Client) Drives

func (c *Client) Drives(rqspec RequestSpec, libspec LibrarySpec) ([]Drive, error)

Drives returns list of drives

func (Client) GetConnectTimeout

func (c Client) GetConnectTimeout() time.Duration

GetConnectTimeout returns connection timeout for the object

func (Client) GetOperationTimeout

func (c Client) GetOperationTimeout() time.Duration

GetOperationTimeout gets timeout for cloud operations (like cloning, starting, stopping etc)

func (Client) GetReadWriteTimeout

func (c Client) GetReadWriteTimeout() time.Duration

GetReadWriteTimeout returns connection timeout for the object

func (*Client) Job

func (c *Client) Job(uuid string) (Job, error)

Job returns job object by uuid

func (*Client) Logger

func (c *Client) Logger(logger https.Logger)

Logger sets logger for http traces

func (*Client) OperationTimeout

func (c *Client) OperationTimeout(timeout time.Duration)

OperationTimeout sets timeout for cloud operations (like cloning, starting, stopping etc)

func (Client) ReadContext

func (c Client) ReadContext() (Context, error)

ReadContext reads and returns context of current server

func (Client) ReadWriteTimeout

func (c Client) ReadWriteTimeout(timeout time.Duration)

ReadWriteTimeout sets read-write timeout

func (*Client) RemoveDrive

func (c *Client) RemoveDrive(uuid string, libspec LibrarySpec) error

RemoveDrive removes given drive by uuid

func (Client) RemoveServer

func (c Client) RemoveServer(uuid, recurse string) error

RemoveServer by uuid of server instance with an option recursively removing attached drives. See RecurseXXX constants in server.go file.

func (*Client) Server

func (c *Client) Server(uuid string) (Server, error)

Server returns given server by uuid, requesting endpoint for server information

func (*Client) Servers

func (c *Client) Servers(rqspec RequestSpec) ([]Server, error)

Servers in current account

func (*Client) ServersFiltered

func (c *Client) ServersFiltered(rqspec RequestSpec, filter func(s Server) bool) ([]Server, error)

ServersFiltered in current account with filter applied

func (Client) StartServer

func (c Client) StartServer(uuid string, avoid []string) error

StartServer by uuid of server instance.

func (Client) StopServer

func (c Client) StopServer(uuid string) error

StopServer by uuid of server instance

type CloneParams

type CloneParams struct {
	Affinities []string
	Media      string
	Name       string
}

CloneParams defines attributes for drive cloning operation

type Components

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

A Components contains information to create new server

func (*Components) AttachDrive

func (c *Components) AttachDrive(bootOrder int, channel, device, uuid string)

AttachDrive attaches drive to components from drive data.

func (*Components) NetworkDHCP4

func (c *Components) NetworkDHCP4(model string)

NetworkDHCP4 attaches NIC, configured with IPv4 DHCP

func (*Components) NetworkManual4

func (c *Components) NetworkManual4(model string)

NetworkManual4 attaches NIC, configured with IPv4 manual settings

func (*Components) NetworkStatic4

func (c *Components) NetworkStatic4(model, address string)

NetworkStatic4 attaches NIC, configured with IPv4 static address

func (*Components) NetworkVLan

func (c *Components) NetworkVLan(model, uuid string)

NetworkVLan attaches NIC, configured with private VLan

func (*Components) SetCPU

func (c *Components) SetCPU(frequency uint64)

SetCPU sets CPU frequency for new server. To unset CPU frequency, call this function with zero in the frequency parameter.

func (*Components) SetDescription

func (c *Components) SetDescription(description string)

SetDescription sets description for new server. To unset, call this function with empty string.

func (*Components) SetMem

func (c *Components) SetMem(bytes uint64)

SetMem sets memory size for new server. To unset this value, call function with zero in the bytes parameter.

func (*Components) SetMeta

func (c *Components) SetMeta(name, value string)

SetMeta information for new server

func (*Components) SetName

func (c *Components) SetName(name string)

SetName sets name for new server. To unset name, call this function with empty string in the name parameter.

func (*Components) SetSMP

func (c *Components) SetSMP(cores uint64)

SetSMP sets number of CPU cores for new server. To unset CPU cores, call this function with zero in the cores parameter.

func (*Components) SetSSHPublicKey

func (c *Components) SetSSHPublicKey(description string)

SetSSHPublicKey sets public SSH key for new server. To unset, call this function with empty string.

func (*Components) SetVNCPassword

func (c *Components) SetVNCPassword(password string)

SetVNCPassword sets VNC password for new server. To unset, call this function with empty string.

type Context

type Context interface {
	// CloudSigma resource
	Resource

	// CPU frequency in MHz
	CPU() int64

	// Get meta-information value stored in the server instance
	Get(key string) (string, bool)

	// Mem capacity in bytes
	Mem() int64

	// Name of server instance
	Name() string

	// NICs for this context instance
	NICs() []ContextNIC

	// VNCPassword to access the server
	VNCPassword() string
}

A Context interface represents server instance context in CloudSigma account

type ContextIPv4

type ContextIPv4 interface {
	fmt.Stringer
	Gateway() string
	Nameservers() []string
	Netmask() int
	UUID() string
}

A ContextIPv4 interface represents IPv4 information for server instance context

type ContextNIC

type ContextNIC interface {
	fmt.Stringer
	// Mac address of network interface card
	Mac() string
	// Model of network interface card
	Model() string
}

A ContextNIC interface represents network interface card for server instance context

type ContextVLan

type ContextVLan interface {
	fmt.Stringer
	// UUID of VLan
	UUID() string
	// Tags returns VLan tags
	Tags() []string
	// Get meta-information value associated with VLan
	Get(key string) (string, bool)
}

A ContextVLan interface represents VLan information for server instance context

type Drive

type Drive interface {
	// CloudSigma resource
	Resource

	// Affinities
	Affinities() []string

	// AllowMultimount
	AllowMultimount() bool

	// Get meta-information value stored in the drive instance
	Get(key string) (v string, ok bool)

	// Media of drive instance
	Media() string

	// Name of drive instance
	Name() string

	// Owner of drive instance
	Owner() Resource

	// Size of drive in bytes
	Size() uint64

	// Status of drive instance
	Status() string

	// StorageType of drive instance
	StorageType() string

	// IsLibrary returns true if this drive is CloudSigma library drive
	Library() LibrarySpec

	// OS returns operating system of the drive (defined for library drives)
	OS() string

	// Arch returns operating system bit architecture the drive (defined for library drives)
	Arch() string

	// Paid image or free (defined for library drives)
	Paid() bool

	// ImageType returns type of drive image (defined for library drives)
	ImageType() string

	// Clone drive instance
	Clone(params CloneParams, avoid []string) (Drive, error)

	// Clone drive instance, wait for operation finished
	CloneWait(params CloneParams, avoid []string) (Drive, error)

	// Jobs for this drive instance.
	// Every job object in resulting slice carries only UUID and URI.
	// To obtain additional information for job, one should use Job.Refresh() method
	// to query cloud for detailed job information.
	Jobs() []Job

	// Refresh information about drive instance
	Refresh() error

	// Resize drive instance
	Resize(newSize uint64) error

	// Resize drive instance, wait for operation finished
	ResizeWait(newSize uint64) error

	// Wait for user-defined event
	Wait(stop func(Drive) bool) error

	// Remove drive
	Remove() error
}

A Drive interface represents drive instance in CloudSigma account

type Error

type Error struct {
	SystemError   error       // wrapped error from underlying API
	StatusCode    int         // HTTP status code
	StatusMessage string      // HTTP status string
	ServiceError  *data.Error // Error response object from CloudSigma endpoint
}

A Error implements library error

func NewError

func NewError(r *https.Response, e error) *Error

NewError creates new Error object

func (Error) Error

func (s Error) Error() string

Error implements error interface

type IPv4

type IPv4 interface {
	// Convert to string
	fmt.Stringer

	// Configuration type
	Conf() string

	// Resource of IPv4
	Resource() Resource
}

A IPv4 interface represents IPv4 configuration

type Job

type Job interface {
	// CloudSigma resource
	Resource

	// Children of this job instance
	Children() []string

	// Created time of this job instance
	Created() time.Time

	// LastModified time of this job instance
	LastModified() time.Time

	// Operation of this job instance
	Operation() string

	// Progress of this job instance
	Progress() int

	// Refresh information about job instance
	Refresh() error

	// Resources of this job instance
	Resources() []string

	// State of this job instance
	State() string

	// Wait job is finished
	Wait() error
}

A Job interface represents job instance in CloudSigma account

type LibrarySpec

type LibrarySpec bool

A LibrarySpec defines the type of drive library to use

const (
	// LibraryAccount requests server to use user account drive library
	LibraryAccount LibrarySpec = false
	// LibraryMedia requests server to use public drive library
	LibraryMedia LibrarySpec = true
)

type NIC

type NIC interface {
	// Convert to string
	fmt.Stringer

	// IPv4 configuration
	IPv4() IPv4

	// MAC address
	MAC() string

	// Model of virtual network interface card
	Model() string

	// Runtime returns runtime information for network interface card or nil if stopped
	Runtime() RuntimeNIC

	// Virtual LAN resource
	VLAN() Resource
}

A NIC interface represents network interface card instance

type RequestSpec

type RequestSpec bool

A RequestSpec defines the type of client request

const (
	// RequestShort requests server to return short object representation
	RequestShort RequestSpec = false
	// RequestDetail requests server to return detail object representation
	RequestDetail RequestSpec = true
)

type Resource

type Resource interface {
	// Convert to string
	fmt.Stringer

	// URI of server instance
	URI() string

	// UUID of server instance
	UUID() string
}

A Resource interface represents abstract resource in CloudSigma account

type RuntimeNIC

type RuntimeNIC interface {
	// Convert to string
	fmt.Stringer

	// IPv4 configuration
	IPv4() Resource

	// Type of network interface card (public, private, etc)
	Type() string
}

A RuntimeNIC interface represents runtime information for network interface card

type Server

type Server interface {
	// CloudSigma resource
	Resource

	// Context serial device enabled for server instance
	Context() bool

	// Cpu frequency in MHz
	CPU() uint64

	// Selects whether the SMP is exposed as cores of a single CPU or separate CPUs.
	// This should be set to false for Windows, because there are license
	// requirements for multiple CPUs.
	CPUsInsteadOfCores() bool

	// Virtual CPU model, for mitigating compatibility issues between the guest operating system
	// and the underlying host's CPU. If not specified, all of the hypervisor's CPUs
	// capabilities are passed directly to the virtual machine.
	CPUModel() string

	// Drives for this server instance
	Drives() []ServerDrive

	// Mem capacity in bytes
	Mem() uint64

	// Name of server instance
	Name() string

	// NICs for this server instance
	NICs() []NIC

	// Symmetric Multiprocessing (SMP) i.e. number of CPU cores
	SMP() uint64

	// Status of server instance
	Status() string

	// VNCPassword to access the server
	VNCPassword() string

	// Get meta-information value stored in the server instance
	Get(key string) (string, bool)

	// Refresh information about server instance
	Refresh() error

	// Start server instance. This method does not check current server status,
	// start command is issued to the endpoint in case of any value cached in Status().
	Start() error

	// Stop server instance. This method does not check current server status,
	// stop command is issued to the endpoint in case of any value cached in Status().
	Stop() error

	// Start server instance and waits for status ServerRunning with timeout
	StartWait() error

	// Stop server instance and waits for status ServerStopped with timeout
	StopWait() error

	// Remove server instance
	Remove(recurse string) error

	// Wait for user-defined event
	Wait(stop func(Server) bool) error

	// IPv4 finds all assigned IPv4 addresses at runtime
	IPv4() []string
}

A Server interface represents server instance in CloudSigma account

type ServerDrive

type ServerDrive interface {
	// CloudSigma resource
	Resource

	// BootOrder of drive
	BootOrder() int

	// Channel of drive
	Channel() string

	// Device name of drive
	Device() string

	// Drive object. Note, returned Drive object carries only UUID and URI, so it needs
	// to perform Drive.Refresh to access additional information.
	Drive() Drive
}

A ServerDrive interface represents drive, connected to server instance

type VersionNum

type VersionNum struct {
	Major int
	Minor int
	Micro int
}

VersionNum defines library version

func VersionNumber

func VersionNumber() VersionNum

VersionNumber returns current library version

func (VersionNum) String

func (v VersionNum) String() string

String representation of VersionNum object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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