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 ¶
- Variables
- func AddDevices(tx *sql.Tx, w string, cId int, devices Devices) error
- func AtoiEmptyDefault(s string, def int) (int, error)
- func CopyFile(dest string, source string) error
- func DbExec(db *sql.DB, q string, args ...interface{}) (sql.Result, error)
- func DbQuery(db *sql.DB, q string, args ...interface{}) (*sql.Rows, error)
- func DbQueryRowScan(db *sql.DB, q string, args []interface{}, outargs []interface{}) error
- func DebugJson(r *bytes.Buffer)
- func Debugf(format string, args ...interface{})
- func FindOrGenCert(certf string, keyf string) error
- func GenCert(certf string, keyf string) error
- func GenerateFingerprint(cert *x509.Certificate) string
- func GetTLSConfig(certf string, keyf string) (*tls.Config, error)
- func GroupId(name string) (int, error)
- func GroupName(gid int) (string, error)
- func IsDbLockedError(err error) bool
- func IsDir(name string) bool
- func LogPath(path ...string) string
- func Logf(format string, args ...interface{})
- func OpenPty() (master *os.File, slave *os.File, err error)
- func OperationWrap(f func() error) func() OperationResult
- func OperationsURL(id string) string
- func ParseLXDFileHeaders(headers http.Header) (uid int, gid int, mode os.FileMode, err error)
- func PathExists(name string) bool
- func Pipe() (master *os.File, slave *os.File, err error)
- func RFC3493Dialer(network, address string) (net.Conn, error)
- func RandomCryptoString() (string, error)
- func ReadCert(fpath string) (*x509.Certificate, error)
- func ReadStdin() ([]byte, error)
- func ReadToJSON(r io.Reader, req interface{}) error
- func ReaderToChannel(r io.Reader) <-chan []byte
- func SetDebug(enabled bool)
- func SetLogger(l Logger)
- func SplitExt(fpath string) (string, string)
- func TxCommit(tx *sql.Tx) error
- func Uidshift(dir string, idmap IdmapSet, testmode bool) error
- func ValidDeviceConfig(t, k, v string) bool
- func ValidDeviceType(t string) bool
- func VarPath(path ...string) string
- func WebsocketMirror(conn *websocket.Conn, w io.WriteCloser, r io.Reader) chan bool
- func WebsocketRecvStream(w io.WriteCloser, conn *websocket.Conn) chan bool
- func WebsocketSendStream(conn *websocket.Conn, r io.Reader) chan bool
- func WriteAll(w io.Writer, buf []byte) error
- func WriteAllBuf(w io.Writer, buf *bytes.Buffer) error
- type BytesReadCloser
- type ContainerAction
- type ContainerState
- type ContainerStatus
- type Device
- type Devices
- type Idmap
- type IdmapSet
- type ImageAlias
- type ImageAliases
- type ImageBaseInfo
- type ImageInfo
- type ImageProperties
- type ImageProperty
- type Ip
- type Jmap
- type Logger
- type Operation
- type OperationResult
- type OperationStatus
- type OperationWebsocket
- type ProfileConfig
- type StringSet
Constants ¶
This section is empty.
Variables ¶
var APICompat = 1
* Please increment the api compat number every time you change the API. * * Version 1.0: ping
var APIVersion = "1.0"
var UserAgent = "LXD " + Version
var Version = "0.7"
Functions ¶
func DbQueryRowScan ¶
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 FindOrGenCert ¶
func GenerateFingerprint ¶
func GenerateFingerprint(cert *x509.Certificate) string
func GroupId ¶
GroupId is an adaption from https://codereview.appspot.com/4589049.
func GroupName ¶
GroupName is an adaption from https://codereview.appspot.com/4589049.
func IsDbLockedError ¶
func LogPath ¶
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 OperationWrap ¶
func OperationWrap(f func() error) func() OperationResult
func OperationsURL ¶
func ParseLXDFileHeaders ¶
func PathExists ¶
func RandomCryptoString ¶
Returns a random base64 encoded string from crypto/rand.
func ReadToJSON ¶
func ReaderToChannel ¶
func SetLogger ¶
func SetLogger(l Logger)
SetLogger defines the *log.Logger where log messages are sent to.
func ValidDeviceConfig ¶
func ValidDeviceType ¶
func VarPath ¶
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 ¶
WebsocketMirror allows mirroring a reader to a websocket and taking the result and writing it to a writer.
func WebsocketRecvStream ¶
func WebsocketRecvStream(w io.WriteCloser, conn *websocket.Conn) chan bool
Types ¶
type BytesReadCloser ¶
func (BytesReadCloser) Close ¶
func (r BytesReadCloser) Close() error
type ContainerAction ¶
type ContainerAction string
const ( Stop ContainerAction = "stop" Start ContainerAction = "start" Restart ContainerAction = "restart" Freeze ContainerAction = "freeze" Unfreeze ContainerAction = "unfreeze" )
type ContainerState ¶
type ContainerState struct { Name string `json:"name"` Profiles []string `json:"profiles"` Config map[string]string `json:"config"` Userdata []byte `json:"userdata"` Status ContainerStatus `json:"status"` Devices Devices `json:"devices"` Ephemeral bool `json:"ephemeral"` }
func (*ContainerState) State ¶
func (c *ContainerState) State() lxc.State
type ContainerStatus ¶
type ContainerStatus struct { State string `json:"status"` StateCode lxc.State `json:"status_code"` Init int `json:"init"` Ips []Ip `json:"ips"` }
func NewStatus ¶
func NewStatus(c *lxc.Container, state lxc.State) ContainerStatus
type Idmap ¶
* We'll flesh this out to be lists of ranges * We will want a list of available ranges (all ranges * which LXD may use) and taken range (parts of the * available ranges which are already in use by containers) * * We also may want some way of deciding which containers may * or perhaps must not share ranges * * For now, we simply have a single range, shared by all * containers
func (*Idmap) ShiftRootfs ¶
type ImageAlias ¶
type ImageAliases ¶
type ImageAliases []ImageAlias
type ImageBaseInfo ¶
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"` Public int `json:"public"` Size int64 `json:"size"` CreationDate int64 `json:"created_at"` ExpiryDate int64 `json:"expires_at"` UploadDate int64 `json:"uploaded_at"` }
type ImageProperties ¶
type ImageProperties []ImageProperty
type ImageProperty ¶
type Operation ¶
type Operation struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Status string `json:"status"` StatusCode OperationStatus `json:"status_code"` Resources map[string][]string `json:"resources"` Metadata json.RawMessage `json:"metadata"` MayCancel bool `json:"may_cancel"` /* The fields below are for use on the server side. */ Run func() OperationResult `json:"-"` /* If this is not nil, the operation can be cancelled by calling this * function */ Cancel func() error `json:"-"` /* This channel receives exactly one value, when the event is done and * the status is updated */ Chan chan bool `json:"-"` /* If this is not nil, users can connect to a websocket for this * operation. The flag indicates whether or not this socket has already * been used: websockets can be connected to exactly once. */ Websocket OperationWebsocket `json:"-"` }
func (*Operation) MetadataAsMap ¶
func (*Operation) SetResult ¶
func (o *Operation) SetResult(result OperationResult)
func (*Operation) SetStatus ¶
func (o *Operation) SetStatus(status OperationStatus)
func (*Operation) SetStatusByErr ¶
type OperationResult ¶
type OperationResult struct { Metadata json.RawMessage Error error }
var OperationSuccess OperationResult = OperationResult{}
func OperationError ¶
func OperationError(err error) OperationResult
type OperationStatus ¶
type OperationStatus int
const ( OK OperationStatus = 100 Started OperationStatus = 101 Stopped OperationStatus = 102 Running OperationStatus = 103 Cancelling OperationStatus = 104 Pending OperationStatus = 105 Success OperationStatus = 200 Failure OperationStatus = 400 Cancelled OperationStatus = 401 )
func (OperationStatus) IsFinal ¶
func (o OperationStatus) IsFinal() bool
func (OperationStatus) String ¶
func (o OperationStatus) String() string
type OperationWebsocket ¶
type OperationWebsocket interface { // Metadata() specifies the metadata for the initial response this // OperationWebsocket renders. Metadata() interface{} // Connect should return the error if the connection failed, // or nil if the connection was successful. Connect(secret string, r *http.Request, w http.ResponseWriter) error // Run the actual operation and return its result. Do() OperationResult }
OperationWebsocket represents the /websocket endpoint for operations. Users can connect by specifying a secret (given to them at operation creation time). As soon as the operation is created, the websocket's Do() function is called. It is up to the Do() function to block and wait for any connections it expects before proceeding.