cloudscale

package module
v6.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 16 Imported by: 5

README

cloudscale.ch Go API SDK

Go Reference Tests

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

Getting Started

To use the cloudscale-go-sdk for managing your cloudscale.ch resources, follow these steps:

  1. Install the SDK:
    Run the following command to install the SDK:

    go mod init example.com/m
    go get github.com/cloudscale-ch/cloudscale-go-sdk/v6
    
  2. Create a File:
    Save the following code into a file, for example, main.go.

    package main
    
    import (
        "context"
        "fmt"
        "github.com/cenkalti/backoff/v5"
        "github.com/cloudscale-ch/cloudscale-go-sdk/v6"
        "golang.org/x/oauth2"
        "log"
        "os"
        "time"
    )
    
    func main() {
        // Read the API token from the environment variable
        apiToken := os.Getenv("CLOUDSCALE_API_TOKEN")
        if apiToken == "" {
            log.Fatalf("CLOUDSCALE_API_TOKEN environment variable is not set")
        }
    
        // Create a new client
        tc := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(
            &oauth2.Token{AccessToken: apiToken},
        ))
        client := cloudscale.NewClient(tc)
    
        // Define server configuration
        createRequest := &cloudscale.ServerRequest{
            Name:    "example-server",
            Flavor:  "flex-8-2",
            Image:   "debian-11",
            Zone:    "rma1",
            SSHKeys: []string{"<KEY>"},
        }
    
        // Create a server
        server, err := client.Servers.Create(context.Background(), createRequest)
        if err != nil {
            log.Fatalf("Error creating server: %v", err)
        }
    
        fmt.Printf("Creating server with UUID: %s\n", server.UUID)
    
        // Wait for the server to be in "running" state
        server, err = client.Servers.WaitFor(
            context.Background(),
            server.UUID,
            cloudscale.ServerIsRunning, // can be replaced with custom condition funcs
            // optionally, pass any option that github.com/cenkalti/backoff/v5 supports
            backoff.WithNotify(func(err error, duration time.Duration) {
                fmt.Printf("Retrying after error: %v, waiting for %v\n", err, duration)
            }),
        )
        if err != nil {
            log.Fatalf("Error waiting for server to start: %v\n", err)
        }
    
        fmt.Printf("Server is now running with status: %s\n", server.Status)
    }
    
  3. Run the File:
    Make sure the CLOUDSCALE_API_TOKEN environment variable is set. Then, run the file:

    export CLOUDSCALE_API_TOKEN="your_api_token_here"
    go run main.go
    

That's it! The code will create a server and leverage the WaitFor helper to wait until the server status changes to running. For more advanced options, check the documentation.

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_API_TOKEN="HELPIMTRAPPEDINATOKENGENERATOR" make integration

There's a possibility to specify the CLOUDSCALE_API_URL environment variable to change the default url of https://api.cloudscale.ch, but you can almost certainly use the default.

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

TESTARGS='-run FloatingIP' make integration

Some test default to "rma1" for testing. To override this, you can set the following variable

INTEGRATION_TEST_ZONE="lpg1"  make integration

Releasing

To create a new release, please do the following:

  • Merge all feature branches into a release branch
  • Checkout the release branch
  • Run make NEW_VERSION=v1.x.x bump-version
    • For a new major release, follow these instructions
    • Update the pkg.go.dev refercenes in this file (multiple!).
  • Commit changes
  • Merge the release branch into master
  • Create a new release on GitHub.

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"
View Source
const UserDataHandlingExtendCloudConfig = "extend-cloud-config"
View Source
const UserDataHandlingPassThrough = "pass-through"

Variables

View Source
var ImportIsSuccessful = func(importInfo *CustomImageImport) (bool, error) {
	if importInfo.Status == "success" {
		return true, nil
	}
	return false, fmt.Errorf("waiting for status: %s, current status: %s", "success", importInfo.Status)
}
View Source
var LoadBalancerIsRunning = func(lb *LoadBalancer) (bool, error) {
	if lb.Status == "running" {
		return true, nil
	}
	return false, fmt.Errorf("waiting for status: %s, current status: %s", "running", lb.Status)
}
View Source
var LoadBalancerPoolMemberIsUp = func(member *LoadBalancerPoolMember) (bool, error) {
	if member.MonitorStatus == "up" {
		return true, nil
	}
	return false, fmt.Errorf("waiting for monitor status: %s, current status: %s", "up", member.MonitorStatus)
}
View Source
var ServerIsRunning = func(server *Server) (bool, error) {
	if server.Status == ServerRunning {
		return true, nil
	}
	return false, fmt.Errorf("waiting for status: %s, current status: %s", ServerRunning, server.Status)
}
View Source
var ServerIsStopped = func(server *Server) (bool, error) {
	if server.Status == ServerStopped {
		return true, nil
	}
	return false, fmt.Errorf("waiting for status: %s, current status: %s", ServerStopped, server.Status)
}
View Source
var UseCloudscaleDefaults = []string{"CLOUDSCALE_DEFAULTS"}

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"`
	Subnet       SubnetStub `json:"subnet"`
}

type AddressRequest

type AddressRequest struct {
	Subnet  string `json:"subnet,omitempty"`
	Address string `json:"address,omitempty"`
}

type BucketMetrics

type BucketMetrics struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
	Data  []BucketMetricsData
}

type BucketMetricsData

type BucketMetricsData struct {
	Subject    BucketMetricsDataSubject `json:"subject"`
	TimeSeries []BucketMetricsInterval  `json:"time_series"`
}

type BucketMetricsDataSubject

type BucketMetricsDataSubject struct {
	BucketName    string `json:"name"`
	ObjectsUserID string `json:"objects_user_id"`
}

type BucketMetricsInterval

type BucketMetricsInterval struct {
	Start time.Time                  `json:"start"`
	End   time.Time                  `json:"end"`
	Usage BucketMetricsIntervalUsage `json:"usage"`
}

type BucketMetricsIntervalUsage

type BucketMetricsIntervalUsage struct {
	Requests      int `json:"requests"`
	ObjectCount   int `json:"object_count"`
	StorageBytes  int `json:"storage_bytes"`
	ReceivedBytes int `json:"received_bytes"`
	SentBytes     int `json:"sent_bytes"`
}

type BucketMetricsRequest

type BucketMetricsRequest struct {
	// Interpreted as midnight in the Europe/Zurich time zone at the start of
	// the day represented by the day of the passed value in the UTC time zone.
	Start time.Time
	// Interpreted as midnight in the Europe/Zurich time zone at the end of
	// the day represented by the day of the passed value in the UTC time zone.
	End            time.Time
	BucketNames    []string
	ObjectsUserIDs []string
}

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
	CustomImages               CustomImageService
	CustomImageImports         CustomImageImportsService
	LoadBalancers              LoadBalancerService
	LoadBalancerPools          LoadBalancerPoolService
	LoadBalancerPoolMembers    LoadBalancerPoolMemberService
	LoadBalancerListeners      LoadBalancerListenerService
	LoadBalancerHealthMonitors LoadBalancerHealthMonitorService
	Metrics                    MetricsService
	// 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 CustomImage

type CustomImage struct {
	ZonalResource
	TaggedResource
	// 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"`
	Slug             string            `json:"slug,omitempty"`
	SizeGB           int               `json:"size_gb,omitempty"`
	Checksums        map[string]string `json:"checksums,omitempty"`
	UserDataHandling string            `json:"user_data_handling,omitempty"`
	FirmwareType     string            `json:"firmware_type,omitempty"`
	Zones            []Zone            `json:"zones"`
	CreatedAt        time.Time         `json:"created_at"`
}

type CustomImageImport

type CustomImageImport struct {
	TaggedResource
	// 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"`
	CustomImage  CustomImageStub `json:"custom_image,omitempty"`
	URL          string          `json:"url,omitempty"`
	Status       string          `json:"status,omitempty"`
	ErrorMessage string          `json:"error_message,omitempty"`
}

type CustomImageImportRequest

type CustomImageImportRequest struct {
	TaggedResourceRequest
	URL              string   `json:"url,omitempty"`
	Name             string   `json:"name,omitempty"`
	Slug             string   `json:"slug,omitempty"`
	UserDataHandling string   `json:"user_data_handling,omitempty"`
	FirmwareType     string   `json:"firmware_type,omitempty"`
	SourceFormat     string   `json:"source_format,omitempty"`
	Zones            []string `json:"zones,omitempty"`
}

type CustomImageRequest

type CustomImageRequest struct {
	TaggedResourceRequest
	Name             string `json:"name,omitempty"`
	Slug             string `json:"slug,omitempty"`
	UserDataHandling string `json:"user_data_handling,omitempty"`
}

type CustomImageServiceOperations

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

type CustomImageStub

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

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 {
	Region *Region `json:"region"` // not using RegionalResource here, as FloatingIP can be regional or global
	TaggedResource
	HREF           string            `json:"href"`
	Network        string            `json:"network"`
	IPVersion      int               `json:"ip_version"`
	NextHop        string            `json:"next_hop"`
	Server         *ServerStub       `json:"server"`
	LoadBalancer   *LoadBalancerStub `json:"load_balancer"`
	Type           string            `json:"type"`
	ReversePointer string            `json:"reverse_ptr,omitempty"`
	CreatedAt      time.Time         `json:"created_at"`
}

func (FloatingIP) IP

func (f FloatingIP) IP() string

func (FloatingIP) PrefixLength

func (f FloatingIP) PrefixLength() int

type FloatingIPCreateRequest

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

type FloatingIPUpdateRequest

type FloatingIPUpdateRequest struct {
	TaggedResourceRequest
	Server         string `json:"server,omitempty"`
	LoadBalancer   string `json:"load_balancer,omitempty"`
	ReversePointer string `json:"reverse_ptr,omitempty"`
}

type GenericCreateService

type GenericCreateService[TResource any, TCreateRequest any] interface {
	Create(ctx context.Context, createRequest *TCreateRequest) (*TResource, error)
}

type GenericDeleteService

type GenericDeleteService[TResource any] interface {
	Delete(ctx context.Context, resourceID string) error
}

type GenericGetService

type GenericGetService[TResource any] interface {
	Get(ctx context.Context, resourceID string) (*TResource, error)
}

type GenericListService

type GenericListService[TResource any] interface {
	List(ctx context.Context, modifiers ...ListRequestModifier) ([]TResource, error)
}

type GenericServiceOperations

type GenericServiceOperations[TResource any, TCreateRequest any, TUpdateRequest any] struct {
	// contains filtered or unexported fields
}

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Create

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Create(ctx context.Context, createRequest *TCreateRequest) (*TResource, error)

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Delete

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Delete(ctx context.Context, resourceID string) error

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Get

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Get(ctx context.Context, resourceID string) (*TResource, error)

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) List

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) List(ctx context.Context, modifiers ...ListRequestModifier) ([]TResource, error)

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Update

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) Update(ctx context.Context, resourceID string, updateRequest *TUpdateRequest) error

func (GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) WaitFor

func (g GenericServiceOperations[TResource, TCreateRequest, TUpdateRequest]) WaitFor(
	ctx context.Context,
	resourceID string,
	condition func(resource *TResource) (bool, error),
	opts ...backoff.RetryOption,
) (*TResource, error)

type GenericUpdateService

type GenericUpdateService[TResource any, TUpdateRequest any] interface {
	Update(ctx context.Context, resourceID string, updateRequest *TUpdateRequest) error
}

type GenericWaitForService

type GenericWaitForService[TResource any] interface {
	WaitFor(ctx context.Context, resourceID string, condition func(resource *TResource) (bool, error), opts ...backoff.RetryOption) (*TResource, error)
}

type Image

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

type Interface

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

type InterfaceRequest

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

type ListRequestModifier

type ListRequestModifier func(r *http.Request)

func WithNameFilter

func WithNameFilter(name string) ListRequestModifier

WithNameFilter uses an undocumented feature of the cloudscale.ch API

func WithTagFilter

func WithTagFilter(tags TagMap) ListRequestModifier

type LoadBalancer

type LoadBalancer struct {
	ZonalResource
	TaggedResource
	// 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"`
	Flavor       LoadBalancerFlavorStub `json:"flavor,omitempty"`
	Status       string                 `json:"status,omitempty"`
	VIPAddresses []VIPAddress           `json:"vip_addresses,omitempty"`
	CreatedAt    time.Time              `json:"created_at,omitempty"`
}

type LoadBalancerFlavorStub

type LoadBalancerFlavorStub struct {
	Slug string `json:"slug,omitempty"`
	Name string `json:"name,omitempty"`
}

type LoadBalancerHealthMonitor

type LoadBalancerHealthMonitor struct {
	TaggedResource
	// 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"`
	Pool          LoadBalancerPoolStub           `json:"pool,omitempty"`
	LoadBalancer  LoadBalancerStub               `json:"load_balancer,omitempty"`
	DelayS        int                            `json:"delay_s,omitempty"`
	TimeoutS      int                            `json:"timeout_s,omitempty"`
	UpThreshold   int                            `json:"up_threshold,omitempty"`
	DownThreshold int                            `json:"down_threshold,omitempty"`
	Type          string                         `json:"type,omitempty"`
	HTTP          *LoadBalancerHealthMonitorHTTP `json:"http,omitempty"`
	CreatedAt     time.Time                      `json:"created_at,omitempty"`
}

type LoadBalancerHealthMonitorHTTP

type LoadBalancerHealthMonitorHTTP struct {
	ExpectedCodes []string `json:"expected_codes,omitempty"`
	Method        string   `json:"method,omitempty"`
	UrlPath       string   `json:"url_path,omitempty"`
	Version       string   `json:"version,omitempty"`
	Host          *string  `json:"host,omitempty"`
}

type LoadBalancerHealthMonitorHTTPRequest

type LoadBalancerHealthMonitorHTTPRequest struct {
	ExpectedCodes []string `json:"expected_codes,omitempty"`
	Method        string   `json:"method,omitempty"`
	UrlPath       string   `json:"url_path,omitempty"`
	Version       string   `json:"version,omitempty"`
	Host          *string  `json:"host,omitempty"`
}

type LoadBalancerHealthMonitorRequest

type LoadBalancerHealthMonitorRequest struct {
	TaggedResourceRequest
	Pool          string                                `json:"pool,omitempty"`
	DelayS        int                                   `json:"delay_s,omitempty"`
	TimeoutS      int                                   `json:"timeout_s,omitempty"`
	UpThreshold   int                                   `json:"up_threshold,omitempty"`
	DownThreshold int                                   `json:"down_threshold,omitempty"`
	Type          string                                `json:"type,omitempty"`
	HTTP          *LoadBalancerHealthMonitorHTTPRequest `json:"http,omitempty"`
}

type LoadBalancerListener

type LoadBalancerListener struct {
	TaggedResource
	// 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"`
	Pool                   *LoadBalancerPoolStub `json:"pool,omitempty"`
	LoadBalancer           LoadBalancerStub      `json:"load_balancer,omitempty"`
	Protocol               string                `json:"protocol,omitempty"`
	ProtocolPort           int                   `json:"protocol_port,omitempty"`
	AllowedCIDRs           []string              `json:"allowed_cidrs,omitempty"`
	TimeoutClientDataMS    int                   `json:"timeout_client_data_ms,omitempty"`
	TimeoutMemberConnectMS int                   `json:"timeout_member_connect_ms,omitempty"`
	TimeoutMemberDataMS    int                   `json:"timeout_member_data_ms,omitempty"`
	CreatedAt              time.Time             `json:"created_at,omitempty"`
}

type LoadBalancerListenerRequest

type LoadBalancerListenerRequest struct {
	TaggedResourceRequest
	Name                   string    `json:"name,omitempty"`
	Pool                   string    `json:"pool,omitempty"`
	Protocol               string    `json:"protocol,omitempty"`
	ProtocolPort           int       `json:"protocol_port,omitempty"`
	AllowedCIDRs           *[]string `json:"allowed_cidrs,omitempty"`
	TimeoutClientDataMS    int       `json:"timeout_client_data_ms,omitempty"`
	TimeoutMemberConnectMS int       `json:"timeout_member_connect_ms,omitempty"`
	TimeoutMemberDataMS    int       `json:"timeout_member_data_ms,omitempty"`
}

type LoadBalancerPool

type LoadBalancerPool struct {
	TaggedResource
	// 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"`
	CreatedAt    time.Time        `json:"created_at,omitempty"`
	LoadBalancer LoadBalancerStub `json:"load_balancer,omitempty"`
	Algorithm    string           `json:"algorithm,omitempty"`
	Protocol     string           `json:"protocol,omitempty"`
}

type LoadBalancerPoolMember

type LoadBalancerPoolMember struct {
	TaggedResource
	// 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"`
	Enabled       bool                 `json:"enabled,omitempty"`
	CreatedAt     time.Time            `json:"created_at,omitempty"`
	Pool          LoadBalancerPoolStub `json:"pool,omitempty"`
	LoadBalancer  LoadBalancerStub     `json:"load_balancer,omitempty"`
	ProtocolPort  int                  `json:"protocol_port,omitempty"`
	MonitorPort   int                  `json:"monitor_port,omitempty"`
	Address       string               `json:"address,omitempty"`
	Subnet        SubnetStub           `json:"subnet,omitempty"`
	MonitorStatus string               `json:"monitor_status,omitempty"`
}

type LoadBalancerPoolMemberRequest

type LoadBalancerPoolMemberRequest struct {
	TaggedResourceRequest
	Name         string `json:"name,omitempty"`
	Enabled      *bool  `json:"enabled,omitempty"`
	ProtocolPort int    `json:"protocol_port,omitempty"`
	MonitorPort  int    `json:"monitor_port,omitempty"`
	Address      string `json:"address,omitempty"`
	Subnet       string `json:"subnet,omitempty"`
}

type LoadBalancerPoolMemberService

type LoadBalancerPoolMemberService interface {
	Create(ctx context.Context, poolID string, createRequest *LoadBalancerPoolMemberRequest) (*LoadBalancerPoolMember, error)
	Get(ctx context.Context, poolID string, resourceID string) (*LoadBalancerPoolMember, error)
	List(ctx context.Context, poolID string, modifiers ...ListRequestModifier) ([]LoadBalancerPoolMember, error)
	Update(ctx context.Context, poolID string, resourceID string, updateRequest *LoadBalancerPoolMemberRequest) error
	Delete(ctx context.Context, poolID string, resourceID string) error
	WaitFor(ctx context.Context, poolID string, resourceID string, condition func(resource *LoadBalancerPoolMember) (bool, error), opts ...backoff.RetryOption) (*LoadBalancerPoolMember, error)
}

type LoadBalancerPoolMemberServiceOperations

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

func (LoadBalancerPoolMemberServiceOperations) Create

func (LoadBalancerPoolMemberServiceOperations) Delete

func (l LoadBalancerPoolMemberServiceOperations) Delete(ctx context.Context, poolID string, resourceID string) error

func (LoadBalancerPoolMemberServiceOperations) Get

func (LoadBalancerPoolMemberServiceOperations) List

func (LoadBalancerPoolMemberServiceOperations) Update

func (LoadBalancerPoolMemberServiceOperations) WaitFor

func (l LoadBalancerPoolMemberServiceOperations) WaitFor(
	ctx context.Context,
	poolID string,
	resourceID string,
	condition func(resource *LoadBalancerPoolMember) (bool, error),
	opts ...backoff.RetryOption,
) (*LoadBalancerPoolMember, error)

type LoadBalancerPoolRequest

type LoadBalancerPoolRequest struct {
	TaggedResourceRequest
	Name         string `json:"name,omitempty"`
	LoadBalancer string `json:"load_balancer,omitempty"`
	Algorithm    string `json:"algorithm,omitempty"`
	Protocol     string `json:"protocol,omitempty"`
}

type LoadBalancerPoolStub

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

type LoadBalancerRequest

type LoadBalancerRequest struct {
	ZonalResourceRequest
	TaggedResourceRequest
	Name         string               `json:"name,omitempty"`
	Flavor       string               `json:"flavor,omitempty"`
	VIPAddresses *[]VIPAddressRequest `json:"vip_addresses,omitempty"`
}

type LoadBalancerStub

type LoadBalancerStub struct {
	HREF string `json:"href,omitempty"`
	UUID string `json:"uuid,omitempty"`
	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 MetricsService

type MetricsService interface {
	GetBucketMetrics(ctx context.Context, request *BucketMetricsRequest) (*BucketMetrics, error)
}

type MetricsServiceOperations

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

func (MetricsServiceOperations) GetBucketMetrics

func (s MetricsServiceOperations) GetBucketMetrics(ctx context.Context, request *BucketMetricsRequest) (*BucketMetrics, error)

type Network

type Network struct {
	ZonalResource
	TaggedResource
	// 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"`
	CreatedAt time.Time    `json:"created_at"`
}

type NetworkCreateRequest

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

type NetworkServiceOperations

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

type NetworkStub

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

type NetworkUpdateRequest

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

type ObjectsUser

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

ObjectsUser contains information

type ObjectsUserRequest

type ObjectsUserRequest struct {
	TaggedResourceRequest
	DisplayName string `json:"display_name,omitempty"`
}

ObjectsUserRequest is used to create and update Objects Users

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
	TaggedResource
	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"`
	CreatedAt       time.Time         `json:"created_at"`
}

type ServerGroup

type ServerGroup struct {
	ZonalResource
	TaggedResource
	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
	TaggedResourceRequest
	Name string `json:"name,omitempty"`
	Type string `json:"type,omitempty"`
}

type ServerGroupStub

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

type ServerRequest

type ServerRequest struct {
	ZonalResourceRequest
	TaggedResourceRequest
	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           *[]ServerVolumeRequest `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 ServerServiceOperations

type ServerServiceOperations struct {
	GenericServiceOperations[Server, ServerRequest, ServerUpdateRequest]
	// contains filtered or unexported fields
}

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

type ServerStub

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

type ServerUpdateRequest

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

type ServerVolumeRequest

type ServerVolumeRequest struct {
	SizeGB int    `json:"size_gb,omitempty"`
	Type   string `json:"type,omitempty"`
}

type Subnet

type Subnet struct {
	TaggedResource
	// 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"`
	GatewayAddress string      `json:"gateway_address,omitempty"`
	DNSServers     []string    `json:"dns_servers,omitempty"`
}

type SubnetCreateRequest

type SubnetCreateRequest struct {
	TaggedResourceRequest
	CIDR           string    `json:"cidr,omitempty"`
	Network        string    `json:"network,omitempty"`
	GatewayAddress string    `json:"gateway_address,omitempty"`
	DNSServers     *[]string `json:"dns_servers,omitempty"`
}

func (SubnetCreateRequest) MarshalJSON

func (request SubnetCreateRequest) MarshalJSON() ([]byte, error)

type SubnetServiceOperations

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

type SubnetStub

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

type SubnetUpdateRequest

type SubnetUpdateRequest struct {
	TaggedResourceRequest
	GatewayAddress string    `json:"gateway_address,omitempty"`
	DNSServers     *[]string `json:"dns_servers"`
}

func (SubnetUpdateRequest) MarshalJSON

func (request SubnetUpdateRequest) MarshalJSON() ([]byte, error)

type TagMap

type TagMap map[string]string

type TaggedResource

type TaggedResource struct {
	Tags TagMap `json:"tags"`
}

type TaggedResourceRequest

type TaggedResourceRequest struct {
	Tags *TagMap `json:"tags,omitempty"`
}

type VIPAddress

type VIPAddress struct {
	Version int        `json:"version,omitempty"`
	Address string     `json:"address,omitempty"`
	Subnet  SubnetStub `json:"subnet,omitempty"`
}

type VIPAddressRequest

type VIPAddressRequest struct {
	Address string `json:"address,omitempty"`
	Subnet  string `json:"subnet,omitempty"`
}

type Volume

type Volume struct {
	ZonalResource
	TaggedResource
	// 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"`
	CreatedAt   time.Time `json:"created_at"`
}

type VolumeRequest

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

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