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.
Index ¶
- Constants
- Variables
- func ResolveEndpoint(endpoint string) (string, error)
- func VerifyEndpoint(e string) error
- func Version() string
- type Client
- func (c *Client) CloneDrive(uuid string, libspec LibrarySpec, params CloneParams, avoid []string) (Drive, error)
- func (c Client) ConnectTimeout(timeout time.Duration)
- func (c *Client) CreateServer(components Components) (Server, error)
- func (c *Client) Drive(uuid string, libspec LibrarySpec) (Drive, error)
- func (c *Client) Drives(rqspec RequestSpec, libspec LibrarySpec) ([]Drive, error)
- func (c Client) GetConnectTimeout() time.Duration
- func (c Client) GetOperationTimeout() time.Duration
- func (c Client) GetReadWriteTimeout() time.Duration
- func (c *Client) Job(uuid string) (Job, error)
- func (c *Client) Logger(logger https.Logger)
- func (c *Client) OperationTimeout(timeout time.Duration)
- func (c Client) ReadContext() (Context, error)
- func (c Client) ReadWriteTimeout(timeout time.Duration)
- func (c *Client) RemoveDrive(uuid string, libspec LibrarySpec) error
- func (c Client) RemoveServer(uuid, recurse string) error
- func (c *Client) Server(uuid string) (Server, error)
- func (c *Client) Servers(rqspec RequestSpec) ([]Server, error)
- func (c *Client) ServersFiltered(rqspec RequestSpec, filter func(s Server) bool) ([]Server, error)
- func (c Client) StartServer(uuid string, avoid []string) error
- func (c Client) StopServer(uuid string) error
- type CloneParams
- type Components
- func (c *Components) AttachDrive(bootOrder int, channel, device, uuid string)
- func (c *Components) NetworkDHCP4(model string)
- func (c *Components) NetworkManual4(model string)
- func (c *Components) NetworkStatic4(model, address string)
- func (c *Components) NetworkVLan(model, uuid string)
- func (c *Components) SetCPU(frequency uint64)
- func (c *Components) SetDescription(description string)
- func (c *Components) SetMem(bytes uint64)
- func (c *Components) SetMeta(name, value string)
- func (c *Components) SetName(name string)
- func (c *Components) SetSMP(cores uint64)
- func (c *Components) SetSSHPublicKey(description string)
- func (c *Components) SetVNCPassword(password string)
- type Context
- type ContextIPv4
- type ContextNIC
- type ContextVLan
- type Drive
- type Error
- type IPv4
- type Job
- type LibrarySpec
- type NIC
- type RequestSpec
- type Resource
- type RuntimeNIC
- type Server
- type ServerDrive
- type VersionNum
Constants ¶
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 )
const ( // ModelVirtio defines constant for "virtio" driver model ModelVirtio = "virtio" // ModelE1000 defines constant for "e1000" driver model ModelE1000 = "e1000" )
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" )
const ( // MediaCdrom defines media type for cdrom drives MediaCdrom = "cdrom" // MediaDisk defines media type for disk drives MediaDisk = "disk" )
const ( // JobStateStarted defines constant for started job state JobStateStarted = "started" // JobStateSuccess defines constant for success job state JobStateSuccess = "success" )
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 = "unavailable" )
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" )
const DefaultRegion string = "zrh"
Default CloudSigma region
Variables ¶
var ErrOperationTimeout = errors.New("operation timeout")
ErrOperationTimeout defines error for operation timeout
Functions ¶
func ResolveEndpoint ¶
ResolveEndpoint returns endpoint for given region code
func VerifyEndpoint ¶
VerifyEndpoint verifies CloudSigma endpoint URL
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client sends and receives requests to CloudSigma endpoint
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 ¶
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 ¶
GetConnectTimeout returns connection timeout for the object
func (Client) GetOperationTimeout ¶
GetOperationTimeout gets timeout for cloud operations (like cloning, starting, stopping etc)
func (Client) GetReadWriteTimeout ¶
GetReadWriteTimeout returns connection timeout for the object
func (*Client) OperationTimeout ¶
OperationTimeout sets timeout for cloud operations (like cloning, starting, stopping etc)
func (Client) ReadContext ¶
ReadContext reads and returns context of current server
func (Client) ReadWriteTimeout ¶
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 ¶
RemoveServer by uuid of server instance with an option recursively removing attached drives. See RecurseXXX constants in server.go file.
func (*Client) Server ¶
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 ¶
ServersFiltered in current account with filter applied
func (Client) StartServer ¶
StartServer by uuid of server instance.
func (Client) StopServer ¶
StopServer by uuid of server instance
type CloneParams ¶
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
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 ¶
VersionNum defines library version
func (VersionNum) String ¶
func (v VersionNum) String() string
String representation of VersionNum object