Documentation
¶
Index ¶
- Constants
- Variables
- func IsInstalledLocally() (bool, error)
- func IsRunningLocally() (bool, error)
- type Cert
- type Client
- func (c Client) AddCert(cert Cert) error
- func (client Client) AddInstance(spec InstanceSpec) (*Instance, error)
- func (client Client) Addresses(name string) ([]network.Address, error)
- func (p Client) CreateProfile(name string, config map[string]string) error
- func (i Client) EnsureImageExists(series string) error
- func (p Client) HasProfile(name string) (bool, error)
- func (i Client) ImageNameForSeries(series string) string
- func (client Client) Instance(name string) (*Instance, error)
- func (client Client) Instances(prefix string, statuses ...string) ([]Instance, error)
- func (c Client) ListCerts() ([]string, error)
- func (c Client) RemoveCert(cert *Cert) error
- func (c Client) RemoveCertByFingerprint(fingerprint string) error
- func (client Client) RemoveInstances(prefix string, names ...string) error
- func (c Client) ServerStatus() (*shared.ServerState, error)
- func (c Client) SetConfig(key, value string) error
- func (client Client) Status(name string) (string, error)
- type Config
- type ImageStream
- type Instance
- type InstanceHardware
- type InstanceSpec
- type InstanceSummary
- type Remote
Constants ¶
const ( MetadataNamespace = "user" // This is defined by the cloud-init code: // http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/cloudinit/sources/ // http://cloudinit.readthedocs.org/en/latest/ // Also see https://github.com/lxc/lxd/blob/master/specs/configuration.md. UserdataKey = "user-data" )
Constants related to user metadata.
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" )
The various status values used for LXD.
Variables ¶
var AliveStatuses = []string{ StatusStarting, StatusStarted, StatusRunning, }
AliveStatuses are the LXD statuses that indicate a container is "alive".
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 ¶
IsInstalledLocally returns true if LXD is installed 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 ¶
NewCertificate creates a new Certificate for the given cert and key.
func (Cert) Fingerprint ¶
Fingerprint returns the cert's LXD fingerprint.
func (Cert) WithDefaults ¶
WithDefaults updates a copy of the remote with default values where needed.
func (Cert) WriteCertPEM ¶
WriteCertPEM writes the cert's x.509 PEM data to the given writer.
func (Cert) WriteKeyPEM ¶
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 ¶
Connect opens an API connection to LXD and returns a high-level Client wrapper around that connection.
func (Client) AddCert ¶
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 ¶
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 ¶
CreateProfile attempts to create a new lxc profile and set the given config.
func (Client) HasProfile ¶
HasProfile returns true/false if the profile exists.
func (Client) ImageNameForSeries ¶
A common place to compute image names (alises) based on the series
func (Client) Instance ¶
Instance gets the up-to-date info about the given instance and returns it.
func (Client) Instances ¶
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 ¶
ListCerts returns the list of cert fingerprints from the server.
func (Client) RemoveCert ¶
RemoveCert removes the cert from the server.
func (Client) RemoveCertByFingerprint ¶
RemoveCertByFingerprint removes the cert from the server.
func (Client) RemoveInstances ¶
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 ¶
SetConfig sets the given value in the server's config.
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
// ImageStream can be either blank (""), "released", or "daily".
// This decides what Ubuntu stream we will use for LXD images.
ImageStream ImageStream
// 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 ¶
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 ¶
Validate checks the client's fields for invalid values.
type ImageStream ¶
type ImageStream string
const ( StreamUnknown ImageStream = "" StreamReleased ImageStream = "released" StreamDaily ImageStream = "daily" )
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 ¶
CurrentStatus returns a string identifying the status of the instance.
func (Instance) Metadata ¶
Metadata returns the user-specified metadata for 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 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
// 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 ¶
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 ¶
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 ¶
Validate checks the Remote fields for invalid values.
Source Files
¶
- addserver.go
- cert.go
- client.go
- client_cert.go
- client_image.go
- client_instance.go
- client_profile.go
- client_raw.go
- client_serverconfig.go
- config.go
- instance.go
- lxd_client.go
- remote.go
- utils.go