lxd

package module
v0.0.0-...-addb04b Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2015 License: Apache-2.0 Imports: 22 Imported by: 0

README

LXD Build Status

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

LXD is pronounced lex-dee.

Getting started with LXD

Since LXD development is happening at such a rapid pace, we only provide daily builds right now. They're available via:

sudo add-apt-repository ppa:ubuntu-lxc/lxd-git-master && sudo apt-get update
sudo apt-get install lxd

After you've got LXD installed, you can take your first steps.

Building from source

We have exeperienced some problems using gccgo, so for now we recommend using the golang compiler. We also require that a 1.1+ version of lxc and lxc-dev be installed. Additionally, some of LXD's dependencies are grabbed from go get via mercurial, so you'll need to have hg in your path as well. You can get these on Ubuntu via:

sudo apt-get install lxc lxc-dev mercurial git pkg-config protobuf-compiler golang-goprotobuf-dev
Installing Go

LXD requires Golang 1.3 or later to work.

If running Ubuntu, the easiest way to get it is to use the LXD PPA:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ubuntu-lxc/lxd-git-master
sudo apt-get update
sudo apt-get install golang

In order to be able to extract images and create containers, a few more dependencies are xz, tar, and setfacl:

sudo apt-get install xz-utils tar acl

To run the testsuite, you'll also need:

sudo apt-get install curl gettext jq sqlite3
Building the tools

LXD consists of two binaries, a client called lxc and a server called lxd. These live in the source tree in the lxc/ and lxd/ 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/lxc/lxd
cd $GOPATH/src/github.com/lxc/lxd
go get -v -d ./...
make

...which will give you two binaries in $GOPATH/bin, lxd the daemon binary, and lxc 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 admin bit allows everyone in the admin group to talk to LXD; you can create your own group if you want, but typically all sudo users are in the admin group, so this is a handy way to allow them to talk to LXD):

sudo -E $GOPATH/bin/lxd --group admin

First steps

LXD has two parts, the daemon (the lxd binary), and the client (the lxc binary). Now that the daemon is all configured and running (either via the packaging or via the from-source instructions above), you can import some images:

scripts/lxd-images import lxc ubuntu trusty amd64 --alias ubuntu --alias ubuntu/trusty --alias ubuntu/trusty/amd64
scripts/lxd-images import lxc debian wheezy amd64 --alias debian --alias debian/wheezy --alias debian/wheezy/amd64

With those two images imported into LXD, you can now start containers:

$GOPATH/bin/lxc launch ubuntu
$GOPATH/bin/lxc launch debian debian01

Bug reports

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

Contributing

Fixes and new features are greatly appreciated but please read our contributing guidelines first.

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

Hacking

Sometimes it is useful to view the raw response that LXD sends; you can do this by:

lxc config set password foo
lxc remote add local 127.0.0.1:8443
wget --no-check-certificate https://127.0.0.1:8443/1.0/finger --certificate=$HOME/.config/lxc/client.crt --private-key=$HOME/.config/lxc/client.key -O - -q

Support and discussions

We use the LXC mailing-lists for developer and user discussions, you can find and subscribe to those at: https://lists.linuxcontainers.org

If you prefer live discussions, some of us also hang out in #lxcontainers on irc.freenode.net.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDir = "$HOME/.config/lxc"
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"),
	}
)

Functions

func ConfigPath

func ConfigPath(file string) string

func IsSnapshot

func IsSnapshot(name string) bool

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 {
	Remote *RemoteConfig

	BaseURL   string
	BaseWSURL 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) AmTrusted

func (c *Client) AmTrusted() bool

func (*Client) ApplyProfile

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

func (*Client) CertificateAdd

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

func (*Client) CertificateList

func (c *Client) CertificateList() (map[string]string, 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 *os.File, stdout *os.File, stderr *os.File) (int, error)

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) GetProfileConfig

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

func (*Client) GetServerConfig

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

func (*Client) Init

func (c *Client) Init(name string, imgremote string, image string, profiles *[]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) ListAliases

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

func (*Client) ListContainers

func (c *Client) ListContainers() ([]string, 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) (*Response, error)

func (*Client) MigrateFrom

func (c *Client) MigrateFrom(name string, operation string, secrets map[string]string, config map[string]string, profiles []string) (*Response, error)

func (*Client) MigrateTo

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

func (*Client) PostAlias

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

func (*Client) PostImage

func (c *Client) PostImage(path string, properties []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) PutImageProperties

func (c *Client) PutImageProperties(name string, p shared.ImageProperties) 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) SetContainerConfig

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

func (*Client) SetProfileConfigItem

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

func (*Client) SetRemotePwd

func (c *Client) SetRemotePwd(password string) (*Response, error)

func (*Client) Snapshot

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

func (*Client) UserAuthServerCert

func (c *Client) UserAuthServerCert(name string) 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"`

	// ListenAddr defines an alternative address for the local daemon
	// to listen on. If empty, the daemon will listen only on the local
	// unix socket address.
	ListenAddr string `yaml:"listen-addr"`
}

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"`
}

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"`
	Resources map[string][]string `json:"resources"`

	/* 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
dist
src/code.google.com/p/go-uuid/uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.
src/code.google.com/p/goprotobuf/proto
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
src/code.google.com/p/goprotobuf/protoc-gen-go/descriptor
Package google_protobuf is a generated protocol buffer package.
Package google_protobuf is a generated protocol buffer package.
src/code.google.com/p/goprotobuf/protoc-gen-go/generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
src/code.google.com/p/goprotobuf/protoc-gen-go/plugin
Package google_protobuf_compiler is a generated protocol buffer package.
Package google_protobuf_compiler is a generated protocol buffer package.
src/github.com/dustinkirkland/golang-petname
Package petname is a library for generating human-readable, random names for objects (e.g.
Package petname is a library for generating human-readable, random names for objects (e.g.
src/github.com/gorilla/context
Package context stores values shared during a request lifetime.
Package context stores values shared during a request lifetime.
src/github.com/gorilla/mux
Package gorilla/mux implements a request router and dispatcher.
Package gorilla/mux implements a request router and dispatcher.
src/github.com/gorilla/websocket
Package websocket implements the WebSocket protocol defined in RFC 6455.
Package websocket implements the WebSocket protocol defined in RFC 6455.
src/github.com/gorilla/websocket/examples/autobahn
Command server is a test server for the Autobahn WebSockets Test Suite.
Command server is a test server for the Autobahn WebSockets Test Suite.
src/github.com/mattn/go-sqlite3
Package sqlite3 provides interface to SQLite3 databases.
Package sqlite3 provides interface to SQLite3 databases.
src/github.com/olekukonko/tablewriter
Create & Generate text based table
Create & Generate text based table
src/golang.org/x/crypto/bcrypt
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.
src/golang.org/x/crypto/blowfish
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm.
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm.
src/golang.org/x/crypto/bn256
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
src/golang.org/x/crypto/cast5
Package cast5 implements CAST5, as defined in RFC 2144.
Package cast5 implements CAST5, as defined in RFC 2144.
src/golang.org/x/crypto/curve25519
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
src/golang.org/x/crypto/hkdf
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.
src/golang.org/x/crypto/md4
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
src/golang.org/x/crypto/nacl/box
Package box authenticates and encrypts messages using public-key cryptography.
Package box authenticates and encrypts messages using public-key cryptography.
src/golang.org/x/crypto/nacl/secretbox
Package secretbox encrypts and authenticates small messages.
Package secretbox encrypts and authenticates small messages.
src/golang.org/x/crypto/ocsp
Package ocsp parses OCSP responses as specified in RFC 2560.
Package ocsp parses OCSP responses as specified in RFC 2560.
src/golang.org/x/crypto/openpgp
Package openpgp implements high level operations on OpenPGP messages.
Package openpgp implements high level operations on OpenPGP messages.
src/golang.org/x/crypto/openpgp/armor
Package armor implements OpenPGP ASCII Armor, see RFC 4880.
Package armor implements OpenPGP ASCII Armor, see RFC 4880.
src/golang.org/x/crypto/openpgp/clearsign
Package clearsign generates and processes OpenPGP, clear-signed data.
Package clearsign generates and processes OpenPGP, clear-signed data.
src/golang.org/x/crypto/openpgp/elgamal
Package elgamal implements ElGamal encryption, suitable for OpenPGP, as specified in "A Public-Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms," IEEE Transactions on Information Theory, v.
Package elgamal implements ElGamal encryption, suitable for OpenPGP, as specified in "A Public-Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms," IEEE Transactions on Information Theory, v.
src/golang.org/x/crypto/openpgp/errors
Package errors contains common error types for the OpenPGP packages.
Package errors contains common error types for the OpenPGP packages.
src/golang.org/x/crypto/openpgp/packet
Package packet implements parsing and serialization of OpenPGP packets, as specified in RFC 4880.
Package packet implements parsing and serialization of OpenPGP packets, as specified in RFC 4880.
src/golang.org/x/crypto/openpgp/s2k
Package s2k implements the various OpenPGP string-to-key transforms as specified in RFC 4800 section 3.7.1.
Package s2k implements the various OpenPGP string-to-key transforms as specified in RFC 4800 section 3.7.1.
src/golang.org/x/crypto/otr
Package otr implements the Off The Record protocol as specified in http://www.cypherpunks.ca/otr/Protocol-v2-3.1.0.html
Package otr implements the Off The Record protocol as specified in http://www.cypherpunks.ca/otr/Protocol-v2-3.1.0.html
src/golang.org/x/crypto/pbkdf2
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
src/golang.org/x/crypto/poly1305
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
src/golang.org/x/crypto/ripemd160
Package ripemd160 implements the RIPEMD-160 hash algorithm.
Package ripemd160 implements the RIPEMD-160 hash algorithm.
src/golang.org/x/crypto/salsa20
Package salsa20 implements the Salsa20 stream cipher as specified in http://cr.yp.to/snuffle/spec.pdf.
Package salsa20 implements the Salsa20 stream cipher as specified in http://cr.yp.to/snuffle/spec.pdf.
src/golang.org/x/crypto/salsa20/salsa
Package salsa provides low-level access to functions in the Salsa family.
Package salsa provides low-level access to functions in the Salsa family.
src/golang.org/x/crypto/scrypt
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
src/golang.org/x/crypto/sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
src/golang.org/x/crypto/ssh
Package ssh implements an SSH client and server.
Package ssh implements an SSH client and server.
src/golang.org/x/crypto/ssh/agent
Package agent implements a client to an ssh-agent daemon.
Package agent implements a client to an ssh-agent daemon.
src/golang.org/x/crypto/ssh/terminal
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
src/golang.org/x/crypto/ssh/test
This package contains integration tests for the code.google.com/p/go.crypto/ssh package.
This package contains integration tests for the code.google.com/p/go.crypto/ssh package.
src/golang.org/x/crypto/twofish
Package twofish implements Bruce Schneier's Twofish encryption algorithm.
Package twofish implements Bruce Schneier's Twofish encryption algorithm.
src/golang.org/x/crypto/xtea
Package xtea implements XTEA encryption, as defined in Needham and Wheeler's 1997 technical report, "Tea extensions."
Package xtea implements XTEA encryption, as defined in Needham and Wheeler's 1997 technical report, "Tea extensions."
src/golang.org/x/crypto/xts
Package xts implements the XTS cipher mode as specified in IEEE P1619/D16.
Package xts implements the XTS cipher mode as specified in IEEE P1619/D16.
src/gopkg.in/lxc/go-lxc.v2
Package lxc provides Go Bindings for LXC (Linux Containers) C API.
Package lxc provides Go Bindings for LXC (Linux Containers) C API.
src/gopkg.in/tomb.v2
The tomb package handles clean goroutine tracking and termination.
The tomb package handles clean goroutine tracking and termination.
src/gopkg.in/yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.
internal
gnuflag
Package flag implements command-line flag parsing in the GNU style.
Package flag implements command-line flag parsing in the GNU style.
lxd
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.

Jump to

Keyboard shortcuts

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