platform

package
v0.0.0-...-95fffc9 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDevice

func AddDevice(lxdServer lxd.InstanceServer, unitName string, devname string, devSettings map[string]string) error

AddDevice adds an external device to a unit with the given devSettings

func AddRemote

func AddRemote(remote Remote, password string) error

AddRemote adds remote LXC host

func AttachNetwork

func AttachNetwork(lxdServer lxd.InstanceServer, name string, bridge string, nic1 string, nic2 string) error

AttachNetwork attaches unit to internal network bridge

func CheckHostPorts

func CheckHostPorts(hostURL string, forwardedPorts []string) (err error)

CheckHostPorts ensures required forwarded ports are free by attempting to connect. If a connection is established the port is already taken

func CheckMemory

func CheckMemory(lxdServer lxd.InstanceServer, ramString string) error

CheckMemory checks if the LXD server host has sufficient RAM to deploy requested unit

func CheckStoragePoolSpace

func CheckStoragePoolSpace(lxdServer lxd.InstanceServer, storagePool string, requestedSpace int64) (err error)

func ConfigDevice

func ConfigDevice(lxdServer lxd.InstanceServer, name string, nic string, ip string) error

ConfigDevice sets IP address lxc config device set [remote]:name eth0 ipv4.address

func ConfigureHost

func ConfigureHost(settings HostSettings, remote Remote) error

ConfigureHost configures local bravetools host and updates resources

func CopyDirectory

func CopyDirectory(lxdServer lxd.InstanceServer, name string, src, dst string) error

CopyDirectory recursively copies a src directory to a destination.

func CopyFiles

func CopyFiles(lxdServer lxd.InstanceServer, name string, src, dst string) error

CopyFiles copies a src file to a dst file where src and dst are regular files.

func CopyImage

func CopyImage(sourceServer lxd.InstanceServer, destServer lxd.InstanceServer, fingerprint string, alias string) error

func CreateStoragePool

func CreateStoragePool(lxdServer lxd.InstanceServer, name string, size string) error

CreateStoragePool creates a new storage pool

func DeleteDevice

func DeleteDevice(lxdServer lxd.InstanceServer, name string, target string) (string, error)

DeleteDevice unmounts a disk

func DeleteImageByFingerprint

func DeleteImageByFingerprint(lxdServer lxd.InstanceServer, fingerprint string) error

DeleteImageFingerprint delete unit image lxc image delete [remote]:[name]

func DeleteNetwork

func DeleteNetwork(lxdServer lxd.InstanceServer, name string) error

DeleteNetwork ..

func DeleteProfile

func DeleteProfile(lxdServer lxd.InstanceServer, name string) error

DeleteProfile ..

func DeleteStoragePool

func DeleteStoragePool(lxdServer lxd.InstanceServer, name string) error

DeleteStoragePool ..

func DeleteUnit

func DeleteUnit(lxdServer lxd.InstanceServer, name string) error

Delete deletes a unit on a LXD remote

func DeleteVolume

func DeleteVolume(lxdServer lxd.InstanceServer, pool string, volume api.StorageVolume) error

DeleteVolume ..

func Exec

func Exec(ctx context.Context, lxdServer lxd.InstanceServer, name string, command []string, arg ExecArgs) (returnCode int, err error)

Exec runs command inside unit

func ExportBravetoolsImage

func ExportBravetoolsImage(image string, outputDir string) error

func ExportImage

func ExportImage(lxdServer lxd.ImageServer, fingerprint string, name string) error

ExportImage downloads unit image into current directory

func FilePush

func FilePush(lxdServer lxd.InstanceServer, name string, sourceFile string, targetPath string) error

FilePush copies local file into unit

func GetBraveProfile

func GetBraveProfile(lxdServer lxd.InstanceServer, profileName string) (braveProfile shared.BraveProfile, err error)

GetBraveProfile ..

func GetBravefileFromLXD

func GetBravefileFromLXD(name string) (*shared.Bravefile, error)

GetBravefileFromLXD generates a Bravefile for import of images from an LXD server

func GetBravetoolsBridgeIP

func GetBravetoolsBridgeIP(lxdServer lxd.InstanceServer, bridgeName string) (string, error)

func GetFingerprintByAlias

func GetFingerprintByAlias(lxdServer lxd.ImageServer, alias string, architecture string) (fingerprint string, err error)

GetFingerprintByAlias retrieves image fingerprint corresponding to provided alias

func GetImageByAlias

func GetImageByAlias(lxdImageServer lxd.ImageServer, alias string, architecture string) (image *api.Image, err error)

GetImageByAlias retrieves image by name

func GetImages

func GetImages(lxdServer lxd.ImageServer) ([]api.Image, error)

GetImages returns all images from host

func GetLXDImageSever

func GetLXDImageSever(remote Remote) (lxd.ImageServer, error)

func GetLXDInstanceServer

func GetLXDInstanceServer(remote Remote) (lxd.InstanceServer, error)

GetLXDInstanceServer ..

func GetLXDServerArch

func GetLXDServerArch(lxdServer lxd.InstanceServer) (string, error)

func GetLXDServerVersion

func GetLXDServerVersion(lxdServer lxd.InstanceServer) (int, error)

GetLXDServerVersion retrieves server semantic version and converts to integer

func GetSimplestreamsLXDSever

func GetSimplestreamsLXDSever(url string, args *lxd.ConnectionArgs) (lxd.ImageServer, error)

func GetUnits

func GetUnits(lxdServer lxd.InstanceServer, profileName string) (units []shared.BraveUnit, err error)

GetUnits returns all running units

func GetVolume

func GetVolume(lxdServer lxd.InstanceServer, pool string) (volume api.StorageVolume, err error)

GetVolume ..

func ImportImage

func ImportImage(lxdServer lxd.InstanceServer, imageTar string, nameAndVersion string) (fingerprint string, err error)

ImportImage imports image from current directory

func LaunchFromImage

func LaunchFromImage(destServer lxd.InstanceServer, sourceServer lxd.ImageServer, imageName string, containerName string, profileName string, storagePool string) (fingerprint string, err error)

LaunchFromImage creates new unit based on image

func ListRemotes

func ListRemotes() (names []string, err error)

func MountDirectory

func MountDirectory(lxdServer lxd.InstanceServer, sourcePath string, destUnit string, destPath string) error

MountDirectory mounts local directory to unit

func ParseRemoteName

func ParseRemoteName(image string) (remote string, imageName string)

ParseRemoteName unpacks remote and rest of image/service name and returns both

func Publish

func Publish(lxdServer lxd.InstanceServer, name string, image string) (fingerprint string, err error)

Publish unit lxc publish -f [remote]:[name] [remote]: --alias image

func Push

func Push(lxdServer lxd.InstanceServer, name string, sourcePath string, targetPath string) error

Push ..

func RemoveRemote

func RemoveRemote(name string) error

RemoveRemote removes remote LXC host

func SaveRemote

func SaveRemote(remote Remote) error

func SetActiveStoragePool

func SetActiveStoragePool(lxdServer lxd.InstanceServer, name string) error

SetActiveStoragePool pool assigns a profile with default storage

func SetConfig

func SetConfig(lxdServer lxd.InstanceServer, name string, config map[string]string) error

SetConfig sets unit parameters

func Start

func Start(lxdServer lxd.InstanceServer, name string) error

Start unit

func Stop

func Stop(lxdServer lxd.InstanceServer, name string) error

Stop unit

func SymlinkPush

func SymlinkPush(lxdServer lxd.InstanceServer, name string, sourceFile string, targetPath string) error

SymlinkPush copies a symlink into unit

func TransferImage

func TransferImage(sourceRemote Remote, bravefile shared.Bravefile) error

func UpdateBraveSettings

func UpdateBraveSettings(settings HostSettings) error

UpdateBraveSettings configuration in place and write to config.yaml

func UpdateDevice

func UpdateDevice(lxdServer lxd.InstanceServer, unitName string, deviceName string, deviceSettings map[string]string) error

UpdateDevice updates the deviceSettings of an existing device - existing config remains unchanged unless overwritten by a matching key in the provided deviceSettings

Types

type Backend

type Backend interface {
	BraveBackendInit() error
	Info() (Info, error)
	Running() (bool, error)
	Start() error
}

Backend ..

func NewHostBackend

func NewHostBackend(hostSettings HostSettings) (backend Backend, err error)

NewHostBackend returns a new Backend from provided host Settings

type BackendResources

type BackendResources struct {
	Name string `yaml:"name"`
	OS   string `yaml:"os"`
	CPU  string `yaml:"cpu"`
	RAM  string `yaml:"ram"`
	HD   string `yaml:"hd"`
	IP   string `yaml:"ip"`
}

BackendResources ..

type BackendSettings

type BackendSettings struct {
	Type      string           `yaml:"type"`
	Resources BackendResources `yaml:"resources"`
}

BackendSettings ..

type BraveHost

type BraveHost struct {
	Settings HostSettings `yaml:"settings"`
	Remote   Remote
	Backend  Backend
}

BraveHost ..

func NewBraveHost

func NewBraveHost() (*BraveHost, error)

NewBraveHost returns Brave host

func (*BraveHost) AddRemote

func (bh *BraveHost) AddRemote() error

AddRemote sets connection to Brave platform

func (*BraveHost) BuildImage

func (bh *BraveHost) BuildImage(bravefile shared.Bravefile) error

BuildImage creates an image based on Bravefile

func (*BraveHost) Compose

func (bh *BraveHost) Compose(backend Backend, composeFile *shared.ComposeFile) (err error)

func (*BraveHost) DeleteLocalImage

func (bh *BraveHost) DeleteLocalImage(name string, legacy bool) error

DeleteLocalImage deletes a local image

func (*BraveHost) DeleteUnit

func (bh *BraveHost) DeleteUnit(name string) error

DeleteUnit ..

func (*BraveHost) GetUnitNames

func (bh *BraveHost) GetUnitNames() []string

GetUnitNames returns a list of all unit names, including remote units. Errors encountered will result in skipping the faulty remote's units.

func (*BraveHost) HostInfo

func (bh *BraveHost) HostInfo(short bool) error

HostInfo returns useful information about brave host

func (*BraveHost) ImportLocalImage

func (bh *BraveHost) ImportLocalImage(sourcePath string) error

ImportLocalImage import tarball into local images folder

func (*BraveHost) InitUnit

func (bh *BraveHost) InitUnit(backend Backend, unitParams shared.Service) (err error)

InitUnit starts unit from supplied image

func (*BraveHost) ListAllMounts

func (bh *BraveHost) ListAllMounts() error

func (*BraveHost) ListMounts

func (bh *BraveHost) ListMounts(unitName string) error

func (*BraveHost) MountShare

func (bh *BraveHost) MountShare(source string, destUnit string, destPath string) error

MountShare ..

func (*BraveHost) PrintLocalImages

func (bh *BraveHost) PrintLocalImages() error

PrintLocalImages prints the images in image store

func (*BraveHost) PrintUnits

func (bh *BraveHost) PrintUnits(backend Backend, remoteName string) error

PrintUnits prints all LXD containers on remote host

func (*BraveHost) PublishUnit

func (bh *BraveHost) PublishUnit(unitName string, imageName string) error

PublishUnit publishes unit to image

func (*BraveHost) StartUnit

func (bh *BraveHost) StartUnit(name string) error

StartUnit restarts unit if running and starts if stopped.

func (*BraveHost) StopUnit

func (bh *BraveHost) StopUnit(name string) error

StopUnit stops unit using name

func (*BraveHost) UmountShare

func (bh *BraveHost) UmountShare(unit string, target string) error

UmountShare ..

type BravetoolsImage

type BravetoolsImage struct {
	Name         string
	Version      string
	Architecture string
	// contains filtered or unexported fields
}

func GetLocalImages

func GetLocalImages() (images []BravetoolsImage, err error)

func ImageFromFilename

func ImageFromFilename(filename string) (BravetoolsImage, error)

func ImageFromLegacyFilename

func ImageFromLegacyFilename(filename string) (BravetoolsImage, error)

func ParseImageString

func ParseImageString(imageString string) (imageStruct BravetoolsImage, err error)

func ParseLegacyImageString

func ParseLegacyImageString(imageString string) (imageStruct BravetoolsImage, err error)

func (BravetoolsImage) String

func (imageStruct BravetoolsImage) String() string

func (BravetoolsImage) ToBasename

func (imageStruct BravetoolsImage) ToBasename() string

type DummyBackend

type DummyBackend struct {
	Settings HostSettings
}

DummyBackend is a non-functional backend

func (*DummyBackend) BraveBackendInit

func (d *DummyBackend) BraveBackendInit() error

func (*DummyBackend) Info

func (d *DummyBackend) Info() (Info, error)

func (*DummyBackend) Running

func (d *DummyBackend) Running() (bool, error)

func (*DummyBackend) Start

func (d *DummyBackend) Start() error

type ExecArgs

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

type HostConfig

type HostConfig struct {
	Ram     string
	Network string
	Storage string
	Backend string
}

type HostSettings

type HostSettings struct {
	Name            string          `yaml:"name"`
	Trust           string          `yaml:"trust"`
	Profile         string          `yaml:"profile"`
	StoragePool     Storage         `yaml:"storage"`
	Network         Network         `yaml:"network"`
	BackendSettings BackendSettings `yaml:"backendsettings"`
	Status          string          `yaml:"status"`
}

HostSettings configuration data loaded from config.yaml

func SetupHostConfiguration

func SetupHostConfiguration(params HostConfig, userHome string) (settings HostSettings)

SetupHostConfiguration creates configuration file and saves it in bravetools directory

type ImageExistsError

type ImageExistsError struct {
	Name string
}

func (*ImageExistsError) Error

func (e *ImageExistsError) Error() string

type Info

type Info struct {
	ImageStorage  string
	VolumeStorage string
	Name          string
	State         string
	IPv4          string
	Release       string
	ImageHash     string
	Load          string
	Disk          StorageUsage
	Memory        StorageUsage
	CPU           string
}

Info describes Brave Platform

func NewInfo

func NewInfo() Info

type Lxd

type Lxd struct {
	Settings *HostSettings
}

Lxd ..

func NewLxd

func NewLxd(settings HostSettings) *Lxd

NewLxd constructor

func (Lxd) BraveBackendInit

func (vm Lxd) BraveBackendInit() error

BraveBackendInit ..

func (Lxd) Info

func (vm Lxd) Info() (Info, error)

Info ..

func (Lxd) Running

func (vm Lxd) Running() (bool, error)

Running returns whether backend is running

func (Lxd) Start

func (vm Lxd) Start() error

Start starts the backend if it is not already running

type LxdStatus

type LxdStatus int

LxdStatus enum

const (
	NotInstalled LxdStatus = iota
	NotInitialised
	Incompatible
	Installed
)

LxdStatus constants

type Multipass

type Multipass struct {
	Settings HostSettings
}

Multipass type defines local dev VM

func NewMultipass

func NewMultipass(settings HostSettings) *Multipass

NewMultipass constructor

func (Multipass) BraveBackendInit

func (vm Multipass) BraveBackendInit() error

BraveBackendInit creates a new instance of BraveAI host

func (Multipass) BraveHostDelete

func (vm Multipass) BraveHostDelete() error

BraveHostDelete removes BraveAI host

func (Multipass) Info

func (vm Multipass) Info() (backendInfo Info, err error)

Info shows all VMs and their state

func (Multipass) Running

func (vm Multipass) Running() (bool, error)

Info shows all VMs and their state

func (Multipass) Start

func (vm Multipass) Start() error

Start starts the backend if it is not already running

type Network

type Network struct {
	Name string `yaml:"name"`
	IP   string `yaml:"ip"`
}

Network ..

type Remote

type Remote struct {
	Name     string `json:"name"`
	URL      string `json:"url"`
	Protocol string `json:"protocol"`
	Public   bool   `json:"public"`
	Profile  string `json:"profile"`
	Network  string `json:"network"`
	Storage  string `json:"storage"`
	// contains filtered or unexported fields
}

Remote represents a configuration of the remote

func LoadRemoteSettings

func LoadRemoteSettings(remoteName string) (Remote, error)

LoadRemoteSettings loads a saved bravetools remote with TLS auth certs/keys if present

func NewBravehostRemote

func NewBravehostRemote(settings HostSettings) Remote

type Storage

type Storage struct {
	Type string `yaml:"type"`
	Name string `yaml:"name"`
	Size string `yaml:"size"`
}

Storage ..

type StorageUsage

type StorageUsage struct {
	UsedStorage  string
	TotalStorage string
}

Jump to

Keyboard shortcuts

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