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
- Variables
- func AtoiEmptyDefault(s string, def int) (int, error)
- func CopyFile(dest string, source string) error
- func DbBegin(db *sql.DB) (*sql.Tx, 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 DbQueryScan(db *sql.DB, q string, inargs []interface{}, outfmt []interface{}) ([][]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 GetFilesystem(path string) (string, error)
- func GetTLSConfig(certf string, keyf string) (*tls.Config, error)
- func GroupId(name string) (int, error)
- func GroupName(gid int) (string, error)
- func IsBridge(iface *net.Interface) bool
- func IsDbLockedError(err error) bool
- func IsDir(name string) bool
- func IsLoopback(iface *net.Interface) bool
- func IsSnapshot(name string) bool
- func LogPath(path ...string) string
- func Logf(format string, args ...interface{})
- func OpenPty(uid, gid int) (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 PrintStack()
- func RFC3493Dialer(network, address string) (net.Conn, error)
- func RandomCryptoString() (string, error)
- func ReadCert(fpath string) (*x509.Certificate, error)
- func ReadLastNLines(f *os.File, lines int) (string, 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 SetSize(fd int, width int, height int) (err error)
- func SplitExt(fpath string) (string, string)
- func TxCommit(tx *sql.Tx) error
- 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 BriefContainerState
- type BriefServerState
- type BytesReadCloser
- type ContainerAction
- type ContainerExecControl
- type ContainerInfo
- type ContainerState
- type ContainerStatus
- type Device
- type Devices
- type IdmapSet
- func (m IdmapSet) Append(s string) (IdmapSet, error)
- func (m IdmapSet) Intersects(i idmapEntry) bool
- func (m IdmapSet) Len() int
- func (m IdmapSet) ShiftIntoNs(uid int, gid int) (int, int)
- func (set *IdmapSet) ShiftRootfs(p string) error
- func (m IdmapSet) ToLxcString() []string
- func (set *IdmapSet) UidshiftIntoContainer(dir string, testmode bool) error
- type ImageAlias
- type ImageAliases
- type ImageBaseInfo
- type ImageInfo
- type ImageProperties
- type Ip
- type Jmap
- type Logger
- type Operation
- type OperationResult
- type OperationStatus
- type OperationWebsocket
- type ProfileConfig
- type ServerState
- type State
- type StringSet
Constants ¶
const (
SYS_CLASS_NET = "/sys/class/net"
)
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 StateMap = map[string]State{ "STOPPED": STOPPED, "STARTING": STARTING, "RUNNING": RUNNING, "STOPPING": STOPPING, "ABORTING": ABORTING, "FREEZING": FREEZING, "FROZEN": FROZEN, "THAWED": THAWED, }
var UserAgent = "LXD " + Version
var Version = "0.10"
Functions ¶
func DbQueryRowScan ¶
func DbQueryScan ¶
func DbQueryScan(db *sql.DB, q string, inargs []interface{}, outfmt []interface{}) ([][]interface{}, error)
* . q is the database query * . inargs is an array of interfaces containing the query arguments * . outfmt is an array of interfaces containing the right types of output * arguments, i.e. * var arg1 string * var arg2 int * outfmt := {}interface{}{arg1, arg2} * * The result will be an array (one per output row) of arrays (one per output argument) * of interfaces, containing pointers to the actual output arguments.
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 GetFilesystem ¶
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 IsLoopback ¶
func IsSnapshot ¶
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 PrintStack ¶
func PrintStack()
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 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 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 BriefServerState ¶
type BriefServerState struct {
Config map[string]interface{} `json:"config"`
}
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 ContainerExecControl ¶
type ContainerInfo ¶
type ContainerInfo struct { State ContainerState `json:"state"` Snaps []string `json:"snaps"` }
type ContainerState ¶
type ContainerState struct { Name string `json:"name"` Profiles []string `json:"profiles"` Config map[string]string `json:"config"` ExpandedConfig map[string]string `json:"expanded_config"` Userdata []byte `json:"userdata"` Status ContainerStatus `json:"status"` Devices Devices `json:"devices"` ExpandedDevices Devices `json:"expanded_devices"` Ephemeral bool `json:"ephemeral"` Log string `json:"log"` }
func (*ContainerState) BriefState ¶
func (c *ContainerState) BriefState() BriefContainerState
func (*ContainerState) State ¶
func (c *ContainerState) State() State
type ContainerStatus ¶
type IdmapSet ¶
type IdmapSet struct {
// contains filtered or unexported fields
}
func (IdmapSet) Intersects ¶
func (*IdmapSet) ShiftRootfs ¶
func (IdmapSet) ToLxcString ¶
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 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.
type ProfileConfig ¶
type ServerState ¶
type ServerState struct { APICompat int `json:"api_compat"` Auth string `json:"auth"` Environment map[string]string `json:"environment"` Config map[string]interface{} `json:"config"` }
func (*ServerState) BriefState ¶
func (c *ServerState) BriefState() BriefServerState
type State ¶
type State int
State type specifies possible container states.
const ( // STOPPED means container is not running STOPPED State = iota + 1 // STARTING means container is starting STARTING // RUNNING means container is running RUNNING // STOPPING means container is stopping STOPPING // ABORTING means container is aborting ABORTING // FREEZING means container is freezing FREEZING // FROZEN means containe is frozen FROZEN // THAWED means container is thawed THAWED )