lxd

package
v0.0.0-...-7f8d8f8 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package lxd is our wrapper to the official lxd client

Index

Constants

This section is empty.

Variables

Conf is our main config

Functions

func CreateContainer

func CreateContainer(host string, name string, image string, storagepool string, options map[string]string) error

CreateContainer creates a container from the given image, with the provided name on the LXD host

func CreateFile

func CreateFile(host string, name string, path string, mode int, contents string) error

CreateFile creates a file or directory on the container. If the provided path ends in / we assume that we are creating a directory

func DeleteContainer

func DeleteContainer(host string, name string) error

DeleteContainer removes a container from a host

func ExecCommand

func ExecCommand(host string, name string, command []string) (float64, error)

ExecCommand runs a command on the container and discards the output. As further comments state, there doesn't seem to be an accurate return of success or not, need to look for a status code return. If a way is found, likely will stop discarding output and return that to the UI. -1 is our return if something outside the command went wrong

func GetContainerState

func GetContainerState(host string, name string) (*api.ContainerState, error)

GetContainerState calls out to our LXD host to get the state of the container. State has data like network info, memory usage, cpu seconds in use, running processes etc

func GetHostResources

func GetHostResources(host string) (map[string]HostResourceInfo, error)

GetHostResources grabs (the kind of limited) info about a host, available CPU cores, Memory, ...

func GetStoragePools

func GetStoragePools(host string) (map[string][]string, error)

GetStoragePools gets a list of all the storage pools available for each host

func IsManageable

func IsManageable(c ContainerInfo) bool

IsManageable just checks our lock flag, user.lxdepot_lock to see if it is "true" or not

func MoveContainer

func MoveContainer(srcHost string, dstHost string, name string) error

MoveContainer will move (copy in lxd speak) a container from one server to another.

func StartContainer

func StartContainer(host string, name string) error

StartContainer starts a stopped container

func StopContainer

func StopContainer(host string, name string) error

StopContainer stops a running container

Types

type ContainerInfo

type ContainerInfo struct {
	Host      *config.LXDhost     // Host details
	Container api.Container       // Container details returned from lxd.GetContainers
	State     *api.ContainerState // Container state from lxd.GetContainerState
	Usage     map[string]float64  // place to store usge conversions, like CPU usage
}

ContainerInfo is a conversion / grouping of useful container information as returned from the lxd client

func GetContainers

func GetContainers(host string, name string, getState bool) ([]ContainerInfo, error)

GetContainers asks for a list of containers from each LXD host, then optionally calls GetContainerState on each container to populate state information (IP, CPU / Memory / Disk usage, etc)

type DiscardCloser

type DiscardCloser struct{}

DiscardCloser is a WriteCloser that just discards data. When we exec commands on a container stdout, etc need some place to go, but at the moment we don't care about the data.

func (DiscardCloser) Close

func (DiscardCloser) Close() error

Close does nothing and is there just to satisfy the WriteCloser interface

func (DiscardCloser) Write

func (DiscardCloser) Write(b []byte) (int, error)

Write just sends its data to the io.Discard object

type HostResourceInfo

type HostResourceInfo struct {
	Host      *config.LXDhost
	Resources *api.Resources
}

HostResourceInfo is a group of Host and Resources as returned by lxd

type ImageInfo

type ImageInfo struct {
	Host         *config.LXDhost  // Host details
	Aliases      []api.ImageAlias // list of aliases this image goes by
	Architecture string           // x86_64, etc
	Fingerprint  string           // fingerprint hash of the image for comparison
}

ImageInfo like above is a grouping of useful image information for the frontend

func GetImages

func GetImages(host string) ([]ImageInfo, error)

GetImages calls each LXD host to get a list of images available on each

Jump to

Keyboard shortcuts

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