cloud

package
v0.0.0-...-23a443e Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerStateRunning  = "running"
	ServerStateStopped  = "stopped"
	ServerStateOther    = "other"
	ServerStateChanging = "changing"

	KindLocalVM = "local_vm"
	KindCloudVM = "cloud_vm"
	// Scaleway cloud provider
	Scaleway = Type("scaleway")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudProvider

type CloudProvider interface {
	CloudProviderBase
	CloudProviderImplementation
}

type CloudProviderBase

type CloudProviderBase interface {
	Save() error     // saves the instance of the cloud provider (name and credentials) in the db
	NameStr() string // returns the name of the cloud provider
	TypeStr() string // returns the string formatted cloud type
}

type CloudProviderImplementation

type CloudProviderImplementation interface {
	// Config methods
	SupportedLocations() (locations []string)                          // returns the supported locations for a specific cloud provider
	AuthFields() (fields []string)                                     // returns the fields that are required to authenticate for a specific cloud provider
	SetAuth(auth map[string]string) error                              // sets the credentials for a cloud provider
	Init() error                                                       // a cloud provider always needs to have Init called to configure it and test the credentials. If auth fails, Init should return an error
	SupportedMachines(location string) (map[string]MachineSpec, error) // returns a map of machine ids and their hardware specifications. A user will choose the machines for their instance

	// Instance methods
	NewInstance(name string, image string, pubKey string, machineType string, location string) (id string, err error)
	DeleteInstance(id string, location string) error
	StartInstance(id string, location string) error
	StopInstance(id string, location string) error
	GetInstanceInfo(id string, location string) (InstanceInfo, error)
	// Image methods
	GetImages() (images map[string]ImageInfo, err error)
	GetProtosImages() (images map[string]ImageInfo, err error)
	AddImage(url string, hash string, version string, location string) (id string, err error)
	UploadLocalImage(imagePath string, imageName string, location string, timeout time.Duration) (id string, err error)
	RemoveImage(name string, location string) error
	// Volume methods
	// - size should by provided in megabytes
	NewVolume(name string, size int, location string) (id string, err error)
	DeleteVolume(id string, location string) error
	AttachVolume(volumeID string, instanceID string, location string) error
	DettachVolume(volumeID string, instanceID string, location string) error
}

CloudProviderImplementation allows interactions with cloud instances and images

type ImageInfo

type ImageInfo struct {
	ID       string
	Name     string
	Location string
}

ImageInfo holds information about a cloud image used for deploying an instance

type InstanceInfo

type InstanceInfo struct {
	ID           string
	Name         string
	PublicKey    string // ed25519 public key
	PublicIP     string // this can be a public or private IP, depending on where the device is located
	Kind         string // type of instance: local_vm, cloud_vm
	KindID       string // ID of the cloud provider or device ID for local VM
	Location     string
	Status       string
	Architecture string
	Volumes      []VolumeInfo
}

InstanceInfo holds information about a cloud instance

func (InstanceInfo) GetID

func (i InstanceInfo) GetID() string

func (InstanceInfo) GetName

func (i InstanceInfo) GetName() string

func (InstanceInfo) GetPublicIP

func (i InstanceInfo) GetPublicIP() string

func (InstanceInfo) GetPublicKey

func (i InstanceInfo) GetPublicKey() string

type MachineSpec

type MachineSpec struct {
	Cores                uint32  // Nr of cores
	Memory               uint32  // MiB
	DefaultStorage       uint32  // GB
	Bandwidth            uint32  // Mbit
	IncludedDataTransfer uint32  // GB. 0 for unlimited
	Baremetal            bool    // true if machine is bare metal
	PriceMonthly         float32 // no currency conversion at the moment. Each cloud reports this differently
}

MachineSpec holds information about the hardware characteristics of vm or baremetal instance

type Manager

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

Manager manages cloud providers and instances

func CreateManager

func CreateManager(db *db.DB, um *user.Manager, sm *pcrypto.Manager, p2p *p2p.P2P) (*Manager, error)

CreateManager creates and returns a cloud manager

func (*Manager) DeleteInstance

func (cm *Manager) DeleteInstance(id string) error

DeleteInstance deletes an instance

func (*Manager) DeleteProvider

func (cm *Manager) DeleteProvider(name string) error

DeleteProvider deletes a cloud provider from the db

func (*Manager) DeployInstance

func (cm *Manager) DeployInstance(instanceName string, cloudName string, cloudLocation string, release release.Release, machineType string) (InstanceInfo, error)

DeployInstance deploys an instance on the provided cloud

func (*Manager) GetInstance

func (cm *Manager) GetInstance(id string) (InstanceInfo, error)

GetInstance retrieves an instance from the db and returns it

func (*Manager) GetInstances

func (cm *Manager) GetInstances(excludeLocalInstance bool) ([]InstanceInfo, error)

GetInstances returns all the instances from the db

func (*Manager) GetInstancesWithUpdatedStatus

func (cm *Manager) GetInstancesWithUpdatedStatus() ([]InstanceInfo, error)

GetInstances returns all the instances from the db

func (*Manager) GetProvider

func (cm *Manager) GetProvider(id string) (CloudProvider, error)

GetProvider returns a cloud provider instance from the db

func (*Manager) GetProviders

func (cm *Manager) GetProviders() ([]CloudProvider, error)

GetProviders returns all the cloud providers from the db

func (*Manager) InitInstance

func (cm *Manager) InitInstance(instanceName string, kind string, kindID string, locationName string, ipString string) error

func (*Manager) LogsRemoteInstance

func (cm *Manager) LogsRemoteInstance(id string) (string, error)

LogsRemoteInstance retrieves the Protos logs from an instance, via SSH

func (*Manager) NewProvider

func (cm *Manager) NewProvider(cloudName string, cloud string) (CloudProvider, error)

NewProvider creates and returns a cloud provider. At this point it is not saved in the db

func (*Manager) StartInstance

func (cm *Manager) StartInstance(id string) error

StartInstance starts an instance

func (*Manager) StopInstance

func (cm *Manager) StopInstance(id string) error

StopInstance stops an instance

func (*Manager) SupportedProviders

func (cm *Manager) SupportedProviders() []string

SupportedProviders returns a list of supported cloud providers

func (*Manager) TunnelInstance

func (cm *Manager) TunnelInstance(id string) error

TunnelInstance creates and SSH tunnel to the instance

func (*Manager) UpdateInstance

func (cm *Manager) UpdateInstance(id string, ip string) error

UpdateInstance updates an instance

func (*Manager) UploadLocalImage

func (cm *Manager) UploadLocalImage(imagePath string, imageName string, cloudName string, cloudLocation string, timeout time.Duration) error

UploadLocalImage uploads a local Protosd image to a specific cloud

type ProviderInfo

type ProviderInfo struct {
	CloudProviderImplementation

	ID   string
	Name string
	Type Type
	Auth map[string]string
	// contains filtered or unexported fields
}

ProviderInfo stores information about a cloud provider

func (ProviderInfo) GetInfo

func (pi ProviderInfo) GetInfo() ProviderInfo

GetInfo returns the ProviderInfo struct. Seems redundant but it's used via the Provider interface

func (ProviderInfo) NameStr

func (pi ProviderInfo) NameStr() string

NameStr returns the name of the cloud provider instance

func (ProviderInfo) Save

func (pi ProviderInfo) Save() error

Save saves the provider information to disk

func (ProviderInfo) TypeStr

func (pi ProviderInfo) TypeStr() string

TypeStr returns the cloud type formatted as string

type Type

type Type string

Type represents a specific cloud (AWS, GCP, DigitalOcean etc.)

func (Type) String

func (ct Type) String() string

type VolumeInfo

type VolumeInfo struct {
	VolumeID string
	Name     string
	Size     uint64
}

VolumeInfo holds information about a data volume

Jump to

Keyboard shortcuts

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