lxdclient

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

This is a small Go library that connects to an LXD server, with the goal of using the same configuration used by the "lxc" command.

It Uses code from https://github.com/lxc/lxd

The lxc code use these default paths:

  • /var/lib/lxd/unix.socket (client/connection.go)
  • $HOME/.config/lxc (lxc/main.go)

But when LXD is installed as a snap, "lxc" seems to use the following:

  • /var/snap/lxd/common/lxd/unix.socket
  • $HOME/snap/lxd/common/config/

lxdclient uses all of the above, whichever it finds first.

See go doc for the full list.

Documentation

Overview

Package lxdclient provides initialization code for connecting to an LXD server, using the same configuration as used by the "lxc" command.

If using the unix socket, connect via the path:

$LXD_SOCKET, if defined

Otherwise, the first of these that exists:

  • $LXD_DIR/unix.socket
  • /var/lib/unix.socket
  • /var/snap/lxd/common/lxd/unix.socket

Otherwise, lxdclient looks for a config directory:

$LXD_CONF, if defined

Otherwise, the first of these that exists:

  • os.UserConfigDir()/lxc
  • $os.UserHomeDir()/snap/lxd/common/config
  • the path returned by github.com/lxc/lxd lxc/config.Config.GlobalConfigPath():

GlobalConfigPath

  • $LXD_GLOBAL_CONF
  • /etc/lxd

Where $var is the var environment variable.

Index

Constants

This section is empty.

Variables

View Source
var Trace bool

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the default LXD client configuration directory. See https://github.com/canonical/lxd/blob/master/client/main.go We use a similar strategy as main.go func (c *cmdGlobal) PreRun, except that we add $HOME/snap/lxd/common/config/ to the LXD config directories searched. If no LXD CONF directory is found, return "", nil.

func LoadConfig

func LoadConfig() (*config.Config, error)

func UnixSocket

func UnixSocket() (string, error)

UnixSocket returns the default LXD Unix Socket See https://github.com/canonical/lxd/blob/master/client/connection.go We use a similar strategy as connection.go ConnectLXDUnixWithContext(), except that we add /var/snap/lxd/common/lxd/ to the LXD directories searched. If no LXD directory is found, return "", nil.

Types

type LxdClient

type LxdClient struct {
	ForceLocal bool   `name:"force-local" usage:"Force using the local unix socket"`
	Project    string `name:"project" usage:"Override the default project"`
	// contains filtered or unexported fields
}

LxdClient provides an lxd.InstanceServer Use it by calling these methods, in order: Configured(), CurrentServer().

func (*LxdClient) Config

func (t *LxdClient) Config() *config.Config

func (*LxdClient) Configured

func (t *LxdClient) Configured() error

func (*LxdClient) CurrentProject

func (t *LxdClient) CurrentProject() string

func (*LxdClient) CurrentServer

func (t *LxdClient) CurrentServer() (lxd.InstanceServer, error)

RootServer - return the LXD instance server for the current project

func (*LxdClient) Init

func (t *LxdClient) Init() error

func (*LxdClient) ProjectServer

func (t *LxdClient) ProjectServer(project string) (lxd.InstanceServer, error)

RootServer - return the LXD instance server for the specified project If project is empty, use the default project

func (*LxdClient) RootServer

func (t *LxdClient) RootServer() (lxd.InstanceServer, error)

RootServer - return the unqualified (no project) LXD instance server

Jump to

Keyboard shortcuts

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