shared

package
v0.0.0-...-ab10d8f Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2016 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

This is a FLEXible file which can be used by both client and daemon.
* Teehee.

That this code needs to exist is kind of dumb, but I'm not sure how else to do it.

Index

Constants

View Source
const (
	ARCH_UNKNOWN                     = 0
	ARCH_32BIT_INTEL_X86             = 1
	ARCH_64BIT_INTEL_X86             = 2
	ARCH_32BIT_ARMV7_LITTLE_ENDIAN   = 3
	ARCH_64BIT_ARMV8_LITTLE_ENDIAN   = 4
	ARCH_32BIT_POWERPC_BIG_ENDIAN    = 5
	ARCH_64BIT_POWERPC_BIG_ENDIAN    = 6
	ARCH_64BIT_POWERPC_LITTLE_ENDIAN = 7
	ARCH_64BIT_S390_BIG_ENDIAN       = 8
)
View Source
const DefaultPort = "8443"
View Source
const SnapshotDelimiter = "/"

Variables

View Source
var APICompat = 1

* Please increment the api compat number every time you change the API. * * Version 1.0: ping

View Source
var APIVersion = "1.0"
View Source
var UserAgent = "LXD " + Version
View Source
var Version = "2.0.0.beta1"
View Source
var WebsocketUpgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin:     func(r *http.Request) bool { return true },
}

Functions

func AddSlash

func AddSlash(path string) string

AddSlash adds a slash to the end of paths if they don't already have one. This can be useful for rsyncing things, since rsync has behavior present on the presence or absence of a trailing slash.

func ArchitectureId

func ArchitectureId(arch string) (int, error)

func ArchitectureName

func ArchitectureName(arch int) (string, error)

func ArchitecturePersonalities

func ArchitecturePersonalities(arch int) ([]int, error)

func ArchitecturePersonality

func ArchitecturePersonality(arch int) (string, error)

func AtoiEmptyDefault

func AtoiEmptyDefault(s string, def int) (int, error)

func BlockFsDetect

func BlockFsDetect(dev string) (string, error)

func DebugJson

func DebugJson(r *bytes.Buffer)

func Debugf

func Debugf(format string, args ...interface{})

Debugf sends to the logger registered via SetLogger the string resulting from running format and args through Sprintf, but only if debugging was enabled via SetDebug.

func DeepCopy

func DeepCopy(src, dest interface{}) error

DeepCopy copies src to dest by using encoding/gob so its not that fast.

func ExtractSnapshotName

func ExtractSnapshotName(name string) string

func FileCopy

func FileCopy(source string, dest string) error

FileCopy copies a file, overwriting the target if it exists.

func FileMove

func FileMove(oldPath string, newPath string) error

FileMove tries to move a file by using os.Rename, if that fails it tries to copy the file and remove the source.

func FindOrGenCert

func FindOrGenCert(certf string, keyf string) error

func GenCert

func GenCert(certf string, keyf string) error

func GetFileStat

func GetFileStat(p string) (uid int, gid int, major int, minor int,
	inode uint64, nlink int, err error)

func GetOwner

func GetOwner(path string) (int, int, error)

func GetTLSConfig

func GetTLSConfig(certf string, keyf string) (*tls.Config, error)

func GroupId

func GroupId(name string) (int, error)

GroupId is an adaption from https://codereview.appspot.com/4589049.

func GroupName

func GroupName(gid int) (string, error)

GroupName is an adaption from https://codereview.appspot.com/4589049.

func IntInSlice

func IntInSlice(key int, list []int) bool

func InterfaceToBool

func InterfaceToBool(value interface{}) bool

FIXME: InterfaceToBool is there for backward compatibility

func IsBlockdev

func IsBlockdev(fm os.FileMode) bool

func IsBlockdevPath

func IsBlockdevPath(pathName string) bool

func IsDir

func IsDir(name string) bool

IsDir returns true if the given path is a directory.

func IsLoopback

func IsLoopback(iface *net.Interface) bool

func IsMountPoint

func IsMountPoint(name string) bool

func IsOnSharedMount

func IsOnSharedMount(pathName string) (bool, error)

func IsSnapshot

func IsSnapshot(name string) bool

func LogPath

func LogPath(path ...string) string

LogPath returns the directory that LXD should put logs under. If LXD_DIR is set, this path is $LXD_DIR/logs, otherwise it is /var/log/lxd.

func Logf

func Logf(format string, args ...interface{})

Logf sends to the logger registered via SetLogger the string resulting from running format and args through Sprintf.

func MkdirAllOwner

func MkdirAllOwner(path string, perm os.FileMode, uid int, gid int) error

func OpenPty

func OpenPty(uid, gid int) (master *os.File, slave *os.File, err error)

func ParseLXDFileHeaders

func ParseLXDFileHeaders(headers http.Header) (uid int, gid int, mode os.FileMode)

func ParseMetadata

func ParseMetadata(metadata interface{}) (map[string]interface{}, error)

func PathExists

func PathExists(name string) bool

func PathIsEmpty

func PathIsEmpty(path string) (bool, error)

PathIsEmpty checks if the given path is empty.

func Pipe

func Pipe() (master *os.File, slave *os.File, err error)

func PrintStack

func PrintStack()

func RFC3493Dialer

func RFC3493Dialer(network, address string) (net.Conn, error)

func RandomCryptoString

func RandomCryptoString() (string, error)

Returns a random base64 encoded string from crypto/rand.

func ReadCert

func ReadCert(fpath string) (*x509.Certificate, error)

func ReadDir

func ReadDir(p string) ([]string, error)

func ReadLastNLines

func ReadLastNLines(f *os.File, lines int) (string, error)

func ReadStdin

func ReadStdin() ([]byte, error)

func ReadToJSON

func ReadToJSON(r io.Reader, req interface{}) error

func ReaderToChannel

func ReaderToChannel(r io.Reader) <-chan []byte

func RunningInUserNS

func RunningInUserNS() bool

func SetSize

func SetSize(fd int, width int, height int) (err error)

func ShiftOwner

func ShiftOwner(basepath string, path string, uid int, gid int) error

func SplitExt

func SplitExt(fpath string) (string, string)

func StringInSlice

func StringInSlice(key string, list []string) bool

func TextEditor

func TextEditor(inPath string, inContent []byte) ([]byte, error)

func ValidHostname

func ValidHostname(name string) bool

func VarPath

func VarPath(path ...string) string

VarPath returns the provided path elements joined by a slash and appended to the end of $LXD_DIR, which defaults to /var/lib/lxd.

func WebsocketMirror

func WebsocketMirror(conn *websocket.Conn, w io.WriteCloser, r io.ReadCloser) (chan bool, chan bool)

WebsocketMirror allows mirroring a reader to a websocket and taking the result and writing it to a writer. This function allows for multiple mirrorings and correctly negotiates stream endings. However, it means any websocket.Conns passed to it are live when it returns, and must be closed explicitly.

func WebsocketRecvStream

func WebsocketRecvStream(w io.WriteCloser, conn *websocket.Conn) chan bool

func WebsocketSendStream

func WebsocketSendStream(conn *websocket.Conn, r io.Reader) chan bool

func WriteAll

func WriteAll(w io.Writer, buf []byte) error

func WriteAllBuf

func WriteAllBuf(w io.Writer, buf *bytes.Buffer) error

Types

type BriefContainerState

type BriefContainerState struct {
	Name      string            `json:"name"`
	Profiles  []string          `json:"profiles"`
	Config    map[string]string `json:"config"`
	Devices   Devices           `json:"devices"`
	Ephemeral bool              `json:"ephemeral"`
}

* BriefContainerState contains a subset of the fields in * ContainerState, namely those which a user may update

type BriefImageInfo

type BriefImageInfo struct {
	Properties map[string]string `json:"properties"`
	Public     bool              `json:"public"`
}

* BriefImageInfo contains a subset of the fields in * ImageInfo, namely those which a user may update

type BriefServerState

type BriefServerState struct {
	Config map[string]interface{} `json:"config"`
}

type BytesReadCloser

type BytesReadCloser struct {
	Buf *bytes.Buffer
}

func (BytesReadCloser) Close

func (r BytesReadCloser) Close() error

func (BytesReadCloser) Read

func (r BytesReadCloser) Read(b []byte) (n int, err error)

type CertInfo

type CertInfo struct {
	Certificate string `json:"certificate"`
	Fingerprint string `json:"fingerprint"`
	Type        string `json:"type"`
}

CertInfo is the representation of a Certificate in the API.

type ContainerAction

type ContainerAction string
const (
	Stop     ContainerAction = "stop"
	Start    ContainerAction = "start"
	Restart  ContainerAction = "restart"
	Freeze   ContainerAction = "freeze"
	Unfreeze ContainerAction = "unfreeze"
)

type ContainerExecControl

type ContainerExecControl struct {
	Command string            `json:"command"`
	Args    map[string]string `json:"args"`
}

type ContainerInfo

type ContainerInfo struct {
	State ContainerState `json:"state"`
	Snaps []string       `json:"snaps"`
}

type ContainerInfoList

type ContainerInfoList []ContainerInfo

func (ContainerInfoList) Len

func (slice ContainerInfoList) Len() int

func (ContainerInfoList) Less

func (slice ContainerInfoList) Less(i, j int) bool

func (ContainerInfoList) Swap

func (slice ContainerInfoList) Swap(i, j int)

type ContainerState

type ContainerState struct {
	Architecture    int               `json:"architecture"`
	Config          map[string]string `json:"config"`
	Devices         Devices           `json:"devices"`
	Ephemeral       bool              `json:"ephemeral"`
	ExpandedConfig  map[string]string `json:"expanded_config"`
	ExpandedDevices Devices           `json:"expanded_devices"`
	Name            string            `json:"name"`
	Profiles        []string          `json:"profiles"`
	Status          ContainerStatus   `json:"status"`
}

func (*ContainerState) BriefState

func (c *ContainerState) BriefState() BriefContainerState

func (*ContainerState) BriefStateExpanded

func (c *ContainerState) BriefStateExpanded() BriefContainerState

type ContainerStatus

type ContainerStatus struct {
	Status       string     `json:"status"`
	StatusCode   StatusCode `json:"status_code"`
	Init         int        `json:"init"`
	Processcount int        `json:"processcount"`
	Ips          []Ip       `json:"ips"`
}

type Device

type Device map[string]string

type Devices

type Devices map[string]Device

func (Devices) Contains

func (list Devices) Contains(k string, d Device) bool

func (Devices) ContainsName

func (list Devices) ContainsName(k string) bool

func (Devices) ExtendFromProfile

func (newBaseDevices Devices) ExtendFromProfile(currentFullDevices Devices, newDevicesFromProfile Devices) error

func (Devices) Update

func (old Devices) Update(newlist Devices) (map[string]Device, map[string]Device, map[string]Device)

type IdmapEntry

type IdmapEntry struct {
	Isuid    bool
	Isgid    bool
	Hostid   int // id as seen on the host - i.e. 100000
	Nsid     int // id as seen in the ns - i.e. 0
	Maprange int
}

* One entry in id mapping set - a single range of either * uid or gid mappings.

func Extend

func Extend(slice []IdmapEntry, element IdmapEntry) []IdmapEntry

taken from http://blog.golang.org/slices (which is under BSD licence)

func (*IdmapEntry) Intersects

func (e *IdmapEntry) Intersects(i IdmapEntry) bool

func (*IdmapEntry) ToLxcString

func (e *IdmapEntry) ToLxcString() string

type IdmapSet

type IdmapSet struct {
	Idmap []IdmapEntry
}

func DefaultIdmapSet

func DefaultIdmapSet() (*IdmapSet, error)

* Create a new default idmap

func (IdmapSet) Append

func (m IdmapSet) Append(s string) (IdmapSet, error)

func (IdmapSet) Intersects

func (m IdmapSet) Intersects(i IdmapEntry) bool

func (IdmapSet) Len

func (m IdmapSet) Len() int

func (*IdmapSet) ShiftFile

func (set *IdmapSet) ShiftFile(p string) error

func (IdmapSet) ShiftFromNs

func (m IdmapSet) ShiftFromNs(uid int, gid int) (int, int)

func (IdmapSet) ShiftIntoNs

func (m IdmapSet) ShiftIntoNs(uid int, gid int) (int, int)

func (*IdmapSet) ShiftRootfs

func (set *IdmapSet) ShiftRootfs(p string) error

func (IdmapSet) ToLxcString

func (m IdmapSet) ToLxcString() []string

func (*IdmapSet) UidshiftFromContainer

func (set *IdmapSet) UidshiftFromContainer(dir string, testmode bool) error

func (*IdmapSet) UidshiftIntoContainer

func (set *IdmapSet) UidshiftIntoContainer(dir string, testmode bool) error

func (*IdmapSet) UnshiftRootfs

func (set *IdmapSet) UnshiftRootfs(p string) error

type ImageAlias

type ImageAlias struct {
	Name        string `json:"target"`
	Description string `json:"description"`
}

type ImageAliases

type ImageAliases []ImageAlias

type ImageBaseInfo

type ImageBaseInfo struct {
	Id          int
	Fingerprint string
	Filename    string
	Size        int64

	// FIXME: This is an interface{] instead of a bool for backward compatibility
	Public interface{}

	Architecture int
	CreationDate int64
	ExpiryDate   int64
	UploadDate   int64
}

type ImageInfo

type ImageInfo struct {
	Aliases      ImageAliases      `json:"aliases"`
	Architecture int               `json:"architecture"`
	Fingerprint  string            `json:"fingerprint"`
	Filename     string            `json:"filename"`
	Properties   map[string]string `json:"properties"`

	// FIXME: This is an interface{] instead of a bool for backward compatibility
	Public interface{} `json:"public"`

	Size         int64 `json:"size"`
	CreationDate int64 `json:"created_at"`
	ExpiryDate   int64 `json:"expires_at"`
	UploadDate   int64 `json:"uploaded_at"`
}

func (*ImageInfo) BriefInfo

func (i *ImageInfo) BriefInfo() BriefImageInfo

type ImageProperties

type ImageProperties map[string]string

type Ip

type Ip struct {
	Interface string `json:"interface"`
	Protocol  string `json:"protocol"`
	Address   string `json:"address"`
	HostVeth  string `json:"host_veth"`
}

type Jmap

type Jmap map[string]interface{}

func (Jmap) GetBool

func (m Jmap) GetBool(key string) (bool, error)

func (Jmap) GetInt

func (m Jmap) GetInt(key string) (int, error)

func (Jmap) GetMap

func (m Jmap) GetMap(key string) (Jmap, error)

func (Jmap) GetString

func (m Jmap) GetString(key string) (string, error)

type Logger

type Logger interface {
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Crit(msg string, ctx ...interface{})
}
var Log Logger

type Operation

type Operation struct {
	Id         string              `json:"id"`
	Class      string              `json:"class"`
	CreatedAt  time.Time           `json:"created_at"`
	UpdatedAt  time.Time           `json:"updated_at"`
	Status     string              `json:"status"`
	StatusCode StatusCode          `json:"status_code"`
	Resources  map[string][]string `json:"resources"`
	Metadata   *Jmap               `json:"metadata"`
	MayCancel  bool                `json:"may_cancel"`
	Err        string              `json:"err"`
}

type ProfileConfig

type ProfileConfig struct {
	Name    string            `json:"name"`
	Config  map[string]string `json:"config"`
	Devices Devices           `json:"devices"`
}

type ServerState

type ServerState struct {
	APICompat   int                    `json:"api_compat"`
	Auth        string                 `json:"auth"`
	Environment ServerStateEnvironment `json:"environment"`
	Config      map[string]interface{} `json:"config"`
	Public      bool                   `json:"public"`
}

func (*ServerState) BriefState

func (c *ServerState) BriefState() BriefServerState

type ServerStateEnvironment

type ServerStateEnvironment struct {
	Addresses          []string `json:"addresses"`
	Architectures      []int    `json:"architectures"`
	Driver             string   `json:"driver"`
	DriverVersion      string   `json:"driver_version"`
	Kernel             string   `json:"kernel"`
	KernelArchitecture string   `json:"kernel_architecture"`
	KernelVersion      string   `json:"kernel_version"`
	Server             string   `json:"server"`
	ServerPid          int      `json:"server_pid"`
	ServerVersion      string   `json:"server_version"`
	Storage            string   `json:"storage"`
	StorageVersion     string   `json:"storage_version"`
}

type StatusCode

type StatusCode int
const (
	OperationCreated StatusCode = 100
	Started          StatusCode = 101
	Stopped          StatusCode = 102
	Running          StatusCode = 103
	Cancelling       StatusCode = 104
	Pending          StatusCode = 105
	Starting         StatusCode = 106
	Stopping         StatusCode = 107
	Aborting         StatusCode = 108
	Freezing         StatusCode = 109
	Frozen           StatusCode = 110
	Thawed           StatusCode = 111

	Success StatusCode = 200

	Failure   StatusCode = 400
	Cancelled StatusCode = 401
)

func FromLXCState

func FromLXCState(state int) StatusCode

* Create a StatusCode from an lxc.State code. N.B.: we accept an int instead * of a lxc.State so that the shared code doesn't depend on lxc, which depends * on liblxc, etc.

func (StatusCode) IsFinal

func (o StatusCode) IsFinal() bool

func (StatusCode) String

func (o StatusCode) String() string

type StringSet

type StringSet map[string]bool

func NewStringSet

func NewStringSet(strings []string) StringSet

func (StringSet) IsSubset

func (ss StringSet) IsSubset(oss StringSet) bool

Directories

Path Synopsis
Package flag implements command-line flag parsing in the GNU style.
Package flag implements command-line flag parsing in the GNU style.

Jump to

Keyboard shortcuts

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