Documentation ¶
Index ¶
- Constants
- Variables
- func EnableHTTPSListener(client interface{ ... }) error
- 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 (c Client) DefaultProfileBridgeName() string
- func (i Client) EnsureImageExists(series string, sources []Remote, copyProgressHandler func(string)) error
- func (p Client) GetProfileConfig(profile string) (map[string]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 (p Client) ProfileDelete(profile string) error
- func (p Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*lxd.Response, 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 (p Client) SetProfileConfigItem(profile, key, value string) error
- func (client Client) Status(name string) (string, error)
- func (c Client) String() string
- type Config
- type Device
- type Devices
- type File
- type Files
- type Instance
- type InstanceHardware
- type InstanceSpec
- type InstanceSummary
- type Protocol
- 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.
const LXDBridgeFile = "/etc/default/lxd-bridge"
Variables ¶
var AliveStatuses = []string{ StatusStarting, StatusStarted, StatusRunning, StatusStopping, StatusStopped, }
AliveStatuses are the LXD statuses that indicate a container is "alive".
var CloudImagesRemote = Remote{ Name: "cloud-images.ubuntu.com", Host: "https://cloud-images.ubuntu.com/releases", Protocol: SimplestreamsProtocol, Cert: nil, ServerPEMCert: "", }
var DefaultImageSources = []Remote{CloudImagesRemote}
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 EnableHTTPSListener ¶
EnableHTTPSListener configures LXD to listen for HTTPS requests, rather than only via the Unix socket.
func IsInstalledLocally ¶
IsInstalledLocally returns true if LXD is installed locally.
func IsRunningLocally ¶
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 (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.
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) 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) DefaultProfileBridgeName ¶
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) GetProfileConfig ¶
GetProfileConfig returns a map with all keys and values for the given profile.
func (Client) HasProfile ¶
HasProfile returns true/false if the profile exists.
func (Client) ImageNameForSeries ¶
A common place to compute image names (aliases) based on the series
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) ProfileDelete ¶
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 ¶
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) SetProfileConfigItem ¶
SetProfileConfigItem updates the given profile config key to the given value.
type Config ¶
type Config struct { // 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) WithDefaults ¶
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 ¶
CurrentStatus 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 // Devices to be added at container initialisation time. Devices // Files to be pushed after initialisation has completed but // before the container is started. Files }
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 // 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 ¶
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) WithDefaults ¶
WithDefaults updates a copy of the remote with default values where needed.