lxd

package module
v0.0.0-...-183c73a Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2015 License: Apache-2.0 Imports: 23 Imported by: 0

README

XLXD

A FORK OF LXD WITH FEWER RESTRICTIONS

REST API, command line tool and OpenStack integration plugin for LXC.

XLXD is pronounced ex-ell-ex-dee.

Getting started with XLXD

TBD

Building from source

TBD

Building the tools

LXD consists of two binaries, a client called xlxc and a server called xlxd. These live in the source tree in the xlxc/ and xlxd/ dirs, respectively. To get the code, set up your go environment:

mkdir -p ~/go
export GOPATH=~/go

And then download it as usual:

go get github.com/krschwab/xlxd
cd $GOPATH/src/github.com/krschwab/xlxd
make

...which will give you two binaries in $GOPATH/bin, xlxd the daemon binary, and xlxc a command line client to that daemon.

Machine Setup

You'll need sub{u,g}ids for root, so that LXD can create the unprivileged containers:

echo "root:1000000:65536" | sudo tee -a /etc/subuid /etc/subgid

Now you can run the daemon (the --group sudo bit allows everyone in the sudo group to talk to LXD; you can create your own group if you want):

sudo -E $GOPATH/bin/xlxd --group sudo

First steps

TBD

Bug reports

Bug reports can be filed at https://github.com/krschwab/lxd/issues/new

Contributing

Contributions to this project should be sent as pull requests on github.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDir = "$HOME/.config/lxc"
View Source
var DefaultConfig = Config{
	Remotes:       defaultRemote,
	DefaultRemote: "local",
	Aliases:       map[string]string{},
}
View Source
var (
	// LXDErrors are special errors; the client library hoists error codes
	// to these errors internally so that user code can compare against
	// them. We probably shouldn't hoist BadRequest or InternalError, since
	// LXD passes an error string along which is more informative than
	// whatever static error message we would put here.
	LXDErrors = map[int]error{
		http.StatusNotFound: fmt.Errorf("not found"),
	}
)
View Source
var LocalRemote = RemoteConfig{
	Addr:   "unix://",
	Public: false}

Functions

func ConfigPath

func ConfigPath(file string) string

func SaveConfig

func SaveConfig(c *Config) error

SaveConfig writes the provided configuration to the config file.

func ServerCertPath

func ServerCertPath(name string) string

func WebsocketDial

func WebsocketDial(dialer websocket.Dialer, url string) (*websocket.Conn, error)

WebsocketDial attempts to dial a websocket to a LXD instance, parsing LXD-style errors and returning them as go errors.

Types

type Client

type Client struct {
	BaseURL   string
	BaseWSURL string
	Config    Config
	Http      http.Client
	Name      string
	Remote    *RemoteConfig
	Transport string
	// contains filtered or unexported fields
}

Client can talk to a LXD daemon.

func NewClient

func NewClient(config *Config, remote string) (*Client, error)

NewClient returns a new LXD client.

func (*Client) Action

func (c *Client) Action(name string, action shared.ContainerAction, timeout int, force bool) (*Response, error)

func (*Client) AddMyCertToServer

func (c *Client) AddMyCertToServer(pwd string) error

func (*Client) Addresses

func (c *Client) Addresses() ([]string, error)

func (*Client) AmTrusted

func (c *Client) AmTrusted() bool

func (*Client) ApplyProfile

func (c *Client) ApplyProfile(container, profile string) (*Response, error)

func (*Client) AsyncWaitMeta

func (c *Client) AsyncWaitMeta(resp *Response) (*shared.Jmap, error)

func (*Client) CertificateAdd

func (c *Client) CertificateAdd(cert *x509.Certificate, name string) error

func (*Client) CertificateList

func (c *Client) CertificateList() ([]shared.CertInfo, error)

func (*Client) CertificateRemove

func (c *Client) CertificateRemove(fingerprint string) error

func (*Client) ContainerDeviceAdd

func (c *Client) ContainerDeviceAdd(container, devname, devtype string, props []string) (*Response, error)

func (*Client) ContainerDeviceDelete

func (c *Client) ContainerDeviceDelete(container, devname string) (*Response, error)

func (*Client) ContainerListDevices

func (c *Client) ContainerListDevices(container string) ([]string, error)

func (*Client) ContainerStatus

func (c *Client) ContainerStatus(name string) (*shared.ContainerState, error)

func (*Client) CopyImage

func (c *Client) CopyImage(image string, dest *Client, copy_aliases bool, aliases []string, public bool) error

func (*Client) Delete

func (c *Client) Delete(name string) (*Response, error)

func (*Client) DeleteAlias

func (c *Client) DeleteAlias(alias string) error

func (*Client) DeleteImage

func (c *Client) DeleteImage(image string) error

func (*Client) Exec

func (c *Client) Exec(name string, cmd []string, env map[string]string,
	stdin io.ReadCloser, stdout io.WriteCloser,
	stderr io.WriteCloser, controlHandler func(*Client, *websocket.Conn)) (int, error)

Exec runs a command inside the LXD container. For "interactive" use such as `lxc exec ...`, one should pass a controlHandler that talks over the control socket and handles things like SIGWINCH. If running non-interactive, passing a nil controlHandler will cause Exec to return when all of the command output is sent to the output buffers.

func (*Client) ExportImage

func (c *Client) ExportImage(image string, target string) (*Response, string, error)

func (*Client) Finger

func (c *Client) Finger() error

func (*Client) GetAlias

func (c *Client) GetAlias(alias string) string

func (*Client) GetContainerConfig

func (c *Client) GetContainerConfig(container string) ([]string, error)

* return string array representing a container's full configuration

func (*Client) GetImageInfo

func (c *Client) GetImageInfo(image string) (*shared.ImageInfo, error)

func (*Client) GetLog

func (c *Client) GetLog(container string, log string) (io.Reader, error)

func (*Client) GetMigrationSourceWS

func (c *Client) GetMigrationSourceWS(container string) (*Response, error)

func (*Client) GetProfileConfig

func (c *Client) GetProfileConfig(profile string) (map[string]string, error)

func (*Client) GetServerConfig

func (c *Client) GetServerConfig() (*Response, error)

func (*Client) GetServerConfigString

func (c *Client) GetServerConfigString() ([]string, error)

func (*Client) ImageFromContainer

func (c *Client) ImageFromContainer(cname string, public bool, aliases []string, properties map[string]string) (string, error)

func (*Client) Init

func (c *Client) Init(name string, imgremote string, image string, profiles *[]string, config map[string]string, ephem bool) (*Response, error)

Init creates a container from either a fingerprint or an alias; you must provide at least one.

func (*Client) IsAlias

func (c *Client) IsAlias(alias string) (bool, error)

func (*Client) IsPublic

func (c *Client) IsPublic() bool

func (*Client) ListAliases

func (c *Client) ListAliases() ([]shared.ImageAlias, error)

func (*Client) ListContainers

func (c *Client) ListContainers() ([]shared.ContainerInfo, error)

func (*Client) ListImages

func (c *Client) ListImages() ([]shared.ImageInfo, error)

func (*Client) ListProfiles

func (c *Client) ListProfiles() ([]string, error)

func (*Client) ListSnapshots

func (c *Client) ListSnapshots(container string) ([]string, error)

func (*Client) LocalCopy

func (c *Client) LocalCopy(source string, name string, config map[string]string, profiles []string, ephemeral bool) (*Response, error)

func (*Client) MigrateFrom

func (c *Client) MigrateFrom(name string, operation string, secrets map[string]string, architecture int, config map[string]string, devices shared.Devices, profiles []string, baseImage string, ephemeral bool) (*Response, error)

func (*Client) Monitor

func (c *Client) Monitor(types []string, handler func(interface{})) error

func (*Client) PostAlias

func (c *Client) PostAlias(alias string, desc string, target string) error

func (*Client) PostImage

func (c *Client) PostImage(imageFile string, rootfsFile string, properties []string, public bool, aliases []string) (string, error)

func (*Client) PostImageURL

func (c *Client) PostImageURL(imageFile string, public bool, aliases []string) (string, error)

func (*Client) ProfileConfig

func (c *Client) ProfileConfig(name string) (*shared.ProfileConfig, error)

func (*Client) ProfileCopy

func (c *Client) ProfileCopy(name, newname string, dest *Client) error

func (*Client) ProfileCreate

func (c *Client) ProfileCreate(p string) error

func (*Client) ProfileDelete

func (c *Client) ProfileDelete(p string) error

func (*Client) ProfileDeviceAdd

func (c *Client) ProfileDeviceAdd(profile, devname, devtype string, props []string) (*Response, error)

func (*Client) ProfileDeviceDelete

func (c *Client) ProfileDeviceDelete(profile, devname string) (*Response, error)

func (*Client) ProfileListDevices

func (c *Client) ProfileListDevices(profile string) ([]string, error)

func (*Client) PullFile

func (c *Client) PullFile(container string, p string) (int, int, os.FileMode, io.ReadCloser, error)

func (*Client) PushFile

func (c *Client) PushFile(container string, p string, gid int, uid int, mode os.FileMode, buf io.ReadSeeker) error

func (*Client) PutImageInfo

func (c *Client) PutImageInfo(name string, p shared.BriefImageInfo) error

func (*Client) PutProfile

func (c *Client) PutProfile(name string, profile shared.ProfileConfig) error

func (*Client) Rename

func (c *Client) Rename(name string, newName string) (*Response, error)

func (*Client) RestoreSnapshot

func (c *Client) RestoreSnapshot(container string, snapshotName string, stateful bool) (*Response, error)

func (*Client) ServerStatus

func (c *Client) ServerStatus() (*shared.ServerState, error)

func (*Client) SetContainerConfig

func (c *Client) SetContainerConfig(container, key, value string) error

func (*Client) SetProfileConfigItem

func (c *Client) SetProfileConfigItem(profile, key, value string) error

func (*Client) SetServerConfig

func (c *Client) SetServerConfig(key string, value string) (*Response, error)

func (*Client) Snapshot

func (c *Client) Snapshot(container string, snapshotName string, stateful bool) (*Response, error)

func (*Client) UpdateContainerConfig

func (c *Client) UpdateContainerConfig(container string, st shared.BriefContainerState) error

func (*Client) UserAuthServerCert

func (c *Client) UserAuthServerCert(name string, acceptCert bool) error

func (*Client) WaitFor

func (c *Client) WaitFor(waitURL string) (*shared.Operation, error)

Wait for an operation

func (*Client) WaitForSuccess

func (c *Client) WaitForSuccess(waitURL string) error

type Config

type Config struct {
	// DefaultRemote holds the remote daemon name from the Remotes map
	// that the client should communicate with by default.
	// If empty it defaults to "local".
	DefaultRemote string `yaml:"default-remote"`

	// Remotes defines a map of remote daemon names to the details for
	// communication with the named daemon.
	// The implicit "local" remote is always available and communicates
	// with the local daemon over a unix socket.
	Remotes map[string]RemoteConfig `yaml:"remotes"`

	// Command line aliases for `lxc`
	Aliases map[string]string `yaml:"aliases"`
}

Config holds settings to be used by a client or daemon.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig reads the configuration from the config path.

func (*Config) ParseRemote

func (c *Config) ParseRemote(raw string) string

func (*Config) ParseRemoteAndContainer

func (c *Config) ParseRemoteAndContainer(raw string) (string, string)

type RemoteConfig

type RemoteConfig struct {
	Addr   string `yaml:"addr"`
	Public bool   `yaml:"public"`
}

RemoteConfig holds details for communication with a remote daemon.

type Response

type Response struct {
	Type ResponseType `json:"type"`

	/* Valid only for Sync responses */
	Status     string `json:"status"`
	StatusCode int    `json:"status_code"`

	/* Valid only for Async responses */
	Operation string `json:"operation"`

	/* Valid only for Error responses */
	Code  int    `json:"error_code"`
	Error string `json:"error"`

	/* Valid for Sync and Error responses */
	Metadata json.RawMessage `json:"metadata"`
}

func HoistResponse

func HoistResponse(r *http.Response, rtype ResponseType) (*Response, error)

HoistResponse hoists a regular http response into a response of type rtype or returns a golang error.

func ParseResponse

func ParseResponse(r *http.Response) (*Response, error)

ParseResponse parses a lxd style response out of an http.Response. Note that this does _not_ automatically convert error responses to golang errors. To do that, use ParseError. Internal client library uses should probably use HoistResponse, unless they are interested in accessing the underlying Error response (e.g. to inspect the error code).

func (*Response) MetadataAsMap

func (r *Response) MetadataAsMap() (*shared.Jmap, error)

func (*Response) MetadataAsOperation

func (r *Response) MetadataAsOperation() (*shared.Operation, error)

type ResponseType

type ResponseType string
const (
	Sync  ResponseType = "sync"
	Async ResponseType = "async"
	Error ResponseType = "error"
)

Directories

Path Synopsis
This is a FLEXible file which can be used by both client and daemon.
This is a FLEXible file which can be used by both client and daemon.
gnuflag
Package flag implements command-line flag parsing in the GNU style.
Package flag implements command-line flag parsing in the GNU style.
test
deps
* An example of how to use lxd's golang /dev/lxd client.
* An example of how to use lxd's golang /dev/lxd client.
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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