cloudscale

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 13 Imported by: 7

README

cloudscale.ch Go API SDK

Build Status

If you want to manage your cloudscale.ch server resources with Go, you are at the right place.

There's a possibility to specify the CLOUDSCALE_URL environment variable to change the default url of https://api.cloudscale.ch.

Download from Github

GO111MODULE=on go get github.com/cloudscale-ch/cloudscale-go-sdk

Testing

The test directory contains integration tests, aside from the unit tests in the root directory. While the unit tests suite runs very quickly because they don't make any network calls, this can take some time to run.

test/integration

This folder contains tests for every type of operation in the cloudscale.ch API and runs tests against it.

Since the tests are run against live data, there is a higher chance of false positives and test failures due to network issues, data changes, etc.

Run the tests using:

CLOUDSCALE_TOKEN="HELPIMTRAPPEDINATOKENGENERATOR" make integration

If you want to give params to go test, you can use something like this:

TESTARGS='-run FloatingIP' make integration

Documentation

Overview

Package metadata implements a client for the cloudscale.ch's OpenStack metadata API. This API allows a server to inspect information about itself, like its server ID.

Documentation for the API is available at:

https://www.cloudscale.ch/en/api/v1

Index

Constants

View Source
const ServerRebooted = "rebooted"
View Source
const ServerRunning = "running"
View Source
const ServerStopped = "stopped"

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

Types

type Address

type Address struct {
	Version      int    `json:"version"`
	Address      string `json:"address"`
	PrefixLength int    `json:"prefix_length"`
	Gateway      string `json:"gateway"`
	ReversePtr   string `json:"reverse_ptr"`
}

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// Authentication token
	AuthToken string

	// User agent for client
	UserAgent string

	Regions      RegionService
	Servers      ServerService
	Volumes      VolumeService
	Networks     NetworkService
	Subnets      SubnetService
	FloatingIPs  FloatingIPsService
	ServerGroups ServerGroupService
	ObjectsUsers ObjectsUsersService
	// contains filtered or unexported fields
}

Client manages communication with CloudScale API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new CloudScale API 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)

type ErrorResponse

type ErrorResponse struct {
	StatusCode int
	Message    map[string]string
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Flavor

type Flavor struct {
	Slug      string `json:"slug"`
	Name      string `json:"name"`
	VCPUCount int    `json:"vcpu_count"`
	MemoryGB  int    `json:"memory_gb"`
}

type FloatingIP

type FloatingIP struct {
	RegionalResource
	HREF           string     `json:"href"`
	Network        string     `json:"network"`
	NextHop        string     `json:"next_hop"`
	Server         ServerStub `json:"server"`
	ReversePointer string     `json:"reverse_ptr,omitempty"`
}

func (FloatingIP) IP

func (f FloatingIP) IP() string

type FloatingIPCreateRequest

type FloatingIPCreateRequest struct {
	RegionalResourceRequest
	IPVersion      int    `json:"ip_version"`
	Server         string `json:"server"`
	PrefixLength   int    `json:"prefix_length,omitempty"`
	ReversePointer string `json:"reverse_ptr,omitempty"`
}

type FloatingIPUpdateRequest

type FloatingIPUpdateRequest struct {
	Server string `json:"server"`
}

type FloatingIPsService

type FloatingIPsService interface {
	Create(ctx context.Context, floatingIPRequest *FloatingIPCreateRequest) (*FloatingIP, error)
	Get(ctx context.Context, ip string) (*FloatingIP, error)
	Update(ctx context.Context, ip string, FloatingIPRequest *FloatingIPUpdateRequest) error
	Delete(ctx context.Context, ip string) error
	List(ctx context.Context) ([]FloatingIP, error)
}

type FloatingIPsServiceOperations

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

func (FloatingIPsServiceOperations) Create

func (FloatingIPsServiceOperations) Delete

func (FloatingIPsServiceOperations) Get

func (FloatingIPsServiceOperations) List

func (FloatingIPsServiceOperations) Update

func (f FloatingIPsServiceOperations) Update(ctx context.Context, ip string, floatingIPUpdateRequest *FloatingIPUpdateRequest) error

type Image

type Image struct {
	Slug            string `json:"slug"`
	Name            string `json:"name"`
	OperatingSystem string `json:"operating_system"`
}

type Interface

type Interface struct {
	Type      string      `json:"type,omitempty"`
	Network   NetworkStub `json:"network,omitempty"`
	Addresses []Address   `json:"addresses,omitempty"`
}

type InterfaceRequest added in v1.1.0

type InterfaceRequest struct {
	Network   string    `json:"network,omitempty"`
	Addresses *[]string `json:"addresses,omitempty"`
}

type ListVolumeParams

type ListVolumeParams struct {
	Name string `json:"name,omitempty"`
}

type Metadata

type Metadata struct {
	AvailabilityZone string `json:"availability_zone,omitempty"`

	Meta struct {
		CloudscaleUUID string `json:"cloudscale_uuid,omitempty"`
	} `json:"meta,omitempty"`
}

type MetadataClient

type MetadataClient struct {
	BaseURL *url.URL
	// contains filtered or unexported fields
}

Client to interact with cloudscale.ch's OpenStack metadata API, from inside a server.

func NewMetadataClient

func NewMetadataClient(httpClient *http.Client) *MetadataClient

NewClient creates a client for the metadata API.

func (*MetadataClient) GetMetadata

func (c *MetadataClient) GetMetadata() (*Metadata, error)

Metadata contains the entire contents of a OpenStack's metadata. This method is unique because it returns all of the metadata at once, instead of individual metadata items.

func (*MetadataClient) GetRawUserData

func (c *MetadataClient) GetRawUserData() (string, error)

RawUserData returns the user data that was provided by the user during Server creation. User data for cloudscale.ch is a YAML Script that is used for cloud-init.

func (*MetadataClient) GetServerID

func (c *MetadataClient) GetServerID() (string, error)

ServerID returns the Server's unique identifier. This is automatically generated upon Server creation.

type Network added in v1.1.0

type Network struct {
	ZonalResource
	// Just use omitempty everywhere. This makes it easy to use restful. Errors
	// will be coming from the API if something is disabled.
	HREF    string       `json:"href,omitempty"`
	UUID    string       `json:"uuid,omitempty"`
	Name    string       `json:"name,omitempty"`
	MTU     int          `json:"mtu,omitempty"`
	Subnets []SubnetStub `json:"subnets"`
}

type NetworkCreateRequest added in v1.1.0

type NetworkCreateRequest struct {
	ZonalResourceRequest
	Name                 string `json:"name,omitempty"`
	MTU                  int    `json:"mtu,omitempty"`
	AutoCreateIPV4Subnet *bool  `json:"auto_create_ipv4_subnet,omitempty"`
}

type NetworkService added in v1.1.0

type NetworkService interface {
	Create(ctx context.Context, createRequest *NetworkCreateRequest) (*Network, error)
	Get(ctx context.Context, networkID string) (*Network, error)
	List(ctx context.Context) ([]Network, error)
	Update(ctx context.Context, networkID string, updateRequest *NetworkUpdateRequest) error
	Delete(ctx context.Context, networkID string) error
}

type NetworkServiceOperations added in v1.1.0

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

func (NetworkServiceOperations) Create added in v1.1.0

func (s NetworkServiceOperations) Create(ctx context.Context, createRequest *NetworkCreateRequest) (*Network, error)

func (NetworkServiceOperations) Delete added in v1.1.0

func (s NetworkServiceOperations) Delete(ctx context.Context, networkID string) error

func (NetworkServiceOperations) Get added in v1.1.0

func (s NetworkServiceOperations) Get(ctx context.Context, networkID string) (*Network, error)

func (NetworkServiceOperations) List added in v1.1.0

func (NetworkServiceOperations) Update added in v1.1.0

func (f NetworkServiceOperations) Update(ctx context.Context, networkID string, updateRequest *NetworkUpdateRequest) error

type NetworkStub added in v1.1.0

type NetworkStub struct {
	HREF string `json:"href,omitempty"`
	Name string `json:"name,omitempty"`
	UUID string `json:"uuid,omitempty"`
}

type NetworkUpdateRequest added in v1.1.0

type NetworkUpdateRequest struct {
	ZonalResourceRequest
	Name string `json:"name,omitempty"`
	MTU  int    `json:"mtu,omitempty"`
}

type ObjectsUser

type ObjectsUser struct {
	HREF        string              `json:"href,omitempty"`
	ID          string              `json:"id,omitempty"`
	DisplayName string              `json:"display_name,omitempty"`
	Keys        []map[string]string `json:"keys,omitempty"`
	Tags        map[string]string   `json:"tags,omitempty"`
}

ObjectsUser contains information

type ObjectsUserRequest

type ObjectsUserRequest struct {
	DisplayName string            `json:"display_name,omitempty"`
	Tags        map[string]string `json:"tags,omitempty"`
}

ObjectsUserRequest is used to create and update Objects Users

type ObjectsUsersService

type ObjectsUsersService interface {
	Create(ctx context.Context, createRequest *ObjectsUserRequest) (*ObjectsUser, error)
	Get(ctx context.Context, objectsUserID string) (*ObjectsUser, error)
	Update(ctx context.Context, objectsUserID string, updateRequest *ObjectsUserRequest) error
	Delete(ctx context.Context, objectsUserID string) error
	List(ctx context.Context) ([]ObjectsUser, error)
}

ObjectsUsersService manages users of the S3-compatible objects storage

type ObjectsUsersServiceOperations

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

ObjectsUsersServiceOperations contains config for this service

func (ObjectsUsersServiceOperations) Create

Create an objects user with the specified attributes.

func (ObjectsUsersServiceOperations) Delete

func (s ObjectsUsersServiceOperations) Delete(ctx context.Context, objectsUserID string) error

Delete an objects user

func (ObjectsUsersServiceOperations) Get

func (s ObjectsUsersServiceOperations) Get(ctx context.Context, objectsUserID string) (*ObjectsUser, error)

Get an objects user by its ID

func (ObjectsUsersServiceOperations) List

List all objects users

func (ObjectsUsersServiceOperations) Update

func (s ObjectsUsersServiceOperations) Update(ctx context.Context, objectsUserID string, updateRequest *ObjectsUserRequest) error

Update the properties of an objects user

type Region

type Region struct {
	Slug  string `json:"slug"`
	Zones []Zone `json:"zones"`
}

type RegionService

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

type RegionServiceOperations

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

func (RegionServiceOperations) List

type RegionalResource

type RegionalResource struct {
	Region Region `json:"Region"`
}

type RegionalResourceRequest

type RegionalResourceRequest struct {
	Region string `json:"region,omitempty"`
}

type Server

type Server struct {
	ZonalResource
	HREF            string            `json:"href"`
	UUID            string            `json:"uuid"`
	Name            string            `json:"name"`
	Status          string            `json:"status"`
	Flavor          Flavor            `json:"flavor"`
	Image           Image             `json:"image"`
	Volumes         []VolumeStub      `json:"volumes"`
	Interfaces      []Interface       `json:"interfaces"`
	SSHFingerprints []string          `json:"ssh_fingerprints"`
	SSHHostKeys     []string          `json:"ssh_host_keys"`
	AntiAfinityWith []ServerStub      `json:"anti_affinity_with"`
	ServerGroups    []ServerGroupStub `json:"server_groups"`
}

type ServerGroup

type ServerGroup struct {
	ZonalResource
	HREF    string       `json:"href"`
	UUID    string       `json:"uuid"`
	Name    string       `json:"name"`
	Type    string       `json:"type"`
	Servers []ServerStub `json:"servers"`
}

type ServerGroupRequest

type ServerGroupRequest struct {
	ZonalResourceRequest
	Name string `json:"name"`
	Type string `json:"type"`
}

type ServerGroupService

type ServerGroupService interface {
	Create(ctx context.Context, createRequest *ServerGroupRequest) (*ServerGroup, error)
	Get(ctx context.Context, serverGroupID string) (*ServerGroup, error)
	Delete(ctx context.Context, serverGroupID string) error
	List(ctx context.Context) ([]ServerGroup, error)
}

type ServerGroupServiceOperations

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

func (ServerGroupServiceOperations) Create

func (ServerGroupServiceOperations) Delete

func (s ServerGroupServiceOperations) Delete(ctx context.Context, serverGroupID string) error

func (ServerGroupServiceOperations) Get

func (s ServerGroupServiceOperations) Get(ctx context.Context, serverGroupID string) (*ServerGroup, error)

func (ServerGroupServiceOperations) List

type ServerGroupStub

type ServerGroupStub struct {
	HREF string `json:"href"`
	UUID string `json:"uuid"`
	Name string `json:"name"`
}

type ServerRequest

type ServerRequest struct {
	ZonalResourceRequest
	Name              string              `json:"name"`
	Flavor            string              `json:"flavor"`
	Image             string              `json:"image"`
	Zone              string              `json:"zone,omitempty"`
	VolumeSizeGB      int                 `json:"volume_size_gb,omitempty"`
	Volumes           *[]Volume           `json:"volumes,omitempty"`
	Interfaces        *[]InterfaceRequest `json:"interfaces,omitempty"`
	BulkVolumeSizeGB  int                 `json:"bulk_volume_size_gb,omitempty"`
	SSHKeys           []string            `json:"ssh_keys"`
	Password          string              `json:"password,omitempty"`
	UsePublicNetwork  *bool               `json:"use_public_network,omitempty"`
	UsePrivateNetwork *bool               `json:"use_private_network,omitempty"`
	UseIPV6           *bool               `json:"use_ipv6,omitempty"`
	AntiAffinityWith  string              `json:"anti_affinity_with,omitempty"`
	ServerGroups      []string            `json:"server_groups,omitempty"`
	UserData          string              `json:"user_data,omitempty"`
}

type ServerService

type ServerService interface {
	Create(ctx context.Context, createRequest *ServerRequest) (*Server, error)
	Get(ctx context.Context, serverID string) (*Server, error)
	Update(ctx context.Context, serverID string, updateRequest *ServerUpdateRequest) error
	Delete(ctx context.Context, serverID string) error
	List(ctx context.Context) ([]Server, error)
	Reboot(ctx context.Context, serverID string) error
	Start(ctx context.Context, serverID string) error
	Stop(ctx context.Context, serverID string) error
}

type ServerServiceOperations

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

func (ServerServiceOperations) Create

func (s ServerServiceOperations) Create(ctx context.Context, createRequest *ServerRequest) (*Server, error)

func (ServerServiceOperations) Delete

func (s ServerServiceOperations) Delete(ctx context.Context, serverID string) error

func (ServerServiceOperations) Get

func (s ServerServiceOperations) Get(ctx context.Context, serverID string) (*Server, error)

func (ServerServiceOperations) List

func (ServerServiceOperations) Reboot

func (s ServerServiceOperations) Reboot(ctx context.Context, serverID string) error

func (ServerServiceOperations) Start

func (s ServerServiceOperations) Start(ctx context.Context, serverID string) error

func (ServerServiceOperations) Stop

func (s ServerServiceOperations) Stop(ctx context.Context, serverID string) error

func (ServerServiceOperations) Update

func (s ServerServiceOperations) Update(ctx context.Context, serverID string, updateRequest *ServerUpdateRequest) error

type ServerStub

type ServerStub struct {
	HREF string `json:"href"`
	UUID string `json:"uuid"`
}

type ServerUpdateRequest

type ServerUpdateRequest struct {
	Name       string              `json:"name,omitempty"`
	Status     string              `json:"status,omitempty"`
	Flavor     string              `json:"flavor,omitempty"`
	Interfaces *[]InterfaceRequest `json:"interfaces,omitempty"`
}

type Subnet added in v1.1.0

type Subnet struct {
	ZonalResource
	// Just use omitempty everywhere. This makes it easy to use restful. Errors
	// will be coming from the API if something is disabled.
	HREF    string      `json:"href,omitempty"`
	UUID    string      `json:"uuid,omitempty"`
	CIDR    string      `json:"cidr,omitempty"`
	Network NetworkStub `json:"network,omitempty"`
}

type SubnetService added in v1.1.0

type SubnetService interface {
	Get(ctx context.Context, subnetID string) (*Subnet, error)
	List(ctx context.Context) ([]Subnet, error)
}

type SubnetServiceOperations added in v1.1.0

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

func (SubnetServiceOperations) Get added in v1.1.0

func (s SubnetServiceOperations) Get(ctx context.Context, subnetID string) (*Subnet, error)

func (SubnetServiceOperations) List added in v1.1.0

type SubnetStub added in v1.1.0

type SubnetStub struct {
	HREF string `json:"href,omitempty"`
	CIDR string `json:"cidr,omitempty"`
	UUID string `json:"uuid,omitempty"`
}

type Volume

type Volume struct {
	ZonalResource
	// Just use omitempty everywhere. This makes it easy to use restful. Errors
	// will be coming from the API if something is disabled.
	HREF        string    `json:"href,omitempty"`
	UUID        string    `json:"uuid,omitempty"`
	Name        string    `json:"name,omitempty"`
	SizeGB      int       `json:"size_gb,omitempty"`
	Type        string    `json:"type,omitempty"`
	ServerUUIDs *[]string `json:"server_uuids,omitempty"`
}

type VolumeRequest

type VolumeRequest struct {
	ZonalResourceRequest
	Name        string    `json:"name,omitempty"`
	SizeGB      int       `json:"size_gb,omitempty"`
	Type        string    `json:"type,omitempty"`
	ServerUUIDs *[]string `json:"server_uuids,omitempty"`
}

type VolumeService

type VolumeService interface {
	Create(ctx context.Context, createRequest *VolumeRequest) (*Volume, error)
	Get(ctx context.Context, volumeID string) (*Volume, error)
	List(ctx context.Context, params *ListVolumeParams) ([]Volume, error)
	Update(ctx context.Context, volumeID string, updateRequest *VolumeRequest) error
	Delete(ctx context.Context, volumeID string) error
}

type VolumeServiceOperations

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

func (VolumeServiceOperations) Create

func (s VolumeServiceOperations) Create(ctx context.Context, createRequest *VolumeRequest) (*Volume, error)

func (VolumeServiceOperations) Delete

func (s VolumeServiceOperations) Delete(ctx context.Context, volumeID string) error

func (VolumeServiceOperations) Get

func (s VolumeServiceOperations) Get(ctx context.Context, volumeID string) (*Volume, error)

func (VolumeServiceOperations) List

func (VolumeServiceOperations) Update

func (f VolumeServiceOperations) Update(ctx context.Context, volumeID string, updateRequest *VolumeRequest) error

type VolumeStub

type VolumeStub struct {
	Type       string `json:"type"`
	DevicePath string `json:"device_path"`
	SizeGB     int    `json:"size_gb"`
	UUID       string `json:"uuid"`
}

type ZonalResource

type ZonalResource struct {
	Zone Zone `json:"zone"`
}

type ZonalResourceRequest

type ZonalResourceRequest struct {
	Zone string `json:"zone,omitempty"`
}

type Zone

type Zone struct {
	Slug string `json:"slug"`
}

Jump to

Keyboard shortcuts

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