db

package
v0.0.0-...-f59c3e7 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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.
View Source
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

View Source
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")
)
View Source
var ImageSourceProtocol = map[int]string{
	0: "lxd",
	1: "direct",
	2: "simplestreams",
}

Functions

func ConfigValueSet

func ConfigValueSet(db *sql.DB, key string, value string) error

func ConfigValuesGet

func ConfigValuesGet(db *sql.DB) (map[string]string, error)

func ContainerConfigClear

func ContainerConfigClear(tx *sql.Tx, id int) error

func ContainerConfigInsert

func ContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error

func ContainerProfilesInsert

func ContainerProfilesInsert(tx *sql.Tx, id int, profiles []string) error

func ContainerUpdate

func ContainerUpdate(tx *sql.Tx, id int, description string, architecture int, ephemeral bool) error

func DevicesAdd

func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error

func IsDbLockedError

func IsDbLockedError(err error) bool

func NetworkConfigAdd

func NetworkConfigAdd(tx *sql.Tx, id int64, config map[string]string) error

func NetworkConfigClear

func NetworkConfigClear(tx *sql.Tx, id int64) error

func NetworkUpdateDescription

func NetworkUpdateDescription(tx *sql.Tx, id int64, description string) error

func ProfileConfigAdd

func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error

func ProfileConfigClear

func ProfileConfigClear(tx *sql.Tx, id int64) error

func ProfileDescriptionUpdate

func ProfileDescriptionUpdate(tx *sql.Tx, id int64, description string) error

func StoragePoolConfigAdd

func StoragePoolConfigAdd(tx *sql.Tx, poolID int64, poolConfig map[string]string) error

Add new storage pool config.

func StoragePoolConfigClear

func StoragePoolConfigClear(tx *sql.Tx, poolID int64) error

Delete storage pool config.

func StoragePoolUpdateDescription

func StoragePoolUpdateDescription(tx *sql.Tx, id int64, description string) error

Update the storage pool description.

func StoragePoolVolumeTypeToName

func StoragePoolVolumeTypeToName(volumeType int) (string, error)

StoragePoolVolumeTypeToName converts a volume integer type code to its human-readable name.

func StorageVolumeConfigAdd

func StorageVolumeConfigAdd(tx *sql.Tx, volumeID int64, volumeConfig map[string]string) error

Add new storage volume config into database.

func StorageVolumeConfigClear

func StorageVolumeConfigClear(tx *sql.Tx, volumeID int64) error

Delete storage volume config.

func StorageVolumeDescriptionUpdate

func StorageVolumeDescriptionUpdate(tx *sql.Tx, volumeID int64, description string) error

Update description of a storage volume.

func TxCommit

func TxCommit(tx *sql.Tx) error

func UpdateSchemasDotGo

func UpdateSchemasDotGo() error

UpdateSchemasDotGo updates the schema.go files in the local/ and cluster/ sub-packages.

Types

type CertInfo

type CertInfo struct {
	ID          int
	Fingerprint string
	Type        int
	Name        string
	Certificate string
}

CertInfo is here to pass the certificates content from the database around

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

func ForLegacyPatches(db *sql.DB) *Node

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

func NewTestNode(t *testing.T) (*Node, func())

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

func (n *Node) Begin() (*sql.Tx, error)

Begin a new transaction against the local database. Legacy method.

func (*Node) CertDelete

func (n *Node) CertDelete(fingerprint string) error

CertDelete deletes a certificate from the db.

func (*Node) CertSave

func (n *Node) CertSave(cert *CertInfo) error

CertSave stores a CertBaseInfo object in the db, it will ignore the ID field from the CertInfo.

func (*Node) CertUpdate

func (n *Node) CertUpdate(fingerprint string, certName string, certType int) error

func (*Node) CertificateGet

func (n *Node) CertificateGet(fingerprint string) (cert *CertInfo, err error)

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

func (n *Node) CertificatesGet() (certs []*CertInfo, err error)

CertificatesGet returns all certificates from the DB as CertBaseInfo objects.

func (*Node) Close

func (n *Node) Close() error

Close the database facade.

func (*Node) ContainerConfig

func (n *Node) ContainerConfig(containerId int) (map[string]string, error)

ContainerConfig gets the container configuration map from the DB

func (*Node) ContainerConfigGet

func (n *Node) ContainerConfigGet(id int, key string) (string, error)

func (*Node) ContainerConfigRemove

func (n *Node) ContainerConfigRemove(id int, name string) error

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 (n *Node) ContainerGetSnapshots(name string) ([]string, error)

func (*Node) ContainerId

func (n *Node) ContainerId(name string) (int, error)

func (*Node) ContainerLastUsedUpdate

func (n *Node) ContainerLastUsedUpdate(id int, date time.Time) error

func (*Node) ContainerName

func (n *Node) ContainerName(id int) (string, error)

func (*Node) ContainerNextSnapshot

func (n *Node) ContainerNextSnapshot(name string) int

* 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

func (n *Node) ContainerPool(containerName string) (string, error)

Get the storage pool of a given container.

func (*Node) ContainerProfiles

func (n *Node) ContainerProfiles(containerId int) ([]string, error)

Get a list of profiles for a given container id.

func (*Node) ContainerRemove

func (n *Node) ContainerRemove(name string) error

func (*Node) ContainerRename

func (n *Node) ContainerRename(oldName string, newName string) error

func (*Node) ContainerSetState

func (n *Node) ContainerSetState(id int, state string) error

func (*Node) ContainerSetStateful

func (n *Node) ContainerSetStateful(id int, stateful bool) error

func (*Node) ContainersList

func (n *Node) ContainersList(cType ContainerType) ([]string, error)

func (*Node) ContainersResetState

func (n *Node) ContainersResetState() error

func (*Node) DB

func (n *Node) DB() *sql.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) Devices

func (n *Node) Devices(qName string, isprofile bool) (types.Devices, error)

func (*Node) ImageAliasAdd

func (n *Node) ImageAliasAdd(name string, imageID int, desc string) error

Insert an alias ento the database.

func (*Node) ImageAliasDelete

func (n *Node) ImageAliasDelete(name string) error

func (*Node) ImageAliasGet

func (n *Node) ImageAliasGet(name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)

func (*Node) ImageAliasRename

func (n *Node) ImageAliasRename(id int, name string) error

func (*Node) ImageAliasUpdate

func (n *Node) ImageAliasUpdate(id int, imageID int, desc string) error

func (*Node) ImageAliasesGet

func (n *Node) ImageAliasesGet() ([]string, error)

func (*Node) ImageAliasesMove

func (n *Node) ImageAliasesMove(source int, destination int) error

func (*Node) ImageDelete

func (n *Node) ImageDelete(id int) error

func (*Node) ImageExists

func (n *Node) ImageExists(fingerprint string) (bool, error)

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

func (n *Node) ImageGetPoolNamesFromIDs(poolIDs []int64) ([]string, error)

Get the names of all storage pools on which a given image exists.

func (*Node) ImageGetPools

func (n *Node) ImageGetPools(imageFingerprint string) ([]int64, error)

Get the names of all storage pools on which a given image exists.

func (*Node) ImageInsert

func (n *Node) ImageInsert(fp string, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string) error

func (*Node) ImageLastAccessInit

func (n *Node) ImageLastAccessInit(fingerprint string) error

func (*Node) ImageLastAccessUpdate

func (n *Node) ImageLastAccessUpdate(fingerprint string, date time.Time) error

func (*Node) ImageSourceGet

func (n *Node) ImageSourceGet(imageId int) (int, api.ImageSource, error)

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 (n *Node) ImageSourceInsert(imageId int, server string, protocol string, certificate string, alias string) error

func (*Node) ImageUpdate

func (n *Node) ImageUpdate(id int, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string) error

func (*Node) ImageUploadedAt

func (n *Node) ImageUploadedAt(id int, uploadedAt time.Time) error

ImageUploadedAt updates the upload_date column and an image row.

func (*Node) ImagesGet

func (n *Node) ImagesGet(public bool) ([]string, error)

func (*Node) ImagesGetExpired

func (n *Node) ImagesGetExpired(expiry int64) ([]string, error)

func (*Node) NetworkConfigGet

func (n *Node) NetworkConfigGet(id int64) (map[string]string, error)

func (*Node) NetworkCreate

func (n *Node) NetworkCreate(name, description string, config map[string]string) (int64, error)

func (*Node) NetworkDelete

func (n *Node) NetworkDelete(name string) error

func (*Node) NetworkGet

func (n *Node) NetworkGet(name string) (int64, *api.Network, error)

func (*Node) NetworkGetInterface

func (n *Node) NetworkGetInterface(devName string) (int64, *api.Network, error)

func (*Node) NetworkRename

func (n *Node) NetworkRename(oldName string, newName string) error

func (*Node) NetworkUpdate

func (n *Node) NetworkUpdate(name, description string, config map[string]string) error

func (*Node) Networks

func (n *Node) Networks() ([]string, error)

func (*Node) Patches

func (n *Node) Patches() ([]string, error)

func (*Node) PatchesMarkApplied

func (n *Node) PatchesMarkApplied(patch string) error

func (*Node) ProfileCleanupLeftover

func (n *Node) ProfileCleanupLeftover() error

func (*Node) ProfileConfig

func (n *Node) ProfileConfig(name string) (map[string]string, error)

Get the profile configuration map from the DB

func (*Node) ProfileContainersGet

func (n *Node) ProfileContainersGet(profile string) ([]string, error)

func (*Node) ProfileCreate

func (n *Node) ProfileCreate(profile string, description string, config map[string]string,
	devices types.Devices) (int64, error)

func (*Node) ProfileCreateDefault

func (n *Node) ProfileCreateDefault() error

func (*Node) ProfileDelete

func (n *Node) ProfileDelete(name string) error

func (*Node) ProfileGet

func (n *Node) ProfileGet(name string) (int64, *api.Profile, error)

func (*Node) ProfileUpdate

func (n *Node) ProfileUpdate(name string, newName string) error

func (*Node) Profiles

func (n *Node) Profiles() ([]string, error)

Profiles returns a string list of profiles.

func (*Node) StoragePoolConfigGet

func (n *Node) StoragePoolConfigGet(poolID int64) (map[string]string, error)

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

func (n *Node) StoragePoolGet(poolName string) (int64, *api.StoragePool, error)

Get a single storage pool.

func (*Node) StoragePoolGetID

func (n *Node) StoragePoolGetID(poolName string) (int64, error)

Get id of a single storage pool.

func (*Node) StoragePoolInsertZfsDriver

func (n *Node) StoragePoolInsertZfsDriver() error

func (*Node) StoragePoolUpdate

func (n *Node) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error

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

func (n *Node) StoragePoolVolumeDelete(volumeName string, volumeType int, poolID int64) error

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

func (n *Node) StoragePoolVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)

Get all storage volumes attached to a given storage pool.

func (*Node) StoragePoolVolumesGetNames

func (n *Node) StoragePoolVolumesGetNames(poolID int64) (int, error)

Get the names of all storage volumes attached to a given storage pool.

func (*Node) StoragePoolVolumesGetType

func (n *Node) StoragePoolVolumesGetType(volumeType int, poolID int64) ([]string, error)

Get all storage volumes attached to a given storage pool of a given volume type.

func (*Node) StoragePools

func (n *Node) StoragePools() ([]string, error)

Get all storage pools.

func (*Node) StoragePoolsGetDrivers

func (n *Node) StoragePoolsGetDrivers() ([]string, error)

Get the names of all storage volumes attached to a given storage pool.

func (*Node) StorageVolumeCleanupImages

func (n *Node) StorageVolumeCleanupImages() error

func (*Node) StorageVolumeConfigGet

func (n *Node) StorageVolumeConfigGet(volumeID int64) (map[string]string, error)

Get config of a storage volume.

func (*Node) StorageVolumeDescriptionGet

func (n *Node) StorageVolumeDescriptionGet(volumeID int64) (string, error)

Get the description of a storage volume.

func (*Node) StorageVolumeMoveToLVMThinPoolNameKey

func (n *Node) StorageVolumeMoveToLVMThinPoolNameKey() error

func (*Node) Transaction

func (n *Node) Transaction(f func(*NodeTx) error) error

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

func NewTestNodeTx(t *testing.T) (*NodeTx, func())

NewTestNodeTx returns a fresh NodeTx object, along with a function that can be called to cleanup state when done with it.

func (*NodeTx) Config

func (n *NodeTx) Config() (map[string]string, error)

Config fetches all LXD node-level config keys.

func (*NodeTx) UpdateConfig

func (n *NodeTx) UpdateConfig(values map[string]string) error

UpdateConfig updates the given LXD node-level configuration keys in the config table. Config keys set to empty values will be deleted.

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.

Jump to

Keyboard shortcuts

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