xelon

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package xelon provides a client for using the Xelon API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyArgument          = errors.New("xelon-sdk-go: argument cannot be empty")
	ErrEmptyPayloadNotAllowed = errors.New("xelon-sdk-go: empty payload is not allowed")
)

Functions

func CheckResponse

func CheckResponse(resp *Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range.

func Stringify added in v0.5.0

func Stringify(message interface{}) string

Stringify attempts to create a string representation of Xelon types

Types

type APIResponse

type APIResponse struct {
	Message           string             `json:"message,omitempty"`
	PersistentStorage *PersistentStorage `json:"persistentStorage,omitempty"`
}

APIResponse is a generic Xelon API response.

type Client

type Client struct {
	BaseURL  *url.URL // Base URL for API requests. BaseURL should always be specified with a trailing slash.
	ClientID string   // ClientID for IP ranges.

	UserAgent string // User agent used when communicating with Xelon API.

	Clouds             *CloudsService
	Devices            *DevicesService
	LoadBalancers      *LoadBalancersService
	Networks           *NetworksService
	PersistentStorages *PersistentStoragesService
	SSHKeys            *SSHKeysService
	Templates          *TemplatesService
	Tenants            *TenantsService
	// contains filtered or unexported fields
}

A Client manages communication with the Xelon API.

func NewClient

func NewClient(token string, opts ...ClientOption) *Client

NewClient returns a new Xelon API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, 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 an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) SetBaseURL deprecated

func (c *Client) SetBaseURL(baseURL string)

Deprecated: SetBaseURL overrides the default BaseURL. Use WithBaseURL instead.

func (*Client) SetUserAgent deprecated

func (c *Client) SetUserAgent(ua string)

Deprecated: SetUserAgent overrides the default UserAgent. Use WithUserAgent instead.

type ClientOption added in v0.7.0

type ClientOption func(*Client)

func WithBaseURL added in v0.7.0

func WithBaseURL(baseURL string) ClientOption

WithBaseURL configures Client to use a specific API endpoint.

func WithClientID added in v0.8.0

func WithClientID(clientID string) ClientOption

WithClientID configures Client to use "X-User-Id" http header by all API requests.

func WithHTTPClient added in v0.7.0

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient configures Client to use a specific http client for communication.

func WithUserAgent added in v0.7.0

func WithUserAgent(ua string) ClientOption

WithUserAgent configures Client to use a specific user agent.

type Cloud added in v0.12.0

type Cloud struct {
	ID        int    `json:"id,omitempty"`
	Name      string `json:"display_name,omitempty"`
	ShortName string `json:"display_short_name,omitempty"`
	Type      int    `json:"type,omitempty"`
}

type CloudsService added in v0.12.0

type CloudsService service

CloudsService handles communication with the organization's cloud related methods of the Xelon API.

func (*CloudsService) List added in v0.12.0

func (s *CloudsService) List(ctx context.Context, tenantID string) ([]Cloud, *Response, error)

type Device

type Device struct {
	CPU            int                   `json:"cpu"`
	LocalVMDetails *DeviceLocalVMDetails `json:"localvmdetails,omitempty"`
	Networks       []DeviceNetwork       `json:"networks,omitempty"`
	PowerState     bool                  `json:"powerstate"`
	RAM            int                   `json:"ram"`
}

Device represents a Xelon device.

type DeviceCreateRequest added in v0.8.0

type DeviceCreateRequest struct {
	CloudID              int    `json:"cloudId"`
	CPUCores             int    `json:"cpucores"`
	DiskSize             int    `json:"disksize"`
	DisplayName          string `json:"displayname"`
	Hostname             string `json:"hostname"`
	IPAddressID          int    `json:"ipaddr1"`
	Memory               int    `json:"memory"`
	NetworkID            int    `json:"networkid1"`
	NICControllerKey     int    `json:"niccontrollerkey1"`
	NICKey               int    `json:"nickey1"`
	NICNumber            int    `json:"nicnumber"`
	NICUnit              int    `json:"nicunit1"`
	Password             string `json:"password"`
	PasswordConfirmation string `json:"password_confirmation"`
	SwapDiskSize         int    `json:"swapdisksize"`
	TemplateID           int    `json:"template"`
	TenantID             string `json:"tenant_identifier"`
}

type DeviceCreateResponse added in v0.8.0

type DeviceCreateResponse struct {
	LocalVMDetails *DeviceLocalVMDetails `json:"device,omitempty"`
	IPs            []string              `json:"ips,omitempty"`
}

type DeviceCreationInfo added in v0.9.0

type DeviceCreationInfo struct {
	Template *Template `json:"template,omitempty"`
	NICs     []NIC     `json:"nics,omitempty"`
}

type DeviceListOptions added in v0.12.1

type DeviceListOptions struct {
	ListOptions
}

type DeviceLocalVMDetails added in v0.8.0

type DeviceLocalVMDetails struct {
	CreatedAt     string `json:"created_at,omitempty"`
	CPU           int    `json:"cpu,omitempty"`
	HVSystemID    int    `json:"hv_system_id,omitempty"`
	ISOMounted    string `json:"iso_mounted,omitempty"`
	LocalVMID     string `json:"localvmid,omitempty"`
	Memory        int    `json:"memory,omitempty"`
	State         int    `json:"state,omitempty"`
	TemplateID    int    `json:"template_id,omitempty"`
	UpdatedAt     string `json:"updated_at,omitempty"`
	UserID        int    `json:"user_id,omitempty"`
	VMDisplayName string `json:"vmdisplayname,omitempty"`
	VMHostname    string `json:"vmhostname,omitempty"`
}

DeviceLocalVMDetails represents a Xelon device's details.

type DeviceNetwork added in v0.8.0

type DeviceNetwork struct {
	IPAddress  string `json:"ip,omitempty"`
	Label      string `json:"label,omitempty"`
	MacAddress string `json:"macAddress,omitempty"`
}

DeviceNetwork represents a Xelon device's network information.

type DeviceRoot

type DeviceRoot struct {
	Device      *Device      `json:"device,omitempty"`
	ToolsStatus *ToolsStatus `json:"toolsStatus,omitempty"`
}

DeviceRoot represents a Xelon device root object.

type DevicesService

type DevicesService service

DevicesService handles communication with the devices related methods of the Xelon API.

func (*DevicesService) Create added in v0.8.0

Create makes a new device with given payload.

func (*DevicesService) Delete added in v0.8.0

func (s *DevicesService) Delete(ctx context.Context, localVMID string) (*Response, error)

Delete removes a device identified by localvmid.

func (*DevicesService) Get

func (s *DevicesService) Get(ctx context.Context, tenantID, localVMID string) (*DeviceRoot, *Response, error)

Get provides detailed information for a device identified by tenant and localvmid.

func (*DevicesService) GetDeviceCreationInfo added in v0.9.0

func (s *DevicesService) GetDeviceCreationInfo(ctx context.Context, tenantID, deviceType string, templateID int) (*DeviceCreationInfo, *Response, error)

GetDeviceCreationInfo retrieves a list of available templates, NICs, and scripts when creating a new device.

func (*DevicesService) List added in v0.12.1

List provides a list of all devices.

func (*DevicesService) Start added in v0.8.0

func (s *DevicesService) Start(ctx context.Context, localVMID string) (*Response, error)

Start starts a specific device identified by localvmid.

func (*DevicesService) Stop added in v0.8.0

func (s *DevicesService) Stop(ctx context.Context, localVMID string) (*Response, error)

Stop stops a specific device identified by localvmid.

type Error added in v0.6.0

type Error struct {
	Message     string `json:"-"`
	Validations map[string]interface{}
}

Error represents an error object in Xelon business logic. It can be a string or array of validation messages.

type ErrorElement

type ErrorElement struct {
	Code  int          `json:"code,omitempty"`
	Error ErrorWrapper `json:"error,omitempty"`
}

func (ErrorElement) String added in v0.6.0

func (e ErrorElement) String() string

type ErrorResponse

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

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ErrorWrapper added in v0.6.0

type ErrorWrapper struct {
	Error
	Partial bool `json:"-"`
}

ErrorWrapper wraps a Error object with additional functionality.

func (*ErrorWrapper) UnmarshalJSON added in v0.6.0

func (w *ErrorWrapper) UnmarshalJSON(data []byte) error

type IP added in v0.9.0

type IP struct {
	ID        int    `json:"id,omitempty"`
	IP        string `json:"ip,omitempty"`
	IPType    int    `json:"iptype,omitempty"`
	LocalVMID string `json:"localvmid,omitempty"`
	NetworkID int    `json:"networkid,omitempty"`
	NICUnit   int    `json:"nicunit,omitempty"`
	Type      string `json:"type,omitempty"`
}

type ListOptions added in v0.12.1

type ListOptions struct {
	// Page of results to retrieve.
	Page int `url:"page,omitempty"`

	// PerPage specifies the number of results to include per page.
	PerPage int `url:"per_page,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type LoadBalancer

type LoadBalancer struct {
	ForwardingRules []LoadBalancerForwardingRule `json:"forwarding_rules,omitempty"`
	Health          string                       `json:"health,omitempty"`
	HealthCheck     LoadBalancerHealthCheck      `json:"health_check,omitempty"`
	ID              int                          `json:"id,omitempty"`
	InternalIP      string                       `json:"internalIp,omitempty"`
	IP              string                       `json:"ip,omitempty"`
	LocalID         string                       `json:"local_id,omitempty"`
	Name            string                       `json:"name,omitempty"`
	Type            int                          `json:"type,omitempty"`
}

LoadBalancer represents a Xelon load balancer.

type LoadBalancerCreateRequest

type LoadBalancerCreateRequest struct {
	CloudID         string                       `json:"cloudId,omitempty"`
	ForwardingRules []LoadBalancerForwardingRule `json:"forwarding_rules,omitempty"`
	Name            string                       `json:"name,omitempty"`
	ServerID        []string                     `json:"server_id,omitempty"`
	Type            int                          `json:"type,omitempty"`
}

type LoadBalancerForwardingRule

type LoadBalancerForwardingRule struct {
	ID    int      `json:"id,omitempty"`
	IP    []string `json:"ip,omitempty"`
	Ports []int    `json:"ports,omitempty"`
	Type  string   `json:"type,omitempty"`
}

LoadBalancerForwardingRule represents a Xelon load balancer forwarding rule.

type LoadBalancerHealthCheck

type LoadBalancerHealthCheck struct {
	BadThreshold  int    `json:"bad_threshold,omitempty"`
	GoodThreshold int    `json:"good_threshold,omitempty"`
	Interval      int    `json:"interval,omitempty"`
	Path          string `json:"path,omitempty"`
	Port          int    `json:"port,omitempty"`
	Timeout       int    `json:"timeout,omitempty"`
}

LoadBalancerHealthCheck represents a Xelon load balancer health check.

type LoadBalancerUpdateForwardingRulesRequest

type LoadBalancerUpdateForwardingRulesRequest struct {
	ForwardingRules []LoadBalancerForwardingRule `json:"forwarding_rules,omitempty"`
}

type LoadBalancersService

type LoadBalancersService service

LoadBalancersService handles communication with the load balancer related methods of the Xelon API.

func (*LoadBalancersService) Create

func (s *LoadBalancersService) Create(ctx context.Context, tenantID string, createRequest *LoadBalancerCreateRequest) (*APIResponse, *Response, error)

Create makes a new load balancer with given payload.

func (*LoadBalancersService) Delete

func (s *LoadBalancersService) Delete(ctx context.Context, tenantID, localID string) (*Response, error)

Delete removes a load balancer.

func (*LoadBalancersService) Get

func (s *LoadBalancersService) Get(ctx context.Context, tenantID, localID string) (*LoadBalancer, *Response, error)

Get provides information about a load balancer identified by local id.

func (*LoadBalancersService) List

func (s *LoadBalancersService) List(ctx context.Context, tenantID string) ([]LoadBalancer, *Response, error)

List provides information about load balancers.

func (*LoadBalancersService) UpdateForwardingRules

func (s *LoadBalancersService) UpdateForwardingRules(ctx context.Context, tenantID, localID string, updateRequest *LoadBalancerUpdateForwardingRulesRequest) (*APIResponse, *Response, error)

type Meta added in v0.12.1

type Meta struct {
	Page    int `json:"current_page,omitempty"`
	PerPage int `json:"per_page,omitempty"`
	Total   int `json:"total,omitempty"`
}

type NIC added in v0.9.0

type NIC struct {
	ControllerKey int                `json:"niccontrollerkey1,omitempty"`
	Key           int                `json:"nickey1,omitempty"`
	IPs           map[string][]NICIP `json:"ips,omitempty"`
	Name          string             `json:"nicname,omitempty"`
	Networks      []NICNetwork       `json:"networks,omitempty"`
	Number        int                `json:"nicnumber,omitempty"`
	Unit          int                `json:"nicunit1,omitempty"`
}

type NICIP added in v0.11.0

type NICIP struct {
	ID      int    `json:"value,omitempty"`
	Address string `json:"text,omitempty"`
}

type NICNetwork added in v0.9.0

type NICNetwork struct {
	Name  string `json:"name,omitempty"`
	Type  string `json:"type,omitempty"`
	Value int    `json:"value,omitempty"`
}

type Network

type Network struct {
	ID      int    `json:"id,omitempty"`
	Name    string `json:"name,omitempty"`
	Network string `json:"network,omitempty"`
	Subnet  string `json:"subnet,omitempty"`
	Type    string `json:"type,omitempty"`
}

type NetworkAddIPRequest added in v0.11.0

type NetworkAddIPRequest struct {
	IPAddress string `json:"ipaddress"`
}

type NetworkDetails added in v0.11.0

type NetworkDetails struct {
	Broadcast      string `json:"broadcast,omitempty"`
	DefaultGateway string `json:"defgw,omitempty"`
	DNSPrimary     string `json:"dns1,omitempty"`
	DNSSecondary   string `json:"dns2,omitempty"`
	ID             int    `json:"id,omitempty"`
	HVSystemID     int    `json:"hv_system_id,omitempty"`
	Name           string `json:"displayname,omitempty"`
	Netmask        string `json:"netmask,omitempty"`
	Network        string `json:"network,omitempty"`
	NetworkID      int    `json:"networkid,omitempty"`
	Subnet         string `json:"subnet,omitempty"`
	Type           string `json:"type,omitempty"`
}

type NetworkInfo added in v0.11.0

type NetworkInfo struct {
	Details *NetworkDetails `json:"localnetid,omitempty"`
	IPs     []IP            `json:"getiplist,omitempty"`
}

type NetworkLANCreateRequest added in v0.11.0

type NetworkLANCreateRequest struct {
	CloudID      int    `json:"cloudId"`
	DisplayName  string `json:"displayname"`
	DNSPrimary   string `json:"dns1"`
	DNSSecondary string `json:"dns2"`
	Gateway      string `json:"gateway"`
	Network      string `json:"network"`
	IPAddresses  string `json:"ip_addresses,omitempty"`
}

NetworkLANCreateRequest represents a request to create a LAN network.

IPAddresses is optional, can either be single "10.0.0.1" or multiple "10.0.0.1-10.0.0.254" entries.

type NetworkUpdateRequest added in v0.11.0

type NetworkUpdateRequest struct {
	*NetworkDetails
}

NetworkUpdateRequest represents a request to update a network.

Following fields are mandatory:

  • NetworkDetails.DefaultGateway
  • NetworkDetails.DNSPrimary
  • NetworkDetails.DNSSecondary
  • NetworkDetails.Name
  • NetworkDetails.Network

type NetworksService added in v0.11.0

type NetworksService service

NetworksService handles communication with the network related methods of the Xelon API.

func (*NetworksService) AddIPAddress added in v0.11.0

func (s *NetworksService) AddIPAddress(ctx context.Context, networkID int, addIPRequest *NetworkAddIPRequest) (*APIResponse, *Response, error)

AddIPAddress adds a new IP address to the specific network.

func (*NetworksService) CreateLAN added in v0.11.0

func (s *NetworksService) CreateLAN(ctx context.Context, tenantID string, createRequest *NetworkLANCreateRequest) (*APIResponse, *Response, error)

CreateLAN makes a new LAN network with given payload.

func (*NetworksService) Delete added in v0.11.0

func (s *NetworksService) Delete(ctx context.Context, networkID int) (*Response, error)

Delete removes a network identified by id.

func (*NetworksService) DeleteIPAddress added in v0.11.0

func (s *NetworksService) DeleteIPAddress(ctx context.Context, networkID, ipAddressID int) (*Response, error)

DeleteIPAddress removes an IP from the specific network.

func (*NetworksService) Get added in v0.11.0

func (s *NetworksService) Get(ctx context.Context, tenantID string, networkID int) (*NetworkInfo, *Response, error)

Get provides information about a network identified by local id.

func (*NetworksService) List added in v0.11.0

func (s *NetworksService) List(ctx context.Context, tenantID string) ([]Network, *Response, error)

List provides a list of all networks.

func (*NetworksService) Update added in v0.11.0

func (s *NetworksService) Update(ctx context.Context, networkID int, updateRequest *NetworkUpdateRequest) (*APIResponse, *Response, error)

Update changes the configuration of a network.

type PersistentStorage

type PersistentStorage struct {
	AssignedServers []DeviceLocalVMDetails `json:"assigned_servers,omitempty"`
	Capacity        int                    `json:"capacity,omitempty"`
	Formatted       int                    `json:"formatted,omitempty"`
	ID              int                    `json:"id,omitempty"`
	LocalID         string                 `json:"local_id,omitempty"`
	Name            string                 `json:"name,omitempty"`
	Type            int                    `json:"type,omitempty"`
	UUID            string                 `json:"uuid,omitempty"`
}

type PersistentStorageAttachDetachRequest

type PersistentStorageAttachDetachRequest struct {
	ServerID []string `json:"server_id"`
}

type PersistentStorageCreateRequest

type PersistentStorageCreateRequest struct {
	*PersistentStorage
	CloudID string `json:"cloudId,omitempty"`
	Size    int    `json:"size,omitempty"`
}

type PersistentStorageExtendRequest added in v0.10.1

type PersistentStorageExtendRequest struct {
	Size int `json:"size"`
}

type PersistentStoragesService

type PersistentStoragesService service

PersistentStoragesService handles communication with the persistent storage related methods of the Xelon API.

func (*PersistentStoragesService) AttachToDevice

func (s *PersistentStoragesService) AttachToDevice(ctx context.Context, tenantID, localID string, attachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error)

func (*PersistentStoragesService) Create

func (*PersistentStoragesService) Delete

func (s *PersistentStoragesService) Delete(ctx context.Context, tenantID, localID string) (*Response, error)

func (*PersistentStoragesService) DetachFromDevice

func (s *PersistentStoragesService) DetachFromDevice(ctx context.Context, tenantID, localID string, detachRequest *PersistentStorageAttachDetachRequest) (*APIResponse, *Response, error)

func (*PersistentStoragesService) Extend added in v0.10.1

func (*PersistentStoragesService) Get

func (s *PersistentStoragesService) Get(ctx context.Context, tenantID, localID string) (*PersistentStorage, *Response, error)

func (*PersistentStoragesService) GetByName added in v0.5.0

func (s *PersistentStoragesService) GetByName(ctx context.Context, tenantID, name string) (*PersistentStorage, *Response, error)

func (*PersistentStoragesService) List

type Response added in v0.5.0

type Response struct {
	*http.Response

	Meta *Meta // Meta describes generic information about the response.

	StackifyID string // StackifyID returned from the API, useful to contact support.
}

Response is a Xelon response. This wraps the standard http.Response.

type SSHKey added in v0.5.0

type SSHKey struct {
	CreatedAt   string `json:"created_at,omitempty"`
	Fingerprint string `json:"fingerprint,omitempty"`
	ID          int    `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	PublicKey   string `json:"ssh_key,omitempty"`
}

SSHKey represents a Xelon ssh key.

func (SSHKey) String added in v0.5.0

func (v SSHKey) String() string

type SSHKeyCreateRequest added in v0.5.0

type SSHKeyCreateRequest struct {
	*SSHKey
}

SSHKeyCreateRequest represents a request to create a ssh key.

type SSHKeysService added in v0.5.0

type SSHKeysService service

SSHKeysService handles communication with the ssh keys related methods of the Xelon API.

func (*SSHKeysService) Create added in v0.5.0

func (s *SSHKeysService) Create(ctx context.Context, createRequest *SSHKeyCreateRequest) (*SSHKey, *Response, error)

Create makes a new ssh key with given payload.

func (*SSHKeysService) Delete added in v0.5.0

func (s *SSHKeysService) Delete(ctx context.Context, sshKeyID int) (*Response, error)

Delete removes a ssh key identified by id.

func (*SSHKeysService) List added in v0.5.0

func (s *SSHKeysService) List(ctx context.Context) ([]SSHKey, *Response, error)

List provides a list of all added SSH keys.

type Template added in v0.9.0

type Template struct {
	ID           int    `json:"id,omitempty"`
	HVSystemID   int    `json:"hv_system_id"`
	Name         string `json:"name,omitempty"`
	NICUnit      int    `json:"nicunit,omitempty"`
	TemplateType int    `json:"templatetype,omitempty"`
	Type         string `json:"type,omitempty"`
}

type Templates added in v0.9.0

type Templates struct {
	LinuxTemplates []Template `json:"templates_linux,omitempty"`
	Templates      []Template `json:"templates,omitempty"`
}

type TemplatesService added in v0.9.0

type TemplatesService service

TemplatesService handles communication with the template related methods of the Xelon API.

func (*TemplatesService) List added in v0.9.0

type Tenant

type Tenant struct {
	Active   bool   `json:"active,omitempty"`
	ID       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Parent   string `json:"parent,omitempty"`
	TenantID string `json:"tenant_identifier,omitempty"`
}

type TenantsService added in v0.10.0

type TenantsService service

TenantsService handles communication with the user related methods of the Xelon API.

func (*TenantsService) GetCurrent added in v0.10.0

func (s *TenantsService) GetCurrent(ctx context.Context) (*Tenant, *Response, error)

GetCurrent provides information about organization.

Note, after calling this method only TenantID field is filled.

func (*TenantsService) List added in v0.10.0

func (s *TenantsService) List(ctx context.Context) ([]Tenant, *Response, error)

List provides information about tenant (aka organizations).

type ToolsStatus added in v0.8.0

type ToolsStatus struct {
	RunningStatus string `json:"runningStatus,omitempty"`
	Version       string `json:"version,omitempty"`
	ToolsStatus   bool   `json:"toolsStatus,omitempty"`
}

Jump to

Keyboard shortcuts

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