Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigureLXDProxies(proxies proxy.Settings) error
- func ConnectRemote(spec ServerSpec) (lxd.ContainerServer, error)
- func DevicesFromInterfaceInfo(interfaces corenetwork.InterfaceInfos) (map[string]device, []string, error)
- func EnsureHTTPS(address string) string
- func EnsureHostPort(address string) (string, error)
- func HasSupport() bool
- func InterfaceInfoFromDevices(nics map[string]device) (corenetwork.InterfaceInfos, error)
- func IsLXDNotFound(err error) bool
- func NewContainerInitialiser(lxdSnapChannel string) container.Initialiser
- func NewContainerManager(cfg container.ManagerConfig, svr *Server) (container.Manager, error)
- func SocketPath(isSocket func(path string) bool) string
- type Certificate
- func (c *Certificate) AsCreateRequest() (api.CertificatesPost, error)
- func (c *Certificate) Fingerprint() (string, error)
- func (c *Certificate) Validate() error
- func (c *Certificate) WriteCertPEM(out io.Writer) error
- func (c *Certificate) WriteKeyPEM(out io.Writer) error
- func (c *Certificate) X509() (*x509.Certificate, error)
- type Container
- type ContainerSpec
- type Protocol
- type ProxyFunc
- type Server
- func (s *Server) AliveContainers(prefix string) ([]Container, error)
- func (s *Server) Clock() clock.Clock
- func (s *Server) ClusterSupported() bool
- func (s *Server) ContainerAddresses(name string) ([]corenetwork.ProviderAddress, error)
- func (s *Server) CopyRemoteImage(sourced SourcedImage, aliases []string, callback environs.StatusCallbackFunc) error
- func (s *Server) CreateClientCertificate(cert *Certificate) error
- func (s *Server) CreateContainerFromSpec(spec ContainerSpec) (*Container, error)
- func (s *Server) CreatePool(name, driver string, cfg map[string]string) error
- func (s *Server) CreateProfileWithConfig(name string, cfg map[string]string) error
- func (s *Server) CreateVolume(pool, name string, cfg map[string]string) error
- func (s *Server) EnableHTTPSListener() error
- func (s *Server) EnsureDefaultStorage(profile *api.Profile, eTag string) error
- func (s *Server) EnsureIPv4(netName string) (bool, error)
- func (s *Server) FilterContainers(prefix string, statuses ...string) ([]Container, error)
- func (s *Server) FindImage(series, arch string, sources []ServerSpec, copyLocal bool, ...) (SourcedImage, error)
- func (s *Server) GetContainerProfiles(name string) ([]string, error)
- func (s *Server) GetNICsFromProfile(profileName string) (map[string]device, error)
- func (s *Server) HasProfile(name string) (bool, error)
- func (s *Server) HostArch() string
- func (s *Server) LocalBridgeName() string
- func (s *Server) Name() string
- func (s *Server) RemoveContainer(name string) error
- func (s *Server) RemoveContainers(names []string) error
- func (s *Server) ReplaceOrAddContainerProfile(name, oldProfile, newProfile string) error
- func (s *Server) ServerCertificate() string
- func (s *Server) ServerVersion() string
- func (s *Server) StartContainer(name string) error
- func (s *Server) StorageSupported() bool
- func (s *Server) SupportedArches() []string
- func (s *Server) UpdateContainerConfig(name string, cfg map[string]string) error
- func (s *Server) UpdateContainerProfiles(name string, profiles []string) error
- func (s *Server) UpdateServerConfig(cfg map[string]string) error
- func (s *Server) UseProject(project string)
- func (s Server) UseTargetServer(name string) (*Server, error)
- func (s *Server) VerifyNetworkDevice(profile *api.Profile, eTag string) error
- func (s *Server) WriteContainer(c *Container) error
- type ServerSpec
- type SnapManager
- type SourcedImage
Constants ¶
const ( UserNamespacePrefix = "user." UserDataKey = UserNamespacePrefix + "user-data" NetworkConfigKey = UserNamespacePrefix + "network-config" JujuModelKey = UserNamespacePrefix + "juju-model" AutoStartKey = "boot.autostart" )
const BridgeConfigFile = "/etc/default/lxd-bridge"
const SnapBridgeConfigFile = "/var/snap/lxd/common/lxd-bridge/config"
Variables ¶
var CloudImagesDailyRemote = ServerSpec{ Name: "cloud-images.ubuntu.com", Host: "https://cloud-images.ubuntu.com/daily", Protocol: SimpleStreamsProtocol, }
CloudImagesDailyRemote hosts images from daily package builds. These images have not been independently tested, but should be sound for use, being build from packages in the released archive.
var CloudImagesRemote = ServerSpec{ Name: "cloud-images.ubuntu.com", Host: "https://cloud-images.ubuntu.com/releases", Protocol: SimpleStreamsProtocol, }
CloudImagesRemote hosts releases blessed by the Canonical team.
var ConnectImageRemote = connectImageRemote
ConnectImageRemote connects to a remote ImageServer using specified protocol.
Functions ¶
func ConfigureLXDProxies ¶
ConfigureLXDProxies will try to set the lxc config core.proxy_http and core.proxy_https configuration values based on the current environment. If LXD is not installed, we skip the configuration.
func ConnectRemote ¶
func ConnectRemote(spec ServerSpec) (lxd.ContainerServer, error)
ConnectRemote connects to LXD on a remote socket.
func DevicesFromInterfaceInfo ¶
func DevicesFromInterfaceInfo(interfaces corenetwork.InterfaceInfos) (map[string]device, []string, error)
DevicesFromInterfaceInfo uses the input interface info collection to create a map of network device configuration in the LXD format. Names for any networks without a known CIDR are returned in a slice.
func EnsureHTTPS ¶
EnsureHTTPS takes a URI and ensures that it is a HTTPS URL. LXD Requires HTTPS.
func EnsureHostPort ¶
EnsureHostPort takes a URI and ensures that it has a port set, if it doesn't then it will ensure that port if added. The address supplied for the Host will be validated when parsed and if the address is not valid, then it will return an error.
func HasSupport ¶
func HasSupport() bool
HasSupport returns true if the current OS supports LXD containers by default
func InterfaceInfoFromDevices ¶
func InterfaceInfoFromDevices(nics map[string]device) (corenetwork.InterfaceInfos, error)
InterfaceInfoFromDevices returns a slice of interface info congruent with the input LXD NIC devices. The output is used to generate cloud-init user-data congruent with the NICs that end up in the container.
func IsLXDNotFound ¶
IsLXDNotFound checks if an error from the LXD API indicates that a requested entity was not found.
func NewContainerInitialiser ¶
func NewContainerInitialiser(lxdSnapChannel string) container.Initialiser
NewContainerInitialiser returns an instance used to perform the steps required to allow a host machine to run a LXC container.
func NewContainerManager ¶
NewContainerManager creates the entity that knows how to create and manage LXD containers. TODO(jam): This needs to grow support for things like LXC's ImageURLGetter functionality.
func SocketPath ¶
SocketPath returns the path to the local LXD socket. The following are tried in order of preference:
- LXD_DIR environment variable.
- Snap socket.
- Debian socket.
We give preference to LXD installed via Snap. isSocket defaults to socket detection from the LXD shared package. TODO (manadart 2018-04-30) This looks like it can be achieved by using a combination of VarPath and HostPath from lxd.shared, in which case this can be deprecated in their favour.
Types ¶
type Certificate ¶
type Certificate 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 }
Certificate holds the information for a single certificate that a client may use to connect to a remote server.
func GenerateClientCertificate ¶
func GenerateClientCertificate() (*Certificate, error)
GenerateClientCertificate creates and returns a new certificate for client communication with an LXD server.
func NewCertificate ¶
func NewCertificate(certPEM, keyPEM []byte) *Certificate
NewCertificate creates a new Certificate for the given cert and key.
func (*Certificate) AsCreateRequest ¶
func (c *Certificate) AsCreateRequest() (api.CertificatesPost, error)
AsCreateRequest creates a payload for the LXD API, suitable for posting the client certificate to an LXD server.
func (*Certificate) Fingerprint ¶
func (c *Certificate) Fingerprint() (string, error)
Fingerprint returns the cert's LXD fingerprint.
func (*Certificate) Validate ¶
func (c *Certificate) Validate() error
Validate ensures that the cert is valid.
func (*Certificate) WriteCertPEM ¶
func (c *Certificate) WriteCertPEM(out io.Writer) error
WriteCertPEM writes the cert's x.509 PEM data to the given writer.
func (*Certificate) WriteKeyPEM ¶
func (c *Certificate) WriteKeyPEM(out io.Writer) error
WriteKeyPEM writes the key's x.509 PEM data to the given writer.
func (*Certificate) X509 ¶
func (c *Certificate) X509() (*x509.Certificate, error)
X509 returns the x.509 certificate.
type Container ¶
Container extends the upstream LXD container type.
func (*Container) AddDisk ¶
AddDisk modifies updates the container's devices map to represent a disk device described by the input arguments. If the device already exists, an error is returned.
func (*Container) CPUs ¶
CPUs returns the configured limit for number of container CPU cores. If unset, zero is returned.
type ContainerSpec ¶
type ContainerSpec struct { Architecture string Name string Image SourcedImage Devices map[string]device Config map[string]string Profiles []string InstanceType string }
ContainerSpec represents the data required to create a new container.
func (*ContainerSpec) ApplyConstraints ¶
func (c *ContainerSpec) ApplyConstraints(serverVersion string, cons constraints.Value)
ApplyConstraints applies the input constraints as valid LXD container configuration to the container spec. Note that we pass these through as supplied. If an instance type constraint has been specified along with specific cores/mem constraints, LXD behaviour is to override with the specific ones even when lower.
type Server ¶
type Server struct { lxd.ContainerServer // contains filtered or unexported fields }
Server extends the upstream LXD container server.
func MaybeNewLocalServer ¶
MaybeNewLocalServer returns a Server based on a local socket connection, if running on an OS supporting LXD containers by default. Otherwise a nil server is returned.
func NewLocalServer ¶
NewLocalServer returns a Server based on a local socket connection.
func NewRemoteServer ¶
func NewRemoteServer(spec ServerSpec) (*Server, error)
NewRemoteServer returns a Server based on a remote connection.
func NewServer ¶
func NewServer(svr lxd.ContainerServer) (*Server, error)
NewServer builds and returns a Server for high-level interaction with the input LXD container server.
func (*Server) AliveContainers ¶
AliveContainers returns the list of containers based on the input namespace prefixed that are in a status indicating they are "alive".
func (*Server) ClusterSupported ¶
func (*Server) ContainerAddresses ¶
func (s *Server) ContainerAddresses(name string) ([]corenetwork.ProviderAddress, error)
ContainerAddresses gets usable network addresses for the container identified by the input name.
func (*Server) CopyRemoteImage ¶
func (s *Server) CopyRemoteImage( sourced SourcedImage, aliases []string, callback environs.StatusCallbackFunc, ) error
CopyRemoteImage accepts an image sourced from a remote server and copies it to the local cache
func (*Server) CreateClientCertificate ¶
func (s *Server) CreateClientCertificate(cert *Certificate) error
CreateClientCertificate adds the input certificate to the server, indicating that is for use in client communication.
func (*Server) CreateContainerFromSpec ¶
func (s *Server) CreateContainerFromSpec(spec ContainerSpec) (*Container, error)
CreateContainerFromSpec creates a new container based on the input spec, and starts it immediately. If the container fails to be started, it is removed. Upon successful creation and start, the container is returned.
func (*Server) CreatePool ¶
func (*Server) CreateProfileWithConfig ¶
CreateProfileWithConfig creates a new profile with the input name and config.
func (*Server) CreateVolume ¶
func (*Server) EnableHTTPSListener ¶
EnableHTTPSListener configures LXD to listen for HTTPS requests, rather than only via a Unix socket. Attempts to listen on all protocols, but falls back to IPv4 only if IPv6 has been disabled with in kernel. Returns an error if updating the server configuration fails.
func (*Server) EnsureDefaultStorage ¶
EnsureDefaultStorage ensures that the input profile is configured with a disk device, creating a new storage pool and a device if required.
func (*Server) EnsureIPv4 ¶
EnsureIPv4 retrieves the network for the input name and checks its IPv4 configuration. If none is detected, it is set to "auto". The boolean return indicates if modification was necessary.
func (*Server) FilterContainers ¶
FilterContainers retrieves the list of containers from the server and filters them based on the input namespace prefix and any supplied statuses.
func (*Server) FindImage ¶
func (s *Server) FindImage( series, arch string, sources []ServerSpec, copyLocal bool, callback environs.StatusCallbackFunc, ) (SourcedImage, error)
FindImage searches the input sources in supplied order, looking for an OS image matching the supplied series and architecture. If found, the image and the server from which it was acquired are returned. If the server is remote the image will be cached by LXD when used to create a container. Supplying true for copyLocal will copy the image to the local cache. Copied images will have the juju/series/arch alias added to them. The callback argument is used to report copy progress.
func (*Server) GetContainerProfiles ¶
GetContainerProfiles returns the list of profiles that are associated with a container.
func (*Server) GetNICsFromProfile ¶
GetNICsFromProfile returns all NIC devices in the profile with the input name. All returned devices have a MAC address; generated if required.
func (*Server) HasProfile ¶
HasProfile interrogates the known profile names and returns a boolean indicating whether a profile with the input name exists.
func (*Server) LocalBridgeName ¶
LocalBridgeName returns the name of the local LXD network bridge.
func (*Server) RemoveContainer ¶
Remove container first ensures that the container is stopped, then deletes it.
func (*Server) RemoveContainers ¶
Remove containers stops and deletes containers matching the input list of names. Any failed removals are indicated in the returned error.
func (*Server) ReplaceOrAddContainerProfile ¶
ReplaceOrAddContainerProfile updates the profiles for the container with the input name, using the input values. TODO: HML 2-apr-2019 remove when provisioner_task processProfileChanges() is removed.
func (*Server) ServerCertificate ¶
ServerCertificate returns the current server environment certificate
func (*Server) ServerVersion ¶
func (*Server) StartContainer ¶
StartContainer starts the extant container identified by the input name.
func (*Server) StorageSupported ¶
func (*Server) SupportedArches ¶
SupportedArches returns all supported arches
func (*Server) UpdateContainerConfig ¶
UpdateContainerConfig updates the configuration for the container with the input name, using the input values.
func (*Server) UpdateContainerProfiles ¶
UpdateContainerProfiles applies the given profiles (by name) to the named container. It is assumed the profiles have all been added to the server before hand.
func (*Server) UpdateServerConfig ¶
UpdateServerConfig updates the server configuration with the input values.
func (*Server) UseProject ¶
UseProject ensures that this server will use the input project. See: https://linuxcontainers.org/lxd/docs/master/projects.
func (Server) UseTargetServer ¶
UseTargetServer returns a new Server based on the input target node name. It is intended for use when operations must target specific nodes in a cluster.
func (*Server) VerifyNetworkDevice ¶
VerifyNetworkDevice attempts to ensure that there is a network usable by LXD and that there is a NIC device with said network as its parent. If there are no NIC devices, and this server is *not* in cluster mode, an attempt is made to create an new device in the input profile, with the default LXD bridge as its parent.
func (*Server) WriteContainer ¶
WriteContainer writes the current representation of the input container to the server.
type ServerSpec ¶
type ServerSpec struct { Name string Host string Protocol Protocol // contains filtered or unexported fields }
ServerSpec describes the location and connection details for a server utilized in LXD workflows.
func MakeSimpleStreamsServerSpec ¶
func MakeSimpleStreamsServerSpec(name, host string) ServerSpec
MakeSimpleStreamsServerSpec creates a ServerSpec for the SimpleStreams protocol, ensuring that the host is HTTPS
func NewInsecureServerSpec ¶
func NewInsecureServerSpec(host string) ServerSpec
NewInsecureServerSpec creates a ServerSpec without certificate requirements, which also bypasses the TLS verification. It also ensures the HTTPS for the host implicitly
func NewServerSpec ¶
func NewServerSpec(host, serverCert string, clientCert *Certificate) ServerSpec
NewServerSpec creates a ServerSpec with default values where needed. It also ensures the HTTPS for the host implicitly
func (*ServerSpec) Validate ¶
func (s *ServerSpec) Validate() error
Validate ensures that the ServerSpec is valid.
func (ServerSpec) WithClientCertificate ¶
func (s ServerSpec) WithClientCertificate(clientCert *Certificate) ServerSpec
WithClientCertificate adds the optional client Certificate to the server spec. Returns the ServerSpec to enable chaining of optional values
func (ServerSpec) WithHTTPClient ¶
func (s ServerSpec) WithHTTPClient(client *http.Client) ServerSpec
WithHTTPClient adds the option of passing the http client to the server spec.
func (ServerSpec) WithProxy ¶
func (s ServerSpec) WithProxy(proxy ProxyFunc) ServerSpec
WithProxy adds the optional proxy to the server spec. Returns the ServerSpec to enable chaining of optional values
func (ServerSpec) WithSkipGetServer ¶
func (s ServerSpec) WithSkipGetServer(b bool) ServerSpec
WithSkipGetServer adds the option skipping of the get server verification to the server spec.
type SnapManager ¶
SnapManager defines an interface implemented by types that can query and/or change the channel for installed snaps.
type SourcedImage ¶
type SourcedImage struct { // Image is the actual image data that was located. Image *api.Image // LXDServer is the image server that supplied the image. LXDServer lxd.ImageServer }
SourcedImage is the result of a successful image acquisition. It includes the relevant data that located the image.