Documentation ¶
Index ¶
- Constants
- Variables
- func CreateDefaultBridgeInDefaultProfile(client creator) error
- func EnableHTTPSListener(client interface{ ... }) error
- func IsInstalledLocally() (bool, error)
- func IsRunningLocally() (bool, error)
- func ResolveConfigKey(name string, namespace ...string) string
- 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 (client Client) AttachDisk(instanceName, deviceName string, disk DiskDevice) error
- func (c Client) CertByFingerprint(fingerprint string) (api.Certificate, error)
- func (p Client) CreateProfile(name string, config map[string]string) error
- func (c Client) DefaultProfileBridgeName() string
- func (i Client) EnsureImageExists(series, arch string, sources []Remote, copyProgressHandler func(string)) (string, error)
- func (p Client) GetProfileConfig(profile string) (map[string]string, error)
- func (p Client) HasProfile(name string) (bool, error)
- func (client Client) Instance(name string) (*Instance, error)
- func (client Client) Instances(prefix string, statuses ...string) ([]Instance, error)
- func (c Client) NetworkCreate(name string, config map[string]string) error
- func (c Client) NetworkGet(name string) (api.Network, error)
- func (p Client) ProfileConfig(profile string) (*api.Profile, error)
- func (p Client) ProfileDelete(profile string) error
- func (p Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*api.Response, error)
- func (c Client) RemoveCertByFingerprint(fingerprint string) error
- func (client Client) RemoveDevice(instanceName, deviceName string) error
- func (client Client) RemoveInstances(prefix string, names ...string) error
- func (c Client) ServerAddresses() ([]string, error)
- func (c Client) ServerStatus() (*api.Server, error)
- func (c Client) SetContainerConfig(container, key, value string) error
- func (p Client) SetProfileConfigItem(profile, key, value string) error
- func (c Client) SetServerConfig(key, value string) error
- func (client Client) Status(name string) (string, error)
- func (c Client) StorageSupported() bool
- func (c Client) String() string
- func (c Client) VolumeCreate(pool, volume string, config map[string]string) error
- func (c Client) VolumeDelete(pool, volume string) error
- func (c Client) VolumeList(pool string) ([]api.StorageVolume, error)
- type Config
- type Device
- type Devices
- type DiskDevice
- 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" // CertificateFingerprintKey is a key that we define to associate // a certificate fingerprint with an instance. We use this to clean // up certificates when removing controller instances. CertificateFingerprintKey = "certificate-fingerprint" )
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 CloudImagesDailyRemote = Remote{ Name: "cloud-images.ubuntu.com", Host: "https://cloud-images.ubuntu.com/daily", Protocol: SimplestreamsProtocol, Cert: nil, ServerPEMCert: "", }
The "daily" stream. This consists of images that are built from the daily * package builds. These images have not been independently tested, but in * theory "should" be good, since they're build from packages from the released * archive.
var CloudImagesRemote = Remote{ Name: "cloud-images.ubuntu.com", Host: "https://cloud-images.ubuntu.com/releases", Protocol: SimplestreamsProtocol, Cert: nil, ServerPEMCert: "", }
The "releases" stream for images. This consists of blessed releases by the * Canonical team.
var DefaultImageSources = []Remote{CloudImagesRemote, CloudImagesDailyRemote}
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 CreateDefaultBridgeInDefaultProfile ¶
func CreateDefaultBridgeInDefaultProfile(client creator) error
CreateDefaultBridgeInDefaultProfile creates a default bridge if it doesn't exist and (if necessary) inserts it into the default profile.
func EnableHTTPSListener ¶
func EnableHTTPSListener(client interface { ServerStatus() (*api.Server, error) SetServerConfig(k, v string) error }) error
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.
func ResolveConfigKey ¶
ResolveConfigKey applies the specified namespaces to the config key name to return the fully-qualified key.
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) AttachDisk ¶
func (client Client) AttachDisk(instanceName, deviceName string, disk DiskDevice) error
AttachDisk attaches a disk to an instance.
func (Client) CertByFingerprint ¶
func (c Client) CertByFingerprint(fingerprint string) (api.Certificate, error)
CertByFingerprint returns information about a certificate with the matching fingerprint. If there is no such certificate, an error satisfying errors.IsNotFound is returned.
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, arch string, sources []Remote, copyProgressHandler func(string), ) (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: 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) 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) NetworkCreate ¶
NetworkCreate creates the specified network.
func (Client) NetworkGet ¶
NetworkGet returns the specified network's configuration.
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) (*api.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) RemoveCertByFingerprint ¶
RemoveCertByFingerprint removes the cert from the server.
func (Client) RemoveDevice ¶
RemoveDevice removes a device from an instance.
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) ServerAddresses ¶
ServerAddresses reports the addresses that the server is listening on.
func (Client) ServerStatus ¶
ServerStatus reports the state of the server.
func (Client) SetContainerConfig ¶
SetContainerConfig sets the given config value for the specified container.
func (Client) SetProfileConfigItem ¶
SetProfileConfigItem updates the given profile config key to the given value.
func (Client) SetServerConfig ¶
SetServerConfig sets the given value in the server's config.
func (Client) StorageSupported ¶
func (c Client) StorageSupported() bool
StorageSupported reports whether or not storage is supported by the LXD remote.
func (Client) VolumeCreate ¶
VolumeCreate creates a volume in a storage pool.
func (Client) VolumeDelete ¶
VolumeDelete deletes a volume from a storage pool.
func (Client) VolumeList ¶
func (c Client) VolumeList(pool string) ([]api.StorageVolume, error)
VolumeList lists volumes in a storage pool, excluding any non-custom type volumes.
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) Disks ¶
func (i *Instance) Disks() map[string]DiskDevice
Disks returns the disk devices attached to 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 // Devices is the instance's devices. Devices map[string]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.