Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigValueSet(db *sql.DB, key string, value string) error
- func ConfigValuesGet(db *sql.DB) (map[string]string, error)
- func ContainerConfigClear(tx *sql.Tx, id int) error
- func ContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error
- func ContainerProfilesInsert(tx *sql.Tx, id int, profiles []string) error
- func ContainerUpdate(tx *sql.Tx, id int, description string, architecture int, ephemeral bool) error
- func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error
- func IsDbLockedError(err error) bool
- func NetworkConfigAdd(tx *sql.Tx, id int64, config map[string]string) error
- func NetworkConfigClear(tx *sql.Tx, id int64) error
- func NetworkUpdateDescription(tx *sql.Tx, id int64, description string) error
- func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error
- func ProfileConfigClear(tx *sql.Tx, id int64) error
- func ProfileDescriptionUpdate(tx *sql.Tx, id int64, description string) error
- func StoragePoolConfigAdd(tx *sql.Tx, poolID int64, poolConfig map[string]string) error
- func StoragePoolConfigClear(tx *sql.Tx, poolID int64) error
- func StoragePoolUpdateDescription(tx *sql.Tx, id int64, description string) error
- func StoragePoolVolumeTypeToName(volumeType int) (string, error)
- func StorageVolumeConfigAdd(tx *sql.Tx, volumeID int64, volumeConfig map[string]string) error
- func StorageVolumeConfigClear(tx *sql.Tx, volumeID int64) error
- func StorageVolumeDescriptionUpdate(tx *sql.Tx, volumeID int64, description string) error
- func TxCommit(tx *sql.Tx) error
- func UpdateSchemasDotGo() error
- type CertInfo
- type ContainerArgs
- type ContainerType
- type LegacyPatch
- type Node
- func (n *Node) Begin() (*sql.Tx, error)
- func (n *Node) CertDelete(fingerprint string) error
- func (n *Node) CertSave(cert *CertInfo) error
- func (n *Node) CertUpdate(fingerprint string, certName string, certType int) error
- func (n *Node) CertificateGet(fingerprint string) (cert *CertInfo, err error)
- func (n *Node) CertificatesGet() (certs []*CertInfo, err error)
- func (n *Node) Close() error
- func (n *Node) ContainerConfig(containerId int) (map[string]string, error)
- func (n *Node) ContainerConfigGet(id int, key string) (string, error)
- func (n *Node) ContainerConfigRemove(id int, name string) error
- func (n *Node) ContainerCreate(args ContainerArgs) (int, error)
- func (n *Node) ContainerGet(name string) (ContainerArgs, error)
- func (n *Node) ContainerGetSnapshots(name string) ([]string, error)
- func (n *Node) ContainerId(name string) (int, error)
- func (n *Node) ContainerLastUsedUpdate(id int, date time.Time) error
- func (n *Node) ContainerName(id int) (string, error)
- func (n *Node) ContainerNextSnapshot(name string) int
- func (n *Node) ContainerPool(containerName string) (string, error)
- func (n *Node) ContainerProfiles(containerId int) ([]string, error)
- func (n *Node) ContainerRemove(name string) error
- func (n *Node) ContainerRename(oldName string, newName string) error
- func (n *Node) ContainerSetState(id int, state string) error
- func (n *Node) ContainerSetStateful(id int, stateful bool) error
- func (n *Node) ContainersList(cType ContainerType) ([]string, error)
- func (n *Node) ContainersResetState() error
- func (n *Node) DB() *sql.DB
- func (n *Node) Devices(qName string, isprofile bool) (types.Devices, error)
- func (n *Node) ImageAliasAdd(name string, imageID int, desc string) error
- func (n *Node) ImageAliasDelete(name string) error
- func (n *Node) ImageAliasGet(name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)
- func (n *Node) ImageAliasRename(id int, name string) error
- func (n *Node) ImageAliasUpdate(id int, imageID int, desc string) error
- func (n *Node) ImageAliasesGet() ([]string, error)
- func (n *Node) ImageAliasesMove(source int, destination int) error
- func (n *Node) ImageDelete(id int) error
- func (n *Node) ImageExists(fingerprint string) (bool, error)
- func (n *Node) ImageGet(fingerprint string, public bool, strictMatching bool) (int, *api.Image, error)
- func (n *Node) ImageGetPoolNamesFromIDs(poolIDs []int64) ([]string, error)
- func (n *Node) ImageGetPools(imageFingerprint string) ([]int64, error)
- func (n *Node) ImageInsert(fp string, fname string, sz int64, public bool, autoUpdate bool, ...) error
- func (n *Node) ImageLastAccessInit(fingerprint string) error
- func (n *Node) ImageLastAccessUpdate(fingerprint string, date time.Time) error
- func (n *Node) ImageSourceGet(imageId int) (int, api.ImageSource, error)
- func (n *Node) ImageSourceGetCachedFingerprint(server string, protocol string, alias string) (string, error)
- func (n *Node) ImageSourceInsert(imageId int, server string, protocol string, certificate string, alias string) error
- func (n *Node) ImageUpdate(id int, fname string, sz int64, public bool, autoUpdate bool, ...) error
- func (n *Node) ImageUploadedAt(id int, uploadedAt time.Time) error
- func (n *Node) ImagesGet(public bool) ([]string, error)
- func (n *Node) ImagesGetExpired(expiry int64) ([]string, error)
- func (n *Node) NetworkConfigGet(id int64) (map[string]string, error)
- func (n *Node) NetworkCreate(name, description string, config map[string]string) (int64, error)
- func (n *Node) NetworkDelete(name string) error
- func (n *Node) NetworkGet(name string) (int64, *api.Network, error)
- func (n *Node) NetworkGetInterface(devName string) (int64, *api.Network, error)
- func (n *Node) NetworkRename(oldName string, newName string) error
- func (n *Node) NetworkUpdate(name, description string, config map[string]string) error
- func (n *Node) Networks() ([]string, error)
- func (n *Node) Patches() ([]string, error)
- func (n *Node) PatchesMarkApplied(patch string) error
- func (n *Node) ProfileCleanupLeftover() error
- func (n *Node) ProfileConfig(name string) (map[string]string, error)
- func (n *Node) ProfileContainersGet(profile string) ([]string, error)
- func (n *Node) ProfileCreate(profile string, description string, config map[string]string, ...) (int64, error)
- func (n *Node) ProfileCreateDefault() error
- func (n *Node) ProfileDelete(name string) error
- func (n *Node) ProfileGet(name string) (int64, *api.Profile, error)
- func (n *Node) ProfileUpdate(name string, newName string) error
- func (n *Node) Profiles() ([]string, error)
- func (n *Node) StoragePoolConfigGet(poolID int64) (map[string]string, error)
- func (n *Node) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, ...) (int64, error)
- func (n *Node) StoragePoolDelete(poolName string) (*api.StoragePool, error)
- func (n *Node) StoragePoolGet(poolName string) (int64, *api.StoragePool, error)
- func (n *Node) StoragePoolGetID(poolName string) (int64, error)
- func (n *Node) StoragePoolInsertZfsDriver() error
- func (n *Node) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error
- func (n *Node) StoragePoolVolumeCreate(volumeName, volumeDescription string, volumeType int, poolID int64, ...) (int64, error)
- func (n *Node) StoragePoolVolumeDelete(volumeName string, volumeType int, poolID int64) error
- func (n *Node) StoragePoolVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error)
- func (n *Node) StoragePoolVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error)
- func (n *Node) StoragePoolVolumeRename(oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error
- func (n *Node) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, ...) error
- func (n *Node) StoragePoolVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)
- func (n *Node) StoragePoolVolumesGetNames(poolID int64) (int, error)
- func (n *Node) StoragePoolVolumesGetType(volumeType int, poolID int64) ([]string, error)
- func (n *Node) StoragePools() ([]string, error)
- func (n *Node) StoragePoolsGetDrivers() ([]string, error)
- func (n *Node) StorageVolumeCleanupImages() error
- func (n *Node) StorageVolumeConfigGet(volumeID int64) (map[string]string, error)
- func (n *Node) StorageVolumeDescriptionGet(volumeID int64) (string, error)
- func (n *Node) StorageVolumeMoveToLVMThinPoolNameKey() error
- func (n *Node) Transaction(f func(*NodeTx) error) error
- type NodeTx
Constants ¶
const ( StoragePoolVolumeTypeContainer = iota StoragePoolVolumeTypeImage StoragePoolVolumeTypeCustom )
XXX: this was extracted from lxd/storage_volume_utils.go, we find a way to
factor it independently from both the db and main packages.
const ( StoragePoolVolumeTypeNameContainer string = "container" StoragePoolVolumeTypeNameImage string = "image" StoragePoolVolumeTypeNameCustom string = "custom" )
Leave the string type in here! This guarantees that go treats this is as a typed string constant. Removing it causes go to treat these as untyped string constants which is not what we want.
Variables ¶
var ( // DbErrAlreadyDefined hapens when the given entry already exists, // for example a container. DbErrAlreadyDefined = fmt.Errorf("The container/snapshot already exists") /* NoSuchObjectError is in the case of joins (and probably other) queries, * we don't get back sql.ErrNoRows when no rows are returned, even though we do * on selects without joins. Instead, you can use this error to * propagate up and generate proper 404s to the client when something * isn't found so we don't abuse sql.ErrNoRows any more than we * already do. */ NoSuchObjectError = fmt.Errorf("No such object") )
var ImageSourceProtocol = map[int]string{
0: "lxd",
1: "direct",
2: "simplestreams",
}
Functions ¶
func ContainerConfigInsert ¶
func ContainerProfilesInsert ¶
func ContainerUpdate ¶
func IsDbLockedError ¶
func StoragePoolConfigAdd ¶
Add new storage pool config.
func StoragePoolConfigClear ¶
Delete storage pool config.
func StoragePoolUpdateDescription ¶
Update the storage pool description.
func StoragePoolVolumeTypeToName ¶
StoragePoolVolumeTypeToName converts a volume integer type code to its human-readable name.
func StorageVolumeConfigAdd ¶
Add new storage volume config into database.
func StorageVolumeConfigClear ¶
Delete storage volume config.
func StorageVolumeDescriptionUpdate ¶
Update description of a storage volume.
func UpdateSchemasDotGo ¶
func UpdateSchemasDotGo() error
UpdateSchemasDotGo updates the schema.go files in the local/ and cluster/ sub-packages.
Types ¶
type ContainerArgs ¶
type ContainerArgs struct { // Don't set manually Id int Description string Architecture int BaseImage string Config map[string]string CreationDate time.Time LastUsedDate time.Time Ctype ContainerType Devices types.Devices Ephemeral bool Name string Profiles []string Stateful bool }
ContainerArgs is a value object holding all db-related details about a container.
type ContainerType ¶
type ContainerType int
ContainerType encodes the type of container (either regular or snapshot).
const ( CTypeRegular ContainerType = 0 CTypeSnapshot ContainerType = 1 )
type LegacyPatch ¶
type LegacyPatch struct { NeedsDB bool // Whether the patch does any DB-related work Hook func(*sql.DB) error // The actual patch logic }
LegacyPatch is a "database" update that performs non-database work. They are needed for historical reasons, since there was a time were db updates could do non-db work and depend on functionality external to the db package. See UpdatesApplyAll below.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node mediates access to LXD's data stored in the node-local SQLite database.
func ForLegacyPatches ¶
ForLegacyPatches is a aid for the hack in initializeDbObject, which sets the db-related Deamon attributes upfront, to be backward compatible with the legacy patches that need to interact with the database.
func NewTestNode ¶
NewTestNode creates a new Node for testing purposes, along with a function that can be used to clean it up when done.
func OpenNode ¶
func OpenNode(dir string, fresh func(*Node) error, legacyPatches map[int]*LegacyPatch) (*Node, error)
OpenNode creates a new Node object.
The fresh hook parameter is used by the daemon to mark all known patch names as applied when a brand new database is created.
The legacyPatches parameter is used as a mean to apply the legacy V10, V11, V15, V29 and V30 non-db updates during the database upgrade sequence, to avoid any change in semantics wrt the old logic (see PR #3322).
func (*Node) CertDelete ¶
CertDelete deletes a certificate from the db.
func (*Node) CertSave ¶
CertSave stores a CertBaseInfo object in the db, it will ignore the ID field from the CertInfo.
func (*Node) CertUpdate ¶
func (*Node) CertificateGet ¶
CertificateGet gets an CertBaseInfo object from the database. The argument fingerprint will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.
func (*Node) CertificatesGet ¶
CertificatesGet returns all certificates from the DB as CertBaseInfo objects.
func (*Node) ContainerConfig ¶
ContainerConfig gets the container configuration map from the DB
func (*Node) ContainerConfigGet ¶
func (*Node) ContainerConfigRemove ¶
func (*Node) ContainerCreate ¶
func (n *Node) ContainerCreate(args ContainerArgs) (int, error)
func (*Node) ContainerGet ¶
func (n *Node) ContainerGet(name string) (ContainerArgs, error)
func (*Node) ContainerGetSnapshots ¶
func (*Node) ContainerLastUsedUpdate ¶
func (*Node) ContainerNextSnapshot ¶
* Note, the code below doesn't deal with snapshots of snapshots. * To do that, we'll need to weed out based on # slashes in names
func (*Node) ContainerPool ¶
Get the storage pool of a given container.
func (*Node) ContainerProfiles ¶
Get a list of profiles for a given container id.
func (*Node) ContainerRemove ¶
func (*Node) ContainerSetStateful ¶
func (*Node) ContainersList ¶
func (n *Node) ContainersList(cType ContainerType) ([]string, error)
func (*Node) ContainersResetState ¶
func (*Node) DB ¶
DB returns the low level database handle to the node-local SQLite database.
FIXME: this is used for compatibility with some legacy code, and should be
dropped once there are no call sites left.
func (*Node) ImageAliasAdd ¶
Insert an alias ento the database.
func (*Node) ImageAliasDelete ¶
func (*Node) ImageAliasGet ¶
func (*Node) ImageAliasUpdate ¶
func (*Node) ImageAliasesGet ¶
func (*Node) ImageDelete ¶
func (*Node) ImageExists ¶
Whether an image with the given fingerprint exists.
func (*Node) ImageGet ¶
func (n *Node) ImageGet(fingerprint string, public bool, strictMatching bool) (int, *api.Image, error)
ImageGet gets an Image object from the database. If strictMatching is false, The fingerprint argument will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.
func (*Node) ImageGetPoolNamesFromIDs ¶
Get the names of all storage pools on which a given image exists.
func (*Node) ImageGetPools ¶
Get the names of all storage pools on which a given image exists.
func (*Node) ImageInsert ¶
func (*Node) ImageLastAccessInit ¶
func (*Node) ImageLastAccessUpdate ¶
func (*Node) ImageSourceGet ¶
func (*Node) ImageSourceGetCachedFingerprint ¶
func (n *Node) ImageSourceGetCachedFingerprint(server string, protocol string, alias string) (string, error)
Try to find a source entry of a locally cached image that matches the given remote details (server, protocol and alias). Return the fingerprint linked to the matching entry, if any.
func (*Node) ImageSourceInsert ¶
func (*Node) ImageUpdate ¶
func (*Node) ImageUploadedAt ¶
ImageUploadedAt updates the upload_date column and an image row.
func (*Node) NetworkConfigGet ¶
func (*Node) NetworkCreate ¶
func (*Node) NetworkDelete ¶
func (*Node) NetworkGetInterface ¶
func (*Node) NetworkUpdate ¶
func (*Node) PatchesMarkApplied ¶
func (*Node) ProfileCleanupLeftover ¶
func (*Node) ProfileConfig ¶
Get the profile configuration map from the DB
func (*Node) ProfileContainersGet ¶
func (*Node) ProfileCreate ¶
func (*Node) ProfileCreateDefault ¶
func (*Node) ProfileDelete ¶
func (*Node) StoragePoolConfigGet ¶
Get config of a storage pool.
func (*Node) StoragePoolCreate ¶
func (n *Node) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error)
Create new storage pool.
func (*Node) StoragePoolDelete ¶
func (n *Node) StoragePoolDelete(poolName string) (*api.StoragePool, error)
Delete storage pool.
func (*Node) StoragePoolGet ¶
Get a single storage pool.
func (*Node) StoragePoolGetID ¶
Get id of a single storage pool.
func (*Node) StoragePoolInsertZfsDriver ¶
func (*Node) StoragePoolUpdate ¶
Update storage pool.
func (*Node) StoragePoolVolumeCreate ¶
func (n *Node) StoragePoolVolumeCreate(volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string) (int64, error)
Create new storage volume attached to a given storage pool.
func (*Node) StoragePoolVolumeDelete ¶
Delete storage volume attached to a given storage pool.
func (*Node) StoragePoolVolumeGetType ¶
func (n *Node) StoragePoolVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error)
Get a single storage volume attached to a given storage pool of a given type.
func (*Node) StoragePoolVolumeGetTypeID ¶
func (n *Node) StoragePoolVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error)
Get ID of a storage volume on a given storage pool of a given storage volume type.
func (*Node) StoragePoolVolumeRename ¶
func (n *Node) StoragePoolVolumeRename(oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error
Rename storage volume attached to a given storage pool.
func (*Node) StoragePoolVolumeUpdate ¶
func (n *Node) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error
Update storage volume attached to a given storage pool.
func (*Node) StoragePoolVolumesGet ¶
Get all storage volumes attached to a given storage pool.
func (*Node) StoragePoolVolumesGetNames ¶
Get the names of all storage volumes attached to a given storage pool.
func (*Node) StoragePoolVolumesGetType ¶
Get all storage volumes attached to a given storage pool of a given volume type.
func (*Node) StoragePoolsGetDrivers ¶
Get the names of all storage volumes attached to a given storage pool.
func (*Node) StorageVolumeCleanupImages ¶
func (*Node) StorageVolumeConfigGet ¶
Get config of a storage volume.
func (*Node) StorageVolumeDescriptionGet ¶
Get the description of a storage volume.
func (*Node) StorageVolumeMoveToLVMThinPoolNameKey ¶
func (*Node) Transaction ¶
Transaction creates a new NodeTx object and transactionally executes the node-level database interactions invoked by the given function. If the function returns no error, all database changes are committed to the node-level database, otherwise they are rolled back.
type NodeTx ¶
type NodeTx struct {
// contains filtered or unexported fields
}
NodeTx models a single interaction with a LXD node-local database.
It wraps low-level sql.Tx objects and offers a high-level API to fetch and update data.
func NewTestNodeTx ¶
NewTestNodeTx returns a fresh NodeTx object, along with a function that can be called to cleanup state when done with it.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package query implements helpers around database/sql to execute various kinds of very common SQL queries.
|
Package query implements helpers around database/sql to execute various kinds of very common SQL queries. |
Package schema offers utilities to create and maintain a database schema.
|
Package schema offers utilities to create and maintain a database schema. |