instances

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Overview

Package instances manages instances on KraftCloud.

Index

Constants

View Source
const DefaultAutoStart = true

DefaultAutoStart is the default autostart value - whether the instance will start immediately after creation

View Source
const Endpoint = "/instances"

Endpoint is the public path for the instances service.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleResponseItem added in v0.5.0

type ConsoleResponseItem struct {
	Status string `json:"status"`
	UUID   string `json:"uuid"`
	Name   string `json:"name"`
	Output string `json:"output"`

	kcclient.APIResponseCommon
}

ConsoleResponseItem is a data item from a response to a GET /instances/console request. https://docs.kraft.cloud/api/v1/instances/#retrieve-the-console-output

type CreateRequest added in v0.5.0

type CreateRequest struct {
	Name          *string                    `json:"name"`
	Image         string                     `json:"image"`
	Args          []string                   `json:"args"`
	Env           map[string]string          `json:"env"`
	MemoryMB      *int                       `json:"memory_mb"`
	ServiceGroup  *CreateRequestServiceGroup `json:"service_group"`
	Volumes       []CreateRequestVolume      `json:"volumes"`
	Autostart     *bool                      `json:"autostart"`
	Replicas      *int                       `json:"replicas"`
	WaitTimeoutMs *int                       `json:"wait_timeout_ms"`
	Features      []Feature                  `json:"features"`
}

CreateRequest is the payload for a POST /instances request. https://docs.kraft.cloud/api/v1/instances/#creating-a-new-instance

type CreateRequestServiceGroup added in v0.5.0

type CreateRequestServiceGroup struct {
	UUID     *string                         `json:"uuid"`
	Name     *string                         `json:"name"`
	Services []services.CreateRequestService `json:"services"`
	DNSName  *string                         `json:"dns_name"`
}

type CreateRequestVolume added in v0.5.0

type CreateRequestVolume struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	SizeMB   int    `json:"size_mb"`
	At       string `json:"at"`
	ReadOnly *bool  `json:"readonly"`
}

type CreateResponseItem added in v0.5.0

type CreateResponseItem struct {
	Status      string `json:"status"`
	State       string `json:"state"`
	UUID        string `json:"uuid"`
	Name        string `json:"name"`
	FQDN        string `json:"fqdn"`
	PrivateFQDN string `json:"private_fqdn"`
	PrivateIP   string `json:"private_ip"`
	BootTimeUs  *int   `json:"boot_time_us"` // only if wait_timeout_ms was set in the request

	kcclient.APIResponseCommon
}

CreateResponseItem is a data item from a response to a POST /instances request. https://docs.kraft.cloud/api/v1/instances/#creating-a-new-instance

type DeleteResponseItem added in v0.5.0

type DeleteResponseItem struct {
	Status        string `json:"status"`
	UUID          string `json:"uuid"`
	Name          string `json:"name"`
	PreviousState string `json:"previous_state"`

	kcclient.APIResponseCommon
}

DeleteResponseItem is a data item from a response to a DELETE /instances request. https://docs.kraft.cloud/api/v1/instances/#deleting-an-instance

type Feature added in v0.5.0

type Feature string

Feature is a special feature of an instance.

const FeatureScaleToZero Feature = "scale-to-zero"

FeatureScaleToZero indicates that the instance can be scaled to zero.

type GetResponseItem added in v0.5.0

type GetResponseItem struct {
	Status            string                        `json:"status"`
	UUID              string                        `json:"uuid"`
	Name              string                        `json:"name"`
	CreatedAt         string                        `json:"created_at"`
	State             string                        `json:"state"`
	Image             string                        `json:"image"`
	MemoryMB          int                           `json:"memory_mb"`
	Args              []string                      `json:"args"`
	Env               map[string]string             `json:"env"`
	FQDN              string                        `json:"fqdn"`
	PrivateFQDN       string                        `json:"private_fqdn"`
	PrivateIP         string                        `json:"private_ip"`
	ServiceGroup      *GetResponseServiceGroup      `json:"service_group"`
	Volumes           []GetResponseVolume           `json:"volumes"`
	NetworkInterfaces []GetResponseNetworkInterface `json:"network_interfaces"`
	BootTimeUs        int                           `json:"boot_time_us"` // always returned, even if never started

	kcclient.APIResponseCommon
}

GetResponseItem is a data item from a response to a GET /instances request. https://docs.kraft.cloud/api/v1/instances/#getting-the-status-of-an-instance

type GetResponseNetworkInterface added in v0.5.0

type GetResponseNetworkInterface struct {
	UUID      string `json:"uuid"`
	PrivateIP string `json:"private_ip"`
	MAC       string `json:"mac"`
}

type GetResponseServiceGroup added in v0.5.0

type GetResponseServiceGroup struct {
	UUID string `json:"uuid"`
	Name string `json:"name"`
}

type GetResponseVolume added in v0.5.0

type GetResponseVolume struct {
	UUID     string `json:"uuid"`
	Name     string `json:"name"`
	At       string `json:"at"`
	ReadOnly bool   `json:"readonly"`
}

type InstancesService

type InstancesService interface {
	kcclient.ServiceClient[InstancesService]

	// Creates one or more new instances of the specified Unikraft images. You can
	// describe the properties of the new instances such as their startup
	// arguments and amount of memory. Note that, the instance properties can only
	// be defined during creation. They cannot be changed later.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#creating-a-new-instance
	Create(ctx context.Context, req CreateRequest) (*CreateResponseItem, error)

	// GetByUUIDs returns the current state and the configuration of one or
	// more instance(s) based on the provided UUID(s).
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#getting-the-status-of-an-instance
	GetByUUIDs(ctx context.Context, uuids ...string) ([]GetResponseItem, error)

	// GetByNames returns the current state and the configuration of one or
	// more instances based on the provided name(s).
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#getting-the-status-of-an-instance
	GetByNames(ctx context.Context, names ...string) ([]GetResponseItem, error)

	// DeleteByUUIDs deletes the specified instances based on their UUID.
	// After this call the UUIDs of the instances are no longer valid. If the
	// instances are currently running, they are force stopped.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#deleting-an-instance
	DeleteByUUIDs(ctx context.Context, uuids ...string) ([]DeleteResponseItem, error)

	// DeleteByNames deletes the specified instances based on their names.
	// After this call the UUIDs of the instances are no longer valid. If the
	// instances are currently running, they are force stopped.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#deleting-an-instance
	DeleteByNames(ctx context.Context, names ...string) ([]DeleteResponseItem, error)

	// Lists all existing instances.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#list-existing-instances
	List(ctx context.Context) ([]ListResponseItem, error)

	// Starts a previously stopped instance(s) based on their UUID(s).
	// Does nothing for instances that are already running.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#starting-an-instance
	StartByUUIDs(ctx context.Context, waitTimeoutMs int, uuids ...string) ([]StartResponseItem, error)

	// Starts a previously stopped instance(s) based on their name(s).
	// Does nothing for instances that are already running.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#starting-an-instance
	StartByNames(ctx context.Context, waitTimeoutMs int, names ...string) ([]StartResponseItem, error)

	// StopByUUIDs stops the specified instance(s) based on their UUID(s), but
	// does not destroy them.  All volatile state (e.g., RAM contents) is lost.
	// Does nothing for instances that are already stopped. Instances can be
	// started again with the start endpoint.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#stopping-an-instance
	StopByUUIDs(ctx context.Context, drainTimeoutMs int, uuid ...string) ([]StopResponseItem, error)

	// StopByNames stops the specified instance(s) based on their name(s), but
	// does not destroy them.  All volatile state (e.g., RAM contents) is lost.
	// Does nothing for instances that are already stopped. Instances can be
	// started again with the start endpoint.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#stopping-an-instance
	StopByNames(ctx context.Context, drainTimeoutMs int, names ...string) ([]StopResponseItem, error)

	// ConsoleByName returns the console output of the specified instance based
	// on its name.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#retrieve-the-console-output
	ConsoleByName(ctx context.Context, name string, maxLines int, latest bool) (*ConsoleResponseItem, error)

	// ConsoleByUUID returns the console output of the specified instance based
	// on its UUID.
	//
	// See: https://docs.kraft.cloud/api/v1/instances/#retrieve-the-console-output
	ConsoleByUUID(ctx context.Context, uuid string, maxLines int, latest bool) (*ConsoleResponseItem, error)
}

func NewInstancesClientFromOptions

func NewInstancesClientFromOptions(opts *options.Options) InstancesService

NewInstancesClientFromOptions instantiates a new instances services client based on the provided pre-existing options.

type ListResponseItem added in v0.5.0

type ListResponseItem struct {
	UUID string `json:"uuid"`
	Name string `json:"name"`

	kcclient.APIResponseCommon
}

ListResponseItem is a data item from a response to a GET /instances/list request. https://docs.kraft.cloud/api/v1/instances/#list-existing-instances

type StartResponseItem added in v0.5.0

type StartResponseItem struct {
	Status        string `json:"status"`
	UUID          string `json:"uuid"`
	Name          string `json:"name"`
	State         string `json:"state"`
	PreviousState string `json:"previous_state"`

	kcclient.APIResponseCommon
}

StartResponseItem is a data item from a response to a POST /instances/start request. https://docs.kraft.cloud/api/v1/instances/#starting-an-instance

type StopResponseItem added in v0.5.0

type StopResponseItem struct {
	Status        string `json:"status"`
	UUID          string `json:"uuid"`
	Name          string `json:"name"`
	State         string `json:"state"`
	PreviousState string `json:"previous_state"`

	kcclient.APIResponseCommon
}

StopResponseItem is a data item from a response to a POST /instances/stop request. https://docs.kraft.cloud/api/v1/instances/#stopping-an-instance

Jump to

Keyboard shortcuts

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