lxdclient

package
v0.0.0-...-2608902 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2016 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

Constants related to user metadata.

View Source
const (
	StatusStarting = "Starting"
	StatusStarted  = "Started"
	StatusRunning  = "Running"
	StatusFreezing = "Freezing"
	StatusFrozen   = "Frozen"
	StatusThawed   = "Thawed"
	StatusStopping = "Stopping"
	StatusStopped  = "Stopped"

	StatusOperationCreated = "Operation created"
	StatusPending          = "Pending"
	StatusAborting         = "Aborting"
	StatusCancelling       = "Canceling"
	StatusCancelled        = "Canceled"
	StatusSuccess          = "Success"
	StatusFailure          = "Failure"

	DefaultLXDBridge = "lxdbr0"
)

The various status values used for LXD.

View Source
const LXDBridgeFile = "/etc/default/lxd-bridge"

Variables

AliveStatuses are the LXD statuses that indicate a container is "alive".

View Source
var CloudImagesRemote = Remote{
	Name:          "cloud-images.ubuntu.com",
	Host:          "https://cloud-images.ubuntu.com/releases",
	Protocol:      SimplestreamsProtocol,
	Cert:          nil,
	ServerPEMCert: "",
}
View Source
var DefaultImageSources = []Remote{CloudImagesRemote}
View Source
var Local = Remote{
	Name: remoteLocalName,
	Host: "",

	Protocol:      LXDProtocol,
	Cert:          nil,
	ServerPEMCert: "",
}

Local is LXD's default "remote". Essentially it is an unencrypted, unauthenticated connection to localhost over a unix socket. However it does require users to be in the lxd group.

Functions

func IsInstalledLocally

func IsInstalledLocally() (bool, error)

IsInstalledLocally returns true if LXD is installed locally.

func IsRunningLocally

func IsRunningLocally() (bool, error)

IsRunningLocally returns true if LXD is running locally.

Types

type Cert

type Cert struct {
	// Name is the name that LXD will use for the cert.
	Name string

	// CertPEM is the PEM-encoded x.509 cert.
	CertPEM []byte

	// KeyPEM is the PEM-encoded x.509 private key.
	KeyPEM []byte
}

Cert holds the information for a single certificate a client may use to connect to a remote server.

func NewCert

func NewCert(certPEM, keyPEM []byte) Cert

NewCertificate creates a new Certificate for the given cert and key.

func (Cert) Fingerprint

func (cert Cert) Fingerprint() (string, error)

Fingerprint returns the cert's LXD fingerprint.

func (Cert) Validate

func (cert Cert) Validate() error

Validate ensures that the cert is valid.

func (Cert) WithDefaults

func (cert Cert) WithDefaults() (Cert, error)

WithDefaults updates a copy of the remote with default values where needed.

func (Cert) WriteCertPEM

func (cert Cert) WriteCertPEM(out io.Writer) error

WriteCertPEM writes the cert's x.509 PEM data to the given writer.

func (Cert) WriteKeyPEM

func (cert Cert) WriteKeyPEM(out io.Writer) error

WriteKeytPEM writes the key's x.509 PEM data to the given writer.

func (Cert) X509

func (cert Cert) X509() (*x509.Certificate, error)

X509 returns the x.509 certificate.

type Client

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

Client is a high-level wrapper around the LXD API client.

func Connect

func Connect(cfg Config) (*Client, error)

Connect opens an API connection to LXD and returns a high-level Client wrapper around that connection.

func (Client) AddCert

func (c Client) AddCert(cert Cert) error

AddCert adds the given certificate to the server.

func (Client) AddInstance

func (client Client) AddInstance(spec InstanceSpec) (*Instance, error)

AddInstance creates a new instance based on the spec's data and returns it. The instance will be created using the client.

func (Client) Addresses

func (client Client) Addresses(name string) ([]network.Address, error)

Addresses returns the list of network.Addresses for this instance. It converts the information that LXD tracks into the Juju network model.

func (Client) CreateProfile

func (p Client) CreateProfile(name string, config map[string]string) error

CreateProfile attempts to create a new lxc profile and set the given config.

func (Client) EnsureImageExists

func (i Client) EnsureImageExists(series string, sources []Remote, copyProgressHandler func(string)) error

EnsureImageExists makes sure we have a local image so we can launch a container. @param series: OS series (trusty, precise, etc) @param architecture: (TODO) The architecture of the image we want to use @param trustLocal: (TODO) check if we already have an image with the right alias. Setting this to False means we will always check the remote sources and only launch the newest version. @param sources: a list of Remotes that we will look in for the image. @param copyProgressHandler: a callback function. If we have to download an image, we will call this with messages indicating how much of the download we have completed (and where we are downloading it from).

func (Client) HasProfile

func (p Client) HasProfile(name string) (bool, error)

HasProfile returns true/false if the profile exists.

func (Client) ImageNameForSeries

func (i Client) ImageNameForSeries(series string) string

A common place to compute image names (aliases) based on the series

func (Client) Instance

func (client Client) Instance(name string) (*Instance, error)

Instance gets the up-to-date info about the given instance and returns it.

func (Client) Instances

func (client Client) Instances(prefix string, statuses ...string) ([]Instance, error)

Instances sends a request to the API for a list of all instances (in the Client's namespace) for which the name starts with the provided prefix. The result is also limited to those instances with one of the specified statuses (if any).

func (Client) ListCerts

func (c Client) ListCerts() ([]string, error)

ListCerts returns the list of cert fingerprints from the server.

func (Client) ProfileDelete

func (p Client) ProfileDelete(profile string) error

ProfileDelete deletes an existing profile. No check is made to verify the profile exists.

func (Client) ProfileDeviceAdd

func (p Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*lxd.Response, error)

ProfileDeviceAdd adds a profile device, such as a disk or a nic, to the specified profile. No check is made to verify the profile exists.

func (Client) RemoveCert

func (c Client) RemoveCert(cert *Cert) error

RemoveCert removes the cert from the server.

func (Client) RemoveCertByFingerprint

func (c Client) RemoveCertByFingerprint(fingerprint string) error

RemoveCertByFingerprint removes the cert from the server.

func (Client) RemoveInstances

func (client Client) RemoveInstances(prefix string, names ...string) error

RemoveInstances sends a request to the API to terminate all instances (in the Client's namespace) that match one of the provided IDs. If a prefix is provided, only IDs that start with the prefix will be considered. The call blocks until all the instances are removed or the request fails.

func (Client) ServerStatus

func (c Client) ServerStatus() (*shared.ServerState, error)

func (Client) SetConfig

func (c Client) SetConfig(key, value string) error

SetConfig sets the given value in the server's config.

func (Client) Status

func (client Client) Status(name string) (string, error)

func (Client) String

func (c Client) String() string

type Config

type Config struct {
	// Namespace identifies the namespace to associate with containers
	// and other resources with which the client interacts. It may be
	// blank.
	// TODO(jam) This doesn't appear to do much at the moment.
	Namespace string

	// Remote identifies the remote server to which the client should
	// connect. For the default "remote" use Local.
	Remote Remote
}

Config contains the config values used for a connection to the LXD API.

func (Config) UsingTCPRemote

func (cfg Config) UsingTCPRemote() (Config, error)

UsingTCPRemote converts the config into a "non-local" version. An already non-local remote is left alone.

For a "local" remote (see Local), the remote is changed to a one with the host set to the IP address of the local lxcbr0 bridge interface. The LXD server is also set up for remote access, exposing the TCP port and adding a certificate for remote access.

func (Config) Validate

func (cfg Config) Validate() error

Validate checks the client's fields for invalid values.

func (Config) WithDefaults

func (cfg Config) WithDefaults() (Config, error)

WithDefaults updates a copy of the config with default values where needed.

type Instance

type Instance struct {
	InstanceSummary
	// contains filtered or unexported fields
}

Instance represents a single realized LXD container.

func NewInstance

func NewInstance(summary InstanceSummary, spec *InstanceSpec) *Instance

NewInstance builds an instance from the provided summary and spec and returns it.

func (Instance) CurrentStatus

func (gi Instance) CurrentStatus(client *Client) (string, error)

CurrentStatus returns a string identifying the status of the instance.

func (Instance) Metadata

func (gi Instance) Metadata() map[string]string

Metadata returns the user-specified metadata for the instance.

func (Instance) Status

func (gi Instance) Status() string

Status returns a string identifying the status of the instance.

type InstanceHardware

type InstanceHardware struct {
	// Architecture is the CPU architecture.
	Architecture string

	// NumCores is the number of CPU cores.
	NumCores uint

	// MemoryMB is the memory allocation for the container.
	MemoryMB uint

	// RootDiskMB is the size of the root disk, in MB.
	RootDiskMB uint64
}

InstanceHardware describes the hardware characteristics of a LXC container.

type InstanceSpec

type InstanceSpec struct {
	// Name is the "name" of the instance.
	Name string

	// Image is the name of the image to use.
	Image string

	// ImageRemote identifies the remote to use for images. By default
	// the client's remote is used.
	ImageRemote string

	// Profiles are the names of the container profiles to apply to the
	// new container, in order.
	Profiles []string

	// Ephemeral indicates whether or not the container should be
	// destroyed when the LXD host is restarted.
	Ephemeral bool

	// Metadata is the instance metadata.
	Metadata map[string]string
}

InstanceSpec holds all the information needed to create a new LXD container.

func (InstanceSpec) Summary

func (spec InstanceSpec) Summary(namespace string) InstanceSummary

Summary builds an InstanceSummary based on the spec and returns it.

type InstanceSummary

type InstanceSummary struct {
	// Name is the "name" of the instance.
	Name string

	// Status holds the status of the instance at a certain point in time.
	Status string

	// Hardware describes the instance's hardware characterstics.
	Hardware InstanceHardware

	// Metadata is the instance metadata.
	Metadata map[string]string
}

InstanceSummary captures all the data needed by Instance.

type Protocol

type Protocol string
const (
	LXDProtocol           Protocol = "lxd"
	SimplestreamsProtocol Protocol = "simplestreams"
)

type Remote

type Remote struct {
	// Name is a label for this remote.
	Name string

	// Host identifies the host to which the client should connect.
	// An empty string is interpreted as:
	//   "localhost over a unix socket (unencrypted)".
	Host string

	// Protocol indicates whether this Remote is accessed via the normal
	// "LXD" protocol, or whether it is a Simplestreams source. The value
	// is only useful for Remotes that are image sources
	Protocol Protocol

	// Cert holds the TLS certificate data for the client to use.
	Cert *Cert

	// ServerPEMCert is the certificate to be supplied as the acceptable
	// server certificate when connecting to the remote.
	ServerPEMCert string
}

Remote describes a LXD "remote" server for a client. In particular it holds the information needed for the client to connect to the remote.

func (Remote) ID

func (r Remote) ID() string

ID identifies the remote to the raw LXD client code. For the non-local case this is Remote.Name. For the local case it is the remote name that LXD special-cases for the local unix socket.

func (Remote) UsingTCP

func (r Remote) UsingTCP() (Remote, error)

UsingTCP converts the remote into a non-local version. For non-local remotes this is a no-op.

For a "local" remote (see Local), the remote is changed to a one with the host set to the IP address of the local lxcbr0 bridge interface. The remote is also set up for remote access, setting the cert if not already set.

func (Remote) Validate

func (r Remote) Validate() error

Validate checks the Remote fields for invalid values.

func (Remote) WithDefaults

func (r Remote) WithDefaults() (Remote, error)

WithDefaults updates a copy of the remote with default values where needed.

Jump to

Keyboard shortcuts

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