db

package
v0.0.0-...-3cb0048 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2017 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StoragePoolVolumeTypeContainer = iota
	StoragePoolVolumeTypeImage
	StoragePoolVolumeTypeCustom
)

XXX: this was extracted from apollo/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.

View Source
const CURRENT_SCHEMA string = `` /* 6495-byte string literal not displayed */

CURRENT_SCHEMA contains the current SQLite SQL Schema.

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: "apollo",
	1: "direct",
	2: "simplestreams",
}

Functions

func Begin

func Begin(db *sql.DB) (*sql.Tx, error)

func CertDelete

func CertDelete(db *sql.DB, fingerprint string) error

CertDelete deletes a certificate from the db.

func CertSave

func CertSave(db *sql.DB, cert *CertInfo) error

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

func CertUpdate

func CertUpdate(db *sql.DB, fingerprint string, certName string, certType int) error

func ConfigValueSet

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

func ConfigValuesGet

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

func ContainerConfig

func ContainerConfig(db *sql.DB, containerId int) (map[string]string, error)

ContainerConfig gets the container configuration map from the DB

func ContainerConfigClear

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

func ContainerConfigGet

func ContainerConfigGet(db *sql.DB, id int, key string) (string, error)

func ContainerConfigInsert

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

func ContainerConfigRemove

func ContainerConfigRemove(db *sql.DB, id int, name string) error

func ContainerCreate

func ContainerCreate(db *sql.DB, args ContainerArgs) (int, error)

func ContainerGetSnapshots

func ContainerGetSnapshots(db *sql.DB, name string) ([]string, error)

func ContainerId

func ContainerId(db *sql.DB, name string) (int, error)

func ContainerLastUsedUpdate

func ContainerLastUsedUpdate(db *sql.DB, id int, date time.Time) error

func ContainerName

func ContainerName(db *sql.DB, id int) (string, error)

func ContainerPool

func ContainerPool(db *sql.DB, containerName string) (string, error)

Get the storage pool of a given container.

func ContainerProfiles

func ContainerProfiles(db *sql.DB, containerId int) ([]string, error)

Get a list of profiles for a given container id.

func ContainerProfilesInsert

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

func ContainerRemove

func ContainerRemove(db *sql.DB, name string) error

func ContainerRename

func ContainerRename(db *sql.DB, oldName string, newName string) error

func ContainerSetState

func ContainerSetState(db *sql.DB, id int, state string) error

func ContainerSetStateful

func ContainerSetStateful(db *sql.DB, id int, stateful bool) error

func ContainerUpdate

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

func ContainersList

func ContainersList(db *sql.DB, cType ContainerType) ([]string, error)

func CreateDb

func CreateDb(db *sql.DB, patchNames []string) (err error)

Create the initial (current) schema for a given SQLite DB connection.

func Devices

func Devices(db *sql.DB, qName string, isprofile bool) (types.Devices, error)

func DevicesAdd

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

func Exec

func Exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error)

func GetLatestSchema

func GetLatestSchema() int

func GetSchema

func GetSchema(db *sql.DB) (v int)

func ImageAliasAdd

func ImageAliasAdd(db *sql.DB, name string, imageID int, desc string) error

Insert an alias ento the database.

func ImageAliasDelete

func ImageAliasDelete(db *sql.DB, name string) error

func ImageAliasGet

func ImageAliasGet(db *sql.DB, name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)

func ImageAliasRename

func ImageAliasRename(db *sql.DB, id int, name string) error

func ImageAliasUpdate

func ImageAliasUpdate(db *sql.DB, id int, imageID int, desc string) error

func ImageAliasesMove

func ImageAliasesMove(db *sql.DB, source int, destination int) error

func ImageDelete

func ImageDelete(db *sql.DB, id int) error

func ImageExists

func ImageExists(db *sql.DB, fingerprint string) (bool, error)

Whether an image with the given fingerprint exists.

func ImageGet

func ImageGet(db *sql.DB, 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 ImageGetPoolNamesFromIDs

func ImageGetPoolNamesFromIDs(db *sql.DB, poolIDs []int64) ([]string, error)

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

func ImageGetPools

func ImageGetPools(db *sql.DB, imageFingerprint string) ([]int64, error)

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

func ImageInsert

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

func ImageLastAccessInit

func ImageLastAccessInit(db *sql.DB, fingerprint string) error

func ImageLastAccessUpdate

func ImageLastAccessUpdate(db *sql.DB, fingerprint string, date time.Time) error

func ImageSourceGet

func ImageSourceGet(db *sql.DB, imageId int) (int, api.ImageSource, error)

func ImageSourceGetCachedFingerprint

func ImageSourceGetCachedFingerprint(db *sql.DB, 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 ImageSourceInsert

func ImageSourceInsert(db *sql.DB, imageId int, server string, protocol string, certificate string, alias string) error

func ImageUpdate

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

func ImagesGet

func ImagesGet(db *sql.DB, public bool) ([]string, error)

func ImagesGetExpired

func ImagesGetExpired(db *sql.DB, expiry int64) ([]string, 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 NetworkConfigGet

func NetworkConfigGet(db *sql.DB, id int64) (map[string]string, error)

func NetworkCreate

func NetworkCreate(db *sql.DB, name, description string, config map[string]string) (int64, error)

func NetworkDelete

func NetworkDelete(db *sql.DB, name string) error

func NetworkGet

func NetworkGet(db *sql.DB, name string) (int64, *api.Network, error)

func NetworkGetInterface

func NetworkGetInterface(db *sql.DB, devName string) (int64, *api.Network, error)

func NetworkRename

func NetworkRename(db *sql.DB, oldName string, newName string) error

func NetworkUpdate

func NetworkUpdate(db *sql.DB, name, description string, config map[string]string) error

func NetworkUpdateDescription

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

func Networks

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

func OpenDb

func OpenDb(path string) (*sql.DB, error)

OpenDb opens the database with the correct parameters for APOLLO.

func Patches

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

func PatchesMarkApplied

func PatchesMarkApplied(db *sql.DB, patch string) error

func ProfileConfig

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

Get the profile configuration map from the DB

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 ProfileContainersGet

func ProfileContainersGet(db *sql.DB, profile string) ([]string, error)

func ProfileCreate

func ProfileCreate(db *sql.DB, profile string, description string, config map[string]string,
	devices types.Devices) (int64, error)

func ProfileCreateDefault

func ProfileCreateDefault(db *sql.DB) error

func ProfileDelete

func ProfileDelete(db *sql.DB, name string) error

func ProfileDescriptionUpdate

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

func ProfileGet

func ProfileGet(db *sql.DB, name string) (int64, *api.Profile, error)

func ProfileUpdate

func ProfileUpdate(db *sql.DB, name string, newName string) error

func Profiles

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

Profiles returns a string list of profiles.

func QueryScan

func QueryScan(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 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 StoragePoolConfigGet

func StoragePoolConfigGet(db *sql.DB, poolID int64) (map[string]string, error)

Get config of a storage pool.

func StoragePoolCreate

func StoragePoolCreate(db *sql.DB, poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error)

Create new storage pool.

func StoragePoolDelete

func StoragePoolDelete(db *sql.DB, poolName string) (*api.StoragePool, error)

Delete storage pool.

func StoragePoolGet

func StoragePoolGet(db *sql.DB, poolName string) (int64, *api.StoragePool, error)

Get a single storage pool.

func StoragePoolGetID

func StoragePoolGetID(db *sql.DB, poolName string) (int64, error)

Get id of a single storage pool.

func StoragePoolUpdate

func StoragePoolUpdate(db *sql.DB, poolName, description string, poolConfig map[string]string) error

Update storage pool.

func StoragePoolUpdateDescription

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

Update the storage pool description.

func StoragePoolVolumeCreate

func StoragePoolVolumeCreate(db *sql.DB, volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string) (int64, error)

Create new storage volume attached to a given storage pool.

func StoragePoolVolumeDelete

func StoragePoolVolumeDelete(db *sql.DB, volumeName string, volumeType int, poolID int64) error

Delete storage volume attached to a given storage pool.

func StoragePoolVolumeGetType

func StoragePoolVolumeGetType(db *sql.DB, 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 StoragePoolVolumeGetTypeID

func StoragePoolVolumeGetTypeID(db *sql.DB, 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 StoragePoolVolumeRename

func StoragePoolVolumeRename(db *sql.DB, oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error

Rename storage volume attached to a given storage pool.

func StoragePoolVolumeTypeToName

func StoragePoolVolumeTypeToName(volumeType int) (string, error)

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

func StoragePoolVolumeUpdate

func StoragePoolVolumeUpdate(db *sql.DB, volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error

Update storage volume attached to a given storage pool.

func StoragePoolVolumesGet

func StoragePoolVolumesGet(db *sql.DB, poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)

Get all storage volumes attached to a given storage pool.

func StoragePoolVolumesGetNames

func StoragePoolVolumesGetNames(db *sql.DB, poolID int64) (int, error)

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

func StoragePoolVolumesGetType

func StoragePoolVolumesGetType(db *sql.DB, volumeType int, poolID int64) ([]string, error)

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

func StoragePools

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

Get all storage pools.

func StoragePoolsGetDrivers

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

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

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 StorageVolumeConfigGet

func StorageVolumeConfigGet(db *sql.DB, volumeID int64) (map[string]string, error)

Get config of a storage volume.

func StorageVolumeDescriptionGet

func StorageVolumeDescriptionGet(db *sql.DB, volumeID int64) (string, error)

Get the description of a storage volume.

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 UpdatesApplyAll

func UpdatesApplyAll(db *sql.DB, doBackup bool, postApply func(int) error) error

Apply all possible database patches. If "doBackup" is true, the sqlite file will be backed up before any update is applied. If "postApply" it's passed, it will be called after each database update gets successfully applied, and be passed the its version (as of now "postApply" is only used by the daemon as a mean to apply the legacy V10 and V15 non-db updates during the database upgrade sequence to, avoid changing semantics see PR #3322).

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

func CertGet

func CertGet(db *sql.DB, fingerprint string) (cert *CertInfo, err error)

CertGet 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 CertsGet

func CertsGet(db *sql.DB) (certs []*CertInfo, err error)

CertsGet returns all certificates from the DB as CertBaseInfo objects.

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.

func ContainerGet

func ContainerGet(db *sql.DB, name string) (ContainerArgs, error)

type ContainerType

type ContainerType int

ContainerType encodes the type of container (either regular or snapshot).

const (
	CTypeRegular  ContainerType = 0
	CTypeSnapshot ContainerType = 1
)

Jump to

Keyboard shortcuts

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