db

package
v0.0.0-...-c012b7a Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterMemberStateCreated = 0
	ClusterMemberStatePending = 1
)

Numeric type codes identifying different cluster member states.

View Source
const (
	RaftVoter   = client.Voter
	RaftStandBy = client.StandBy
	RaftSpare   = client.Spare
)

RaftNode roles.

View Source
const (
	StoragePoolVolumeTypeContainer = iota
	StoragePoolVolumeTypeImage
	StoragePoolVolumeTypeCustom
	StoragePoolVolumeTypeVM
)

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"
	StoragePoolVolumeTypeNameVM        string = "virtual-machine"
	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 (
	StoragePoolVolumeContentTypeFS = iota
	StoragePoolVolumeContentTypeBlock
)

Content types.

View Source
const (
	StoragePoolVolumeContentTypeNameFS    string = "filesystem"
	StoragePoolVolumeContentTypeNameBlock string = "block"
)

Content type names.

View Source
const CertificateTypeClient = 1

CertificateTypeClient indicates a client certificate type.

View Source
const CertificateTypeServer = 2

CertificateTypeServer indicates a server certificate type.

View Source
const ClusterRoleDatabase = ClusterRole("database")

ClusterRoleDatabase represents the database role in a cluster.

View Source
const ClusterRoleDatabaseStandBy = ClusterRole("database-standby")

ClusterRoleDatabaseStandBy represents the database stand-by role in a cluster.

View Source
const DefaultOfflineThreshold = 20

DefaultOfflineThreshold is the default value for the cluster.offline_threshold configuration key, expressed in seconds.

Variables

View Source
var (
	// ErrAlreadyDefined hapens when the given entry already exists,
	// for example a container.
	ErrAlreadyDefined = fmt.Errorf("The record already exists")

	// ErrNoSuchObject 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.
	ErrNoSuchObject = fmt.Errorf("No such object")

	// ErrNoClusterMember is used to indicate no cluster member has been found for a resource.
	ErrNoClusterMember = fmt.Errorf("No cluster member found")
)
View Source
var ClusterRoles = map[int]ClusterRole{}

ClusterRoles maps role ids into human-readable names.

Note: the database role is currently stored directly in the raft configuration which acts as single source of truth for it. This map should only contain LXD-specific cluster roles.

View Source
var ErrInstanceListStop = fmt.Errorf("search stopped")

ErrInstanceListStop used as return value from InstanceList's instanceFunc when prematurely stopping the search.

View Source
var ErrSomeNodesAreBehind = fmt.Errorf("some nodes are behind this node's version")

ErrSomeNodesAreBehind is returned by OpenCluster if some of the nodes in the cluster have a schema or API version that is less recent than this node.

View Source
var ErrUnknownEntityID = fmt.Errorf("Unknown entity ID")

ErrUnknownEntityID describes the unknown entity ID error

View Source
var ImageSourceProtocol = map[int]string{
	0: "lxd",
	1: "direct",
	2: "simplestreams",
}

ImageSourceProtocol maps image source protocol codes to human-readable names.

View Source
var NodeSpecificNetworkConfig = []string{
	"bridge.external_interfaces",
	"parent",
}

NodeSpecificNetworkConfig lists all network config keys which are node-specific.

View Source
var StoragePoolNodeConfigKeys = []string{
	"size",
	"source",
	"volatile.initial_source",
	"zfs.pool_name",
	"lvm.thinpool_name",
	"lvm.vg_name",
}

StoragePoolNodeConfigKeys lists all storage pool config keys which are node-specific.

View Source
var StoragePoolVolumeTypeNames = map[int]string{
	StoragePoolVolumeTypeContainer: "container",
	StoragePoolVolumeTypeImage:     "image",
	StoragePoolVolumeTypeCustom:    "custom",
	StoragePoolVolumeTypeVM:        "virtual-machine",
}

StoragePoolVolumeTypeNames represents a map of storage volume types and their names.

View Source
var StorageRemoteDriverNames func() []string

StorageRemoteDriverNames returns a list of remote storage driver names.

View Source
var WarningSeverities = map[WarningSeverity]string{
	WarningSeverityLow:      "low",
	WarningSeverityModerate: "moderate",
	WarningSeverityHigh:     "high",
}

WarningSeverities associates a severity code to its name.

View Source
var WarningSeverityTypes = map[string]WarningSeverity{}

WarningSeverityTypes associates a warning severity to its type code.

View Source
var WarningStatusTypes = map[string]WarningStatus{}

WarningStatusTypes associates a warning status to its type code.

View Source
var WarningStatuses = map[WarningStatus]string{
	WarningStatusNew:          "new",
	WarningStatusAcknowledged: "acknowledged",
	WarningStatusResolved:     "resolved",
}

WarningStatuses associates a warning code to its name.

View Source
var WarningTypeNames = map[WarningType]string{
	WarningUndefined:                              "Undefined warning",
	WarningMissingCGroupBlkio:                     "Couldn't find the CGroup blkio",
	WarningMissingCGroupBlkioWeight:               "Couldn't find the CGroup blkio.weight",
	WarningMissingCGroupCPUController:             "Couldn't find the CGroup CPU controller",
	WarningMissingCGroupCPUsetController:          "Couldn't find the CGroup CPUset controller",
	WarningMissingCGroupCPUacctController:         "Couldn't find the CGroup CPUacct controller",
	WarningMissingCGroupDevicesController:         "Couldn't find the CGroup devices controller",
	WarningMissingCGroupFreezerController:         "Couldn't find the CGroup freezer controller",
	WarningMissingCGroupHugetlbController:         "Couldn't find the CGroup hugetlb controller",
	WarningMissingCGroupMemoryController:          "Couldn't find the CGroup memory controller",
	WarningMissingCGroupNetworkPriorityController: "Couldn't find the CGroup network priority controller",
	WarningMissingCGroupPidsController:            "Couldn't find the CGroup pids controller",
	WarningMissingCGroupMemorySwapAccounting:      "Couldn't find the CGroup memory swap accounting",
	WarningClusterTimeSkew:                        "Time skew detected between leader and local",
	WarningAppArmorNotAvailable:                   "AppArmor support has been disabled",
	WarningMissingVirtiofsd:                       "Missing virtiofsd",
	WarningUnableToConnectToMAAS:                  "Unable to connect to MAAS",
	WarningAppArmorDisabledDueToRawDnsmasq:        "Skipping AppArmor for dnsmasq due to raw.dnsmasq being set",
	WarningLargerIPv6PrefixThanSupported:          "IPv6 networks with a prefix larger than 64 aren't properly supported by dnsmasq",
	WarningProxyBridgeNetfilterNotEnabled:         "Proxy bridge netfilter not enabled",
	WarningNetworkStartupFailure:                  "Failed to start network",
	WarningOfflineClusterMember:                   "Offline cluster member",
	WarningInstanceAutostartFailure:               "Failed to autostart instance",
}

WarningTypeNames associates a warning code to its name.

View Source
var WarningTypes = map[string]WarningType{}

WarningTypes associates a warning type to its type code.

Functions

func CertificateAPITypeToDBType

func CertificateAPITypeToDBType(apiType string) (int, error)

CertificateAPITypeToDBType converts an API type to the equivalent DB type.

func CreateInstanceConfig

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

CreateInstanceConfig inserts a new config for the instance with the given ID.

func ExpandInstanceConfig

func ExpandInstanceConfig(config map[string]string, profiles []api.Profile) map[string]string

ExpandInstanceConfig expands the given instance config with the config values of the given profiles.

func ExpandInstanceDevices

func ExpandInstanceDevices(devices deviceConfig.Devices, profiles []api.Profile) deviceConfig.Devices

ExpandInstanceDevices expands the given instance devices with the devices defined in the given profiles.

func NetworkStateToAPIStatus

func NetworkStateToAPIStatus(state NetworkState) string

NetworkStateToAPIStatus converts DB NetworkState to API status string.

func NewTestDqliteServer

func NewTestDqliteServer(t *testing.T) (string, driver.NodeStore, func())

NewTestDqliteServer creates a new test dqlite server.

Return the directory backing the test server and a newly created server store that can be used to connect to it.

func OpenNode

func OpenNode(dir string, fresh func(*Node) error, legacyPatches map[int]*LegacyPatch) (*Node, *Dump, 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).

Return the newly created Node object, and a Dump of the pre-clustering data if we've migrating to a cluster-aware version.

func ProfileToAPI

func ProfileToAPI(profile *Profile) *api.Profile

ProfileToAPI is a convenience to convert a Profile db struct into an API profile struct.

func StoragePoolStateToAPIStatus

func StoragePoolStateToAPIStatus(state StoragePoolState) string

StoragePoolStateToAPIStatus converts DB StoragePoolState to API status string.

func TxCommit

func TxCommit(tx *sql.Tx) error

TxCommit commits the given transaction.

func UpdateInstance

func UpdateInstance(tx *sql.Tx, id int, description string, architecture int, ephemeral bool,
	expiryDate time.Time) error

UpdateInstance updates the description, architecture and ephemeral flag of the instance with the given ID.

Types

type Certificate

type Certificate struct {
	ID          int
	Fingerprint string `db:"primary=yes&comparison=like"`
	Type        int
	Name        string
	Certificate string
	Restricted  bool
	Projects    []string
}

Certificate is here to pass the certificates content from the database around.

func (*Certificate) ToAPI

func (cert *Certificate) ToAPI() api.Certificate

ToAPI converts the database Certificate struct to an api.Certificate entry.

func (*Certificate) ToAPIType

func (cert *Certificate) ToAPIType() string

ToAPIType returns the API equivalent type.

type CertificateFilter

type CertificateFilter struct {
	Fingerprint string // Matched with LIKE
}

CertificateFilter can be used to filter results yielded by GetCertInfos

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster mediates access to LXD's data stored in the cluster dqlite database.

func ForLocalInspection

func ForLocalInspection(db *sql.DB) *Cluster

ForLocalInspection 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 ForLocalInspectionWithPreparedStmts

func ForLocalInspectionWithPreparedStmts(db *sql.DB) (*Cluster, error)

ForLocalInspectionWithPreparedStmts is the same as ForLocalInspection but it also prepares the statements used in auto-generated database code.

func NewTestCluster

func NewTestCluster(t *testing.T) (*Cluster, func())

NewTestCluster creates a new Cluster for testing purposes, along with a function that can be used to clean it up when done.

func OpenCluster

func OpenCluster(name string, store driver.NodeStore, address, dir string, timeout time.Duration, dump *Dump, options ...driver.Option) (*Cluster, error)

OpenCluster creates a new Cluster object for interacting with the dqlite database.

- name: Basename of the database file holding the data. Typically "db.bin". - dialer: Function used to connect to the dqlite backend via gRPC SQL. - address: Network address of this node (or empty string). - dir: Base LXD database directory (e.g. /var/lib/lxd/database) - timeout: Give up trying to open the database after this amount of time. - dump: If not nil, a copy of 2.0 db data, for migrating to 3.0.

The address and api parameters will be used to determine if the cluster database matches our version, and possibly trigger a schema update. If the schema update can't be performed right now, because some nodes are still behind, an Upgrading error is returned.

func (*Cluster) AddImageToLocalNode

func (c *Cluster) AddImageToLocalNode(project, fingerprint string) error

AddImageToLocalNode creates a new entry in the images_nodes table for tracking that the local node has the given image.

func (*Cluster) Begin

func (c *Cluster) Begin() (*sql.Tx, error)

Begin a new transaction against the cluster database.

FIXME: legacy method.

func (*Cluster) Close

func (c *Cluster) Close() error

Close the database facade.

func (*Cluster) CopyDefaultImageProfiles

func (c *Cluster) CopyDefaultImageProfiles(id int, newID int) error

CopyDefaultImageProfiles copies default profiles from id to new_id.

func (*Cluster) CreateCertificate

func (c *Cluster) CreateCertificate(cert Certificate) (int64, error)

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

func (*Cluster) CreateImage

func (c *Cluster) CreateImage(project, fp string, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string, typeName string) error

CreateImage creates a new image.

func (*Cluster) CreateImageAlias

func (c *Cluster) CreateImageAlias(project, name string, imageID int, desc string) error

CreateImageAlias inserts an alias ento the database.

func (*Cluster) CreateImageSource

func (c *Cluster) CreateImageSource(id int, server string, protocol string, certificate string, alias string) error

CreateImageSource inserts a new image source.

func (*Cluster) CreateInstanceBackup

func (c *Cluster) CreateInstanceBackup(args InstanceBackup) error

CreateInstanceBackup creates a new backup.

func (*Cluster) CreateNetwork

func (c *Cluster) CreateNetwork(projectName string, name string, description string, netType NetworkType, config map[string]string) (int64, error)

CreateNetwork creates a new network.

func (*Cluster) CreateNetworkACL

func (c *Cluster) CreateNetworkACL(projectName string, info *api.NetworkACLsPost) (int64, error)

CreateNetworkACL creates a new Network ACL.

func (*Cluster) CreateStoragePool

func (c *Cluster) CreateStoragePool(poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error)

CreateStoragePool creates new storage pool.

func (*Cluster) CreateStoragePoolVolume

func (c *Cluster) CreateStoragePoolVolume(project, volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, contentType int) (int64, error)

CreateStoragePoolVolume creates a new storage volume attached to a given storage pool.

func (*Cluster) CreateStoragePoolVolumeBackup

func (c *Cluster) CreateStoragePoolVolumeBackup(args StoragePoolVolumeBackup) error

CreateStoragePoolVolumeBackup creates a new storage volume backup.

func (*Cluster) CreateStorageVolumeSnapshot

func (c *Cluster) CreateStorageVolumeSnapshot(project, volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, expiryDate time.Time) (int64, error)

CreateStorageVolumeSnapshot creates a new storage volume snapshot attached to a given storage pool.

func (*Cluster) DB

func (c *Cluster) DB() *sql.DB

DB returns the low level database handle to the cluster database.

FIXME: this is used for compatibility with some legacy code, and should be

dropped once there are no call sites left.

func (*Cluster) DeleteCertificate

func (c *Cluster) DeleteCertificate(fingerprint string) error

DeleteCertificate deletes a certificate from the db.

func (*Cluster) DeleteImage

func (c *Cluster) DeleteImage(id int) error

DeleteImage deletes the image with the given ID.

func (*Cluster) DeleteImageAlias

func (c *Cluster) DeleteImageAlias(project, name string) error

DeleteImageAlias deletes the alias with the given name.

func (*Cluster) DeleteInstance

func (c *Cluster) DeleteInstance(project, name string) error

DeleteInstance removes the instance with the given name from the database.

func (*Cluster) DeleteInstanceBackup

func (c *Cluster) DeleteInstanceBackup(name string) error

DeleteInstanceBackup removes the instance backup with the given name from the database.

func (*Cluster) DeleteInstanceConfigKey

func (c *Cluster) DeleteInstanceConfigKey(id int, key string) error

DeleteInstanceConfigKey removes the given key from the config of the instance with the given ID.

func (*Cluster) DeleteNetwork

func (c *Cluster) DeleteNetwork(project string, name string) error

DeleteNetwork deletes the network with the given name.

func (*Cluster) DeleteNetworkACL

func (c *Cluster) DeleteNetworkACL(id int64) error

DeleteNetworkACL deletes the Network ACL.

func (*Cluster) DeleteStoragePoolVolumeBackup

func (c *Cluster) DeleteStoragePoolVolumeBackup(name string) error

DeleteStoragePoolVolumeBackup removes the storage volume backup with the given name from the database.

func (*Cluster) EnterExclusive

func (c *Cluster) EnterExclusive() error

EnterExclusive acquires a lock on the cluster db, so any successive call to Transaction will block until ExitExclusive has been called.

func (*Cluster) ExitExclusive

func (c *Cluster) ExitExclusive(f func(*ClusterTx) error) error

ExitExclusive runs the given transaction and then releases the lock acquired with EnterExclusive.

func (*Cluster) FillMissingStoragePoolDriver

func (c *Cluster) FillMissingStoragePoolDriver() error

FillMissingStoragePoolDriver fills the driver of all storage pools without a driver, setting it to 'zfs'.

func (*Cluster) GetCachedImageSourceFingerprint

func (c *Cluster) GetCachedImageSourceFingerprint(server string, protocol string, alias string, typeName string, architecture int) (string, error)

GetCachedImageSourceFingerprint tries 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 (*Cluster) GetCertificate

func (c *Cluster) GetCertificate(fingerprint string) (*Certificate, error)

GetCertificate 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 certificate with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.

func (*Cluster) GetCreatedNetworks

func (c *Cluster) GetCreatedNetworks(project string) ([]string, error)

GetCreatedNetworks returns the names of all networks that are in state networkCreated.

func (*Cluster) GetCreatedStoragePoolNames

func (c *Cluster) GetCreatedStoragePoolNames() ([]string, error)

GetCreatedStoragePoolNames returns the names of all storage pools that are created.

func (*Cluster) GetExpiredImagesInProject

func (c *Cluster) GetExpiredImagesInProject(expiry int64, project string) ([]string, error)

GetExpiredImagesInProject returns the names of all images that have expired since the given time.

func (*Cluster) GetExpiredInstanceBackups

func (c *Cluster) GetExpiredInstanceBackups() ([]InstanceBackup, error)

GetExpiredInstanceBackups returns a list of expired instance backups.

func (*Cluster) GetExpiredStorageVolumeSnapshots

func (c *Cluster) GetExpiredStorageVolumeSnapshots() ([]StorageVolumeArgs, error)

GetExpiredStorageVolumeSnapshots returns a list of expired volume snapshots.

func (*Cluster) GetImage

func (c *Cluster) GetImage(project, fingerprint string, public bool) (int, *api.Image, error)

GetImage gets an Image object from the database.

The fingerprint argument will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. However in case the shortform matches more than one image, an error will be returned.

func (*Cluster) GetImageAlias

func (c *Cluster) GetImageAlias(project, name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)

GetImageAlias returns the alias with the given name in the given project.

func (*Cluster) GetImageAliases

func (c *Cluster) GetImageAliases(project string) ([]string, error)

GetImageAliases returns the names of the aliases of all images.

func (*Cluster) GetImageFromAnyProject

func (c *Cluster) GetImageFromAnyProject(fingerprint string) (int, *api.Image, error)

GetImageFromAnyProject returns an image matching the given fingerprint, if it exists in any project.

func (*Cluster) GetImages

func (c *Cluster) GetImages() (map[string][]string, error)

GetImages returns all images.

func (*Cluster) GetImagesFingerprints

func (c *Cluster) GetImagesFingerprints(project string, public bool) ([]string, error)

GetImagesFingerprints returns the names of all images (optionally only the public ones).

func (*Cluster) GetImagesOnLocalNode

func (c *Cluster) GetImagesOnLocalNode() (map[string][]string, error)

GetImagesOnLocalNode returns all images that the local LXD node has.

func (*Cluster) GetImagesOnNode

func (c *Cluster) GetImagesOnNode(id int64) (map[string][]string, error)

GetImagesOnNode returns all images that the node with the given id has.

func (*Cluster) GetInstanceBackup

func (c *Cluster) GetInstanceBackup(projectName string, name string) (InstanceBackup, error)

GetInstanceBackup returns the backup with the given name.

func (*Cluster) GetInstanceBackupWithID

func (c *Cluster) GetInstanceBackupWithID(backupID int) (InstanceBackup, error)

GetInstanceBackupWithID returns the backup with the given ID.

func (*Cluster) GetInstanceBackups

func (c *Cluster) GetInstanceBackups(projectName string, name string) ([]string, error)

GetInstanceBackups returns the names of all backups of the instance with the given name.

func (*Cluster) GetInstanceConfig

func (c *Cluster) GetInstanceConfig(id int, key string) (string, error)

GetInstanceConfig returns the value of the given key in the configuration of the instance with the given ID.

func (*Cluster) GetInstanceID

func (c *Cluster) GetInstanceID(project, name string) (int, error)

GetInstanceID returns the ID of the instance with the given name.

func (*Cluster) GetInstancePool

func (c *Cluster) GetInstancePool(project, instanceName string) (string, error)

GetInstancePool returns the storage pool of a given instance.

This is a non-transactional variant of ClusterTx.GetInstancePool().

func (*Cluster) GetInstanceProjectAndName

func (c *Cluster) GetInstanceProjectAndName(id int) (string, string, error)

GetInstanceProjectAndName returns the project and the name of the instance with the given ID.

func (*Cluster) GetInstanceSnapshotID

func (c *Cluster) GetInstanceSnapshotID(project, instance, name string) (int, error)

GetInstanceSnapshotID returns the ID of the snapshot with the given name.

func (*Cluster) GetInstanceSnapshotsNames

func (c *Cluster) GetInstanceSnapshotsNames(project, name string) ([]string, error)

GetInstanceSnapshotsNames returns the names of all snapshots of the instance in the given project with the given name.

func (*Cluster) GetInstancesWithProfile

func (c *Cluster) GetInstancesWithProfile(project, profile string) (map[string][]string, error)

GetInstancesWithProfile gets the names of the instance associated with the profile with the given name in the given project.

func (*Cluster) GetLocalStoragePoolVolume

func (c *Cluster) GetLocalStoragePoolVolume(project, volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error)

GetLocalStoragePoolVolume gets a single storage volume attached to a given storage pool of a given type, on the current node in the given project.

func (*Cluster) GetLocalStoragePoolVolumeSnapshotsWithType

func (c *Cluster) GetLocalStoragePoolVolumeSnapshotsWithType(projectName string, volumeName string, volumeType int, poolID int64) ([]StorageVolumeArgs, error)

GetLocalStoragePoolVolumeSnapshotsWithType get all snapshots of a storage volume attached to a given storage pool of a given volume type, on the local node. Returns snapshots slice ordered by when they were created, oldest first.

func (*Cluster) GetLocalStoragePoolVolumes

func (c *Cluster) GetLocalStoragePoolVolumes(project string, poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)

GetLocalStoragePoolVolumes returns all storage volumes attached to a given storage pool on the current node. If there are no volumes, it returns an empty list as well as ErrNoSuchObject.

func (*Cluster) GetLocalStoragePoolVolumesWithType

func (c *Cluster) GetLocalStoragePoolVolumesWithType(projectName string, volumeType int, poolID int64) ([]string, error)

GetLocalStoragePoolVolumesWithType returns all storage volumes attached to a given storage pool of a given volume type, on the current node.

func (*Cluster) GetNetworkACL

func (c *Cluster) GetNetworkACL(projectName string, name string) (int64, *api.NetworkACL, error)

GetNetworkACL returns the Network ACL with the given name in the given project.

func (*Cluster) GetNetworkACLIDsByNames

func (c *Cluster) GetNetworkACLIDsByNames(project string) (map[string]int64, error)

GetNetworkACLIDsByNames returns a map of names to IDs of existing Network ACLs.

func (*Cluster) GetNetworkACLNameAndProjectWithID

func (c *Cluster) GetNetworkACLNameAndProjectWithID(networkACLID int) (string, string, error)

GetNetworkACLNameAndProjectWithID returns the network ACL name and project name for the given ID.

func (*Cluster) GetNetworkACLs

func (c *Cluster) GetNetworkACLs(project string) ([]string, error)

GetNetworkACLs returns the names of existing Network ACLs.

func (*Cluster) GetNetworkInAnyState

func (c *Cluster) GetNetworkInAnyState(project string, name string) (int64, *api.Network, map[int64]NetworkNode, error)

GetNetworkInAnyState returns the network with the given name. The network can be in any state.

func (*Cluster) GetNetworkNameAndProjectWithID

func (c *Cluster) GetNetworkNameAndProjectWithID(networkID int) (string, string, error)

GetNetworkNameAndProjectWithID returns the network name and project name for the given ID.

func (*Cluster) GetNetworkWithInterface

func (c *Cluster) GetNetworkWithInterface(devName string) (int64, *api.Network, error)

GetNetworkWithInterface returns the network associated with the interface with the given name.

func (*Cluster) GetNetworks

func (c *Cluster) GetNetworks(project string) ([]string, error)

GetNetworks returns the names of existing networks.

func (*Cluster) GetNextInstanceSnapshotIndex

func (c *Cluster) GetNextInstanceSnapshotIndex(project string, name string, pattern string) int

GetNextInstanceSnapshotIndex returns the index that the next snapshot of the instance with the given name and pattern should have.

func (*Cluster) GetNextStorageVolumeSnapshotIndex

func (c *Cluster) GetNextStorageVolumeSnapshotIndex(pool, name string, typ int, pattern string) int

GetNextStorageVolumeSnapshotIndex returns the index of the next snapshot of the storage volume with the given name should have.

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 (*Cluster) GetNodeID

func (c *Cluster) GetNodeID() int64

GetNodeID returns the current nodeID (0 if not set)

func (*Cluster) GetNodesWithImage

func (c *Cluster) GetNodesWithImage(fingerprint string) ([]string, error)

GetNodesWithImage returns the addresses of online nodes which already have the image.

func (*Cluster) GetNodesWithImageAndAutoUpdate

func (c *Cluster) GetNodesWithImageAndAutoUpdate(fingerprint string, autoUpdate bool) ([]string, error)

GetNodesWithImageAndAutoUpdate returns the addresses of online nodes which already have the image.

func (*Cluster) GetNodesWithoutImage

func (c *Cluster) GetNodesWithoutImage(fingerprint string) ([]string, error)

GetNodesWithoutImage returns the addresses of online nodes which don't have the image.

func (*Cluster) GetPoolNamesFromIDs

func (c *Cluster) GetPoolNamesFromIDs(poolIDs []int64) ([]string, error)

GetPoolNamesFromIDs get the names of the storage pools with the given IDs.

func (*Cluster) GetPoolsWithImage

func (c *Cluster) GetPoolsWithImage(imageFingerprint string) ([]int64, error)

GetPoolsWithImage get the IDs of all storage pools on which a given image exists.

func (*Cluster) GetProfile

func (c *Cluster) GetProfile(project, name string) (int64, *api.Profile, error)

GetProfile returns the profile with the given name.

func (*Cluster) GetProfileNames

func (c *Cluster) GetProfileNames(project string) ([]string, error)

GetProfileNames returns the names of all profiles in the given project.

func (*Cluster) GetProfiles

func (c *Cluster) GetProfiles(projectName string, profileNames []string) ([]api.Profile, error)

GetProfiles returns the profiles with the given names in the given project.

func (*Cluster) GetProject

func (c *Cluster) GetProject(projectName string) (*api.Project, error)

GetProject returns the project with the given key.

func (*Cluster) GetStoragePool

func (c *Cluster) GetStoragePool(poolName string) (int64, *api.StoragePool, map[int64]StoragePoolNode, error)

GetStoragePool returns a single storage pool.

The pool must be in the created stated, not pending.

func (*Cluster) GetStoragePoolDrivers

func (c *Cluster) GetStoragePoolDrivers() ([]string, error)

GetStoragePoolDrivers returns the names of all storage drivers currently being used by at least one storage pool.

func (*Cluster) GetStoragePoolID

func (c *Cluster) GetStoragePoolID(poolName string) (int64, error)

GetStoragePoolID returns the id of a single storage pool.

func (*Cluster) GetStoragePoolInAnyState

func (c *Cluster) GetStoragePoolInAnyState(name string) (int64, *api.StoragePool, map[int64]StoragePoolNode, error)

GetStoragePoolInAnyState returns the storage pool with the given name.

The pool can be in any state.

func (*Cluster) GetStoragePoolNames

func (c *Cluster) GetStoragePoolNames() ([]string, error)

GetStoragePoolNames returns the names of all storage pools.

func (*Cluster) GetStoragePoolNodeVolumeID

func (c *Cluster) GetStoragePoolNodeVolumeID(projectName string, volumeName string, volumeType int, poolID int64) (int64, error)

GetStoragePoolNodeVolumeID gets the ID of a storage volume on a given storage pool of a given storage volume type and project, on the current node.

func (*Cluster) GetStoragePoolVolumeBackup

func (c *Cluster) GetStoragePoolVolumeBackup(projectName string, poolName string, backupName string) (StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackup returns the volume backup with the given name.

func (*Cluster) GetStoragePoolVolumeBackupWithID

func (c *Cluster) GetStoragePoolVolumeBackupWithID(backupID int) (StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackupWithID returns the volume backup with the given ID.

func (*Cluster) GetStoragePoolVolumeBackups

func (c *Cluster) GetStoragePoolVolumeBackups(projectName string, volumeName string, poolID int64) ([]StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackups returns a list of volume backups.

func (*Cluster) GetStoragePoolVolumeBackupsNames

func (c *Cluster) GetStoragePoolVolumeBackupsNames(projectName string, volumeName string, poolID int64) ([]string, error)

GetStoragePoolVolumeBackupsNames returns the names of all backups of the storage volume with the given name.

func (*Cluster) GetStoragePoolVolumeWithID

func (c *Cluster) GetStoragePoolVolumeWithID(volumeID int) (StorageVolumeArgs, error)

GetStoragePoolVolumeWithID returns the volume with the given ID.

func (*Cluster) GetStoragePoolVolumes

func (c *Cluster) GetStoragePoolVolumes(project string, poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)

GetStoragePoolVolumes returns all storage volumes attached to a given storage pool on any node. If there are no volumes, it returns an empty list and no error.

func (*Cluster) GetStoragePoolVolumesNames

func (c *Cluster) GetStoragePoolVolumesNames(poolID int64) ([]string, error)

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

func (*Cluster) GetStoragePoolVolumesWithType

func (c *Cluster) GetStoragePoolVolumesWithType(volumeType int) ([]StorageVolumeArgs, error)

GetStoragePoolVolumesWithType return a list of all volumes of the given type.

func (*Cluster) GetStoragePoolWithID

func (c *Cluster) GetStoragePoolWithID(poolID int) (int64, *api.StoragePool, map[int64]StoragePoolNode, error)

GetStoragePoolWithID returns the storage pool with the given ID.

func (*Cluster) GetStorageVolumeDescription

func (c *Cluster) GetStorageVolumeDescription(volumeID int64) (string, error)

GetStorageVolumeDescription gets the description of a storage volume.

func (*Cluster) GetStorageVolumeSnapshotExpiry

func (c *Cluster) GetStorageVolumeSnapshotExpiry(volumeID int64) (time.Time, error)

GetStorageVolumeSnapshotExpiry gets the expiry date of a storage volume snapshot.

func (*Cluster) GetStorageVolumeSnapshotWithID

func (c *Cluster) GetStorageVolumeSnapshotWithID(snapshotID int) (StorageVolumeArgs, error)

GetStorageVolumeSnapshotWithID returns the volume snapshot with the given ID.

func (*Cluster) GetStorageVolumeSnapshotsNames

func (c *Cluster) GetStorageVolumeSnapshotsNames(volumeID int64) ([]string, error)

GetStorageVolumeSnapshotsNames gets the snapshot names of a storage volume.

func (*Cluster) GetURIFromEntity

func (c *Cluster) GetURIFromEntity(entityType int, entityID int) (string, error)

GetURIFromEntity returns the URI for the given entity type and entity ID.

func (*Cluster) ImageExists

func (c *Cluster) ImageExists(project string, fingerprint string) (bool, error)

ImageExists returns whether an image with the given fingerprint exists.

func (*Cluster) ImageIsReferencedByOtherProjects

func (c *Cluster) ImageIsReferencedByOtherProjects(project string, fingerprint string) (bool, error)

ImageIsReferencedByOtherProjects returns true if the image with the given fingerprint is referenced by projects other than the given one.

func (*Cluster) InitImageLastUseDate

func (c *Cluster) InitImageLastUseDate(fingerprint string) error

InitImageLastUseDate inits the last_use_date field of the image with the given fingerprint.

func (*Cluster) InstanceList

func (c *Cluster) InstanceList(filter *InstanceFilter, instanceFunc func(inst Instance, project api.Project, profiles []api.Profile) error) error

InstanceList loads all instances across all projects and for each instance runs the instanceFunc passing in the instance and it's project and profiles. Accepts optional filter argument to specify a subset of instances.

func (*Cluster) IsRemoteStorage

func (c *Cluster) IsRemoteStorage(poolID int64) (bool, error)

IsRemoteStorage return whether a given pool is backed by remote storage.

func (*Cluster) Kill

func (c *Cluster) Kill()

Kill should be called upon shutdown, it will prevent retrying failed database queries.

func (*Cluster) LegacyContainersList

func (c *Cluster) LegacyContainersList() ([]string, error)

LegacyContainersList returns the names of all the containers.

NOTE: this is a pre-projects legacy API that is used only by patches. Don't use it for new code.

func (*Cluster) LegacySnapshotsList

func (c *Cluster) LegacySnapshotsList() ([]string, error)

LegacySnapshotsList returns the names of all the snapshots.

NOTE: this is a pre-projects legacy API that is used only by patches. Don't use it for new code.

func (*Cluster) LocateImage

func (c *Cluster) LocateImage(fingerprint string) (string, error)

LocateImage returns the address of an online node that has a local copy of the given image, or an empty string if the image is already available on this node.

If the image is not available on any online node, an error is returned.

func (*Cluster) MoveImageAlias

func (c *Cluster) MoveImageAlias(source int, destination int) error

MoveImageAlias changes the image ID associated with an alias.

func (*Cluster) NetworkNodes

func (c *Cluster) NetworkNodes(networkID int64) (map[int64]NetworkNode, error)

NetworkNodes returns the nodes keyed by node ID that the given network is defined on.

func (*Cluster) NodeID

func (c *Cluster) NodeID(id int64)

NodeID sets the the node NodeID associated with this cluster instance. It's used for backward-compatibility of all db-related APIs that were written before clustering and don't accept a node NodeID, so in those cases we automatically use this value as implicit node NodeID.

func (*Cluster) RemoveStoragePool

func (c *Cluster) RemoveStoragePool(poolName string) (*api.StoragePool, error)

RemoveStoragePool deletes storage pool.

func (*Cluster) RemoveStoragePoolVolume

func (c *Cluster) RemoveStoragePoolVolume(project, volumeName string, volumeType int, poolID int64) error

RemoveStoragePoolVolume deletes the storage volume attached to a given storage pool.

func (*Cluster) RemoveStorageVolumeImages

func (c *Cluster) RemoveStorageVolumeImages(fingerprints []string) error

RemoveStorageVolumeImages removes the volumes associated with the images with the given fingerprints.

func (*Cluster) RemoveUnreferencedProfiles

func (c *Cluster) RemoveUnreferencedProfiles() error

RemoveUnreferencedProfiles removes unreferenced profiles.

func (*Cluster) RenameImageAlias

func (c *Cluster) RenameImageAlias(id int, name string) error

RenameImageAlias renames the alias with the given ID.

func (*Cluster) RenameInstanceBackup

func (c *Cluster) RenameInstanceBackup(oldName, newName string) error

RenameInstanceBackup renames an instance backup from the given current name to the new one.

func (*Cluster) RenameNetwork

func (c *Cluster) RenameNetwork(project string, oldName string, newName string) error

RenameNetwork renames a network.

func (*Cluster) RenameNetworkACL

func (c *Cluster) RenameNetworkACL(id int64, newName string) error

RenameNetworkACL renames a Network ACL.

func (*Cluster) RenameStoragePoolVolume

func (c *Cluster) RenameStoragePoolVolume(project, oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error

RenameStoragePoolVolume renames the storage volume attached to a given storage pool.

func (*Cluster) RenameVolumeBackup

func (c *Cluster) RenameVolumeBackup(oldName, newName string) error

RenameVolumeBackup renames a volume backup from the given current name to the new one.

func (*Cluster) ResetInstancesPowerState

func (c *Cluster) ResetInstancesPowerState() error

ResetInstancesPowerState resets the power state of all instances.

func (*Cluster) Transaction

func (c *Cluster) Transaction(f func(*ClusterTx) error) error

Transaction creates a new ClusterTx object and transactionally executes the cluster database interactions invoked by the given function. If the function returns no error, all database changes are committed to the cluster database database, otherwise they are rolled back.

If EnterExclusive has been called before, calling Transaction will block until ExitExclusive has been called as well to release the lock.

func (*Cluster) UpdateCertificate

func (c *Cluster) UpdateCertificate(fingerprint string, cert Certificate) error

UpdateCertificate updates a certificate in the db.

func (*Cluster) UpdateCertificateProjects

func (c *Cluster) UpdateCertificateProjects(id int, projects []string) error

UpdateCertificateProjects updates the list of projects on a certificate.

func (*Cluster) UpdateImage

func (c *Cluster) UpdateImage(id int, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string, project string, profileIds []int64) error

UpdateImage updates the image with the given ID.

func (*Cluster) UpdateImageAlias

func (c *Cluster) UpdateImageAlias(id int, imageID int, desc string) error

UpdateImageAlias updates the alias with the given ID.

func (*Cluster) UpdateImageLastUseDate

func (c *Cluster) UpdateImageLastUseDate(fingerprint string, date time.Time) error

UpdateImageLastUseDate updates the last_use_date field of the image with the given fingerprint.

func (*Cluster) UpdateImageUploadDate

func (c *Cluster) UpdateImageUploadDate(id int, uploadedAt time.Time) error

UpdateImageUploadDate updates the upload_date column and an image row.

func (*Cluster) UpdateInstancePowerState

func (c *Cluster) UpdateInstancePowerState(id int, state string) error

UpdateInstancePowerState sets the the power state of the instance with the given ID.

func (*Cluster) UpdateInstanceSnapshotCreationDate

func (c *Cluster) UpdateInstanceSnapshotCreationDate(instanceID int, date time.Time) error

UpdateInstanceSnapshotCreationDate updates the creation_date field of the instance snapshot with ID.

func (*Cluster) UpdateInstanceStatefulFlag

func (c *Cluster) UpdateInstanceStatefulFlag(id int, stateful bool) error

UpdateInstanceStatefulFlag toggles the stateful flag of the instance with the given ID.

func (*Cluster) UpdateNetwork

func (c *Cluster) UpdateNetwork(project string, name, description string, config map[string]string) error

UpdateNetwork updates the network with the given name.

func (*Cluster) UpdateNetworkACL

func (c *Cluster) UpdateNetworkACL(id int64, config *api.NetworkACLPut) error

UpdateNetworkACL updates the Network ACL with the given ID.

func (*Cluster) UpdateStoragePool

func (c *Cluster) UpdateStoragePool(poolName, description string, poolConfig map[string]string) error

UpdateStoragePool updates a storage pool.

func (*Cluster) UpdateStoragePoolVolume

func (c *Cluster) UpdateStoragePoolVolume(project, volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error

UpdateStoragePoolVolume updates the storage volume attached to a given storage pool.

func (*Cluster) UpdateStorageVolumeSnapshot

func (c *Cluster) UpdateStorageVolumeSnapshot(project, volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string, expiryDate time.Time) error

UpdateStorageVolumeSnapshot updates the storage volume snapshot attached to a given storage pool.

func (*Cluster) UpgradeStorageVolumConfigToLVMThinPoolNameKey

func (c *Cluster) UpgradeStorageVolumConfigToLVMThinPoolNameKey() error

UpgradeStorageVolumConfigToLVMThinPoolNameKey upgrades the config keys of LVM volumes.

func (*Cluster) UpsertWarning

func (c *Cluster) UpsertWarning(nodeName string, projectName string, entityTypeCode int, entityID int, typeCode WarningType, message string) error

UpsertWarning creates or updates a warning.

func (*Cluster) UpsertWarningLocalNode

func (c *Cluster) UpsertWarningLocalNode(projectName string, entityTypeCode int, entityID int, typeCode WarningType, message string) error

UpsertWarningLocalNode creates or updates a warning for the local node. Returns error if no local node name.

type ClusterRole

type ClusterRole string

ClusterRole represents the role of a member in a cluster.

type ClusterTx

type ClusterTx struct {
	// contains filtered or unexported fields
}

ClusterTx models a single interaction with a LXD cluster database.

It wraps low-level sql.Tx objects and offers a high-level API to fetch and update data.

func NewTestClusterTx

func NewTestClusterTx(t *testing.T) (*ClusterTx, func())

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

func (*ClusterTx) CertificateExists

func (c *ClusterTx) CertificateExists(fingerprint string) (bool, error)

CertificateExists checks if a certificate with the given key exists.

func (*ClusterTx) CertificateProjectsRef

func (c *ClusterTx) CertificateProjectsRef(filter CertificateFilter) (map[string][]string, error)

CertificateProjectsRef returns entities used by certificates.

func (*ClusterTx) ClearNode

func (c *ClusterTx) ClearNode(id int64) error

ClearNode removes any instance or image associated with this node.

func (*ClusterTx) Config

func (c *ClusterTx) Config() (map[string]string, error)

Config fetches all LXD cluster config keys.

func (*ClusterTx) CreateCertificate

func (c *ClusterTx) CreateCertificate(object Certificate) (int64, error)

CreateCertificate adds a new certificate to the database.

func (*ClusterTx) CreateInstance

func (c *ClusterTx) CreateInstance(object Instance) (int64, error)

CreateInstance adds a new instance to the database.

func (*ClusterTx) CreateInstanceConfig

func (c *ClusterTx) CreateInstanceConfig(id int, config map[string]string) error

CreateInstanceConfig inserts a new config for the container with the given ID.

func (*ClusterTx) CreateInstanceSnapshot

func (c *ClusterTx) CreateInstanceSnapshot(object InstanceSnapshot) (int64, error)

CreateInstanceSnapshot adds a new instance_snapshot to the database.

func (*ClusterTx) CreateNetworkConfig

func (c *ClusterTx) CreateNetworkConfig(networkID, nodeID int64, config map[string]string) error

CreateNetworkConfig adds a new entry in the networks_config table

func (*ClusterTx) CreateNode

func (c *ClusterTx) CreateNode(name string, address string) (int64, error)

CreateNode adds a node to the current list of LXD nodes that are part of the cluster. The node's architecture will be the architecture of the machine the method is being run on. It returns the ID of the newly inserted row.

func (*ClusterTx) CreateNodeRole

func (c *ClusterTx) CreateNodeRole(id int64, role ClusterRole) error

CreateNodeRole adds a role to the node.

func (*ClusterTx) CreateNodeWithArch

func (c *ClusterTx) CreateNodeWithArch(name string, address string, arch int) (int64, error)

CreateNodeWithArch is the same as NodeAdd, but lets setting the node architecture explicitly.

func (*ClusterTx) CreateOperation

func (c *ClusterTx) CreateOperation(project, uuid string, typ OperationType) (int64, error)

CreateOperation adds a new operations to the table.

func (*ClusterTx) CreatePendingNetwork

func (c *ClusterTx) CreatePendingNetwork(node string, projectName string, name string, netType NetworkType, conf map[string]string) error

CreatePendingNetwork creates a new pending network on the node with the given name.

func (*ClusterTx) CreatePendingStoragePool

func (c *ClusterTx) CreatePendingStoragePool(node, name, driver string, conf map[string]string) error

CreatePendingStoragePool creates a new pending storage pool on the node with the given name.

func (*ClusterTx) CreateProfile

func (c *ClusterTx) CreateProfile(object Profile) (int64, error)

CreateProfile adds a new profile to the database.

func (*ClusterTx) CreateProject

func (c *ClusterTx) CreateProject(object api.ProjectsPost) (int64, error)

CreateProject adds a new project to the database.

func (*ClusterTx) CreateStoragePoolConfig

func (c *ClusterTx) CreateStoragePoolConfig(poolID, nodeID int64, config map[string]string) error

CreateStoragePoolConfig adds a new entry in the storage_pools_config table

func (*ClusterTx) DeleteCertificate

func (c *ClusterTx) DeleteCertificate(fingerprint string) error

DeleteCertificate deletes the certificate matching the given key parameters.

func (*ClusterTx) DeleteCertificateByNameAndType

func (c *ClusterTx) DeleteCertificateByNameAndType(name string, certType int) error

DeleteCertificateByNameAndType deletes the certificate(s) matching the given name and certificate type.

func (*ClusterTx) DeleteInstance

func (c *ClusterTx) DeleteInstance(project string, name string) error

DeleteInstance deletes the instance matching the given key parameters.

func (*ClusterTx) DeleteInstanceConfigKey

func (c *ClusterTx) DeleteInstanceConfigKey(id int64, key string) error

DeleteInstanceConfigKey removes the given key from the config of the instance with the given ID.

func (*ClusterTx) DeleteInstanceSnapshot

func (c *ClusterTx) DeleteInstanceSnapshot(project string, instance string, name string) error

DeleteInstanceSnapshot deletes the instance_snapshot matching the given key parameters.

func (*ClusterTx) DeleteProfile

func (c *ClusterTx) DeleteProfile(project string, name string) error

DeleteProfile deletes the profile matching the given key parameters.

func (*ClusterTx) DeleteProject

func (c *ClusterTx) DeleteProject(name string) error

DeleteProject deletes the project matching the given key parameters.

func (*ClusterTx) DeleteWarning

func (c *ClusterTx) DeleteWarning(UUID string) error

DeleteWarning deletes the warning matching the given key parameters.

func (*ClusterTx) DeleteWarningsByStatus

func (c *ClusterTx) DeleteWarningsByStatus(status WarningStatus) error

DeleteWarningsByStatus deletes all warnings with the given status.

func (*ClusterTx) GetCertificate

func (c *ClusterTx) GetCertificate(fingerprint string) (*Certificate, error)

GetCertificate returns the certificate with the given key.

func (*ClusterTx) GetCertificateID

func (c *ClusterTx) GetCertificateID(fingerprint string) (int64, error)

GetCertificateID return the ID of the certificate with the given key.

func (*ClusterTx) GetCertificates

func (c *ClusterTx) GetCertificates(filter CertificateFilter) ([]Certificate, error)

GetCertificates returns all available certificates.

func (*ClusterTx) GetCreatedNetworks

func (c *ClusterTx) GetCreatedNetworks() (map[string]map[int64]api.Network, error)

GetCreatedNetworks returns a map of api.Network associated to project and network ID. Only networks that have are in state networkCreated are returned.

func (*ClusterTx) GetCustomVolumesInProject

func (c *ClusterTx) GetCustomVolumesInProject(project string) ([]StorageVolumeArgs, error)

GetCustomVolumesInProject returns all custom volumes in the given project.

func (*ClusterTx) GetFailureDomainsNames

func (c *ClusterTx) GetFailureDomainsNames() (map[uint64]string, error)

GetFailureDomainsNames return a map associating failure domain IDs to their names.

func (*ClusterTx) GetImage

func (c *ClusterTx) GetImage(project string, fingerprint string) (*Image, error)

GetImage returns the image with the given key.

func (*ClusterTx) GetImageSource

func (c *ClusterTx) GetImageSource(imageID int) (int, api.ImageSource, error)

GetImageSource returns the image source with the given ID.

func (*ClusterTx) GetImages

func (c *ClusterTx) GetImages(filter ImageFilter) ([]Image, error)

GetImages returns all available images.

func (*ClusterTx) GetInstance

func (c *ClusterTx) GetInstance(project string, name string) (*Instance, error)

GetInstance returns the instance with the given key.

func (*ClusterTx) GetInstanceID

func (c *ClusterTx) GetInstanceID(project string, name string) (int64, error)

GetInstanceID return the ID of the instance with the given key.

func (*ClusterTx) GetInstanceNames

func (c *ClusterTx) GetInstanceNames(project string) ([]string, error)

GetInstanceNames returns the names of all containers the given project.

func (*ClusterTx) GetInstanceNamesByNodeAddress

func (c *ClusterTx) GetInstanceNamesByNodeAddress(project string, instanceType instancetype.Type) (map[string][]string, error)

GetInstanceNamesByNodeAddress returns the names of all containers grouped by cluster node address.

The node address of containers running on the local node is set to the empty string, to distinguish it from remote nodes.

Containers whose node is down are addeded to the special address "0.0.0.0".

func (*ClusterTx) GetInstancePool

func (c *ClusterTx) GetInstancePool(projectName string, instanceName string) (string, error)

GetInstancePool returns the storage pool of a given instance (or snapshot).

func (*ClusterTx) GetInstanceSnapshot

func (c *ClusterTx) GetInstanceSnapshot(project string, instance string, name string) (*InstanceSnapshot, error)

GetInstanceSnapshot returns the instance_snapshot with the given key.

func (*ClusterTx) GetInstanceSnapshotID

func (c *ClusterTx) GetInstanceSnapshotID(project string, instance string, name string) (int64, error)

GetInstanceSnapshotID return the ID of the instance_snapshot with the given key.

func (*ClusterTx) GetInstanceSnapshots

func (c *ClusterTx) GetInstanceSnapshots(filter InstanceSnapshotFilter) ([]InstanceSnapshot, error)

GetInstanceSnapshots returns all available instance_snapshots.

func (*ClusterTx) GetInstanceSnapshotsWithName

func (c *ClusterTx) GetInstanceSnapshotsWithName(project string, name string) ([]Instance, error)

GetInstanceSnapshotsWithName returns all snapshots of a given instance in date created order, oldest first.

func (*ClusterTx) GetInstanceToNodeMap

func (c *ClusterTx) GetInstanceToNodeMap(project string, instanceType instancetype.Type) (map[string]string, error)

GetInstanceToNodeMap returns a map associating the name of each instance in the given project to the name of the node hosting the instance.

func (*ClusterTx) GetInstances

func (c *ClusterTx) GetInstances(filter InstanceFilter) ([]Instance, error)

GetInstances returns all available instances.

func (*ClusterTx) GetLocalImagesFingerprints

func (c *ClusterTx) GetLocalImagesFingerprints() ([]string, error)

GetLocalImagesFingerprints returns the fingerprints of all local images.

func (*ClusterTx) GetLocalInstancesInProject

func (c *ClusterTx) GetLocalInstancesInProject(projectName string, instanceType instancetype.Type) ([]Instance, error)

GetLocalInstancesInProject retuurns all instances of the given type on the local node within the given project. If projectName is empty then all instances in all projects are returned.

func (*ClusterTx) GetLocalNodeAddress

func (c *ClusterTx) GetLocalNodeAddress() (string, error)

GetLocalNodeAddress returns the address of the node this method is invoked on.

func (*ClusterTx) GetLocalNodeName

func (c *ClusterTx) GetLocalNodeName() (string, error)

GetLocalNodeName returns the name of the node this method is invoked on.

func (*ClusterTx) GetLocalOperations

func (c *ClusterTx) GetLocalOperations() ([]Operation, error)

GetLocalOperations returns all operations associated with this node.

func (*ClusterTx) GetLocalOperationsUUIDs

func (c *ClusterTx) GetLocalOperationsUUIDs() ([]string, error)

GetLocalOperationsUUIDs returns the UUIDs of all operations associated with this node.

func (*ClusterTx) GetNetworkID

func (c *ClusterTx) GetNetworkID(projectName string, name string) (int64, error)

GetNetworkID returns the ID of the network with the given name.

func (*ClusterTx) GetNetworksLocalConfig

func (c *ClusterTx) GetNetworksLocalConfig() (map[string]map[string]string, error)

GetNetworksLocalConfig returns a map associating each network name to its node-specific config values on the local node (i.e. the ones where node_id equals the ID of the local node).

func (*ClusterTx) GetNodeAddressOfInstance

func (c *ClusterTx) GetNodeAddressOfInstance(project string, name string, instanceType instancetype.Type) (string, error)

GetNodeAddressOfInstance returns the address of the node hosting the instance with the given name in the given project.

It returns the empty string if the container is hosted on this node.

func (*ClusterTx) GetNodeByAddress

func (c *ClusterTx) GetNodeByAddress(address string) (NodeInfo, error)

GetNodeByAddress returns the node with the given network address.

func (*ClusterTx) GetNodeByName

func (c *ClusterTx) GetNodeByName(name string) (NodeInfo, error)

GetNodeByName returns the node with the given name.

func (*ClusterTx) GetNodeFailureDomain

func (c *ClusterTx) GetNodeFailureDomain(id int64) (string, error)

GetNodeFailureDomain returns the failure domain associated with the node with the given ID.

func (*ClusterTx) GetNodeMaxVersion

func (c *ClusterTx) GetNodeMaxVersion() ([2]int, error)

GetNodeMaxVersion returns the highest version possible on the cluster.

func (*ClusterTx) GetNodeOfflineThreshold

func (c *ClusterTx) GetNodeOfflineThreshold() (time.Duration, error)

GetNodeOfflineThreshold returns the amount of time that needs to elapse after which a series of unsuccessful heartbeat will make the node be considered offline.

func (*ClusterTx) GetNodeWithID

func (c *ClusterTx) GetNodeWithID(nodeID int) (NodeInfo, error)

GetNodeWithID returns the node with the given ID.

func (*ClusterTx) GetNodeWithLeastInstances

func (c *ClusterTx) GetNodeWithLeastInstances(archs []int, defaultArch int) (string, error)

GetNodeWithLeastInstances returns the name of the non-offline node with with the least number of containers (either already created or being created with an operation). If archs is not empty, then return only nodes with an architecture in that list.

func (*ClusterTx) GetNodes

func (c *ClusterTx) GetNodes() ([]NodeInfo, error)

GetNodes returns all LXD nodes part of the cluster.

If this LXD instance is not clustered, a list with a single node whose address is 0.0.0.0 is returned.

func (*ClusterTx) GetNodesCount

func (c *ClusterTx) GetNodesCount() (int, error)

GetNodesCount returns the number of nodes in the LXD cluster.

Since there's always at least one node row, even when not-clustered, the return value is greater than zero

func (*ClusterTx) GetNodesFailureDomains

func (c *ClusterTx) GetNodesFailureDomains() (map[string]uint64, error)

GetNodesFailureDomains returns a map associating each node address with its failure domain code.

func (*ClusterTx) GetNodesWithRunningOperations

func (c *ClusterTx) GetNodesWithRunningOperations(project string) ([]string, error)

GetNodesWithRunningOperations returns a list of nodes that have running operations

func (*ClusterTx) GetNonPendingNetworkIDs

func (c *ClusterTx) GetNonPendingNetworkIDs() (map[string]int64, error)

GetNonPendingNetworkIDs returns a map associating each network name to its ID.

Pending networks are skipped.

func (*ClusterTx) GetNonPendingStoragePoolsNamesToIDs

func (c *ClusterTx) GetNonPendingStoragePoolsNamesToIDs() (map[string]int64, error)

GetNonPendingStoragePoolsNamesToIDs returns a map associating each storage pool name to its ID.

Pending storage pools are skipped.

func (*ClusterTx) GetOperationByUUID

func (c *ClusterTx) GetOperationByUUID(uuid string) (Operation, error)

GetOperationByUUID returns the operation with the given UUID.

func (*ClusterTx) GetOperationWithID

func (c *ClusterTx) GetOperationWithID(opID int) (Operation, error)

GetOperationWithID returns the operation with the given ID.

func (*ClusterTx) GetOperationsOfType

func (c *ClusterTx) GetOperationsOfType(projectName string, opType OperationType) ([]Operation, error)

GetOperationsOfType returns a list operations that belong to the specified project and have the desired type.

func (*ClusterTx) GetPendingNodeByAddress

func (c *ClusterTx) GetPendingNodeByAddress(address string) (NodeInfo, error)

GetPendingNodeByAddress returns the pending node with the given network address.

func (*ClusterTx) GetProfile

func (c *ClusterTx) GetProfile(project string, name string) (*Profile, error)

GetProfile returns the profile with the given key.

func (*ClusterTx) GetProfileID

func (c *ClusterTx) GetProfileID(project string, name string) (int64, error)

GetProfileID return the ID of the profile with the given key.

func (*ClusterTx) GetProfileURIs

func (c *ClusterTx) GetProfileURIs(filter ProfileFilter) ([]string, error)

GetProfileURIs returns all available profile URIs.

func (*ClusterTx) GetProfiles

func (c *ClusterTx) GetProfiles(filter ProfileFilter) ([]Profile, error)

GetProfiles returns all available profiles.

func (*ClusterTx) GetProject

func (c *ClusterTx) GetProject(name string) (*api.Project, error)

GetProject returns the project with the given key.

func (*ClusterTx) GetProjectID

func (c *ClusterTx) GetProjectID(name string) (int64, error)

GetProjectID return the ID of the project with the given key.

func (*ClusterTx) GetProjectIDsToNames

func (c *ClusterTx) GetProjectIDsToNames() (map[int64]string, error)

GetProjectIDsToNames returns a map associating each project ID to its project name.

func (*ClusterTx) GetProjectNames

func (c *ClusterTx) GetProjectNames() ([]string, error)

GetProjectNames returns the names of all available projects.

func (*ClusterTx) GetProjectURIs

func (c *ClusterTx) GetProjectURIs(filter ProjectFilter) ([]string, error)

GetProjectURIs returns all available project URIs.

func (*ClusterTx) GetProjects

func (c *ClusterTx) GetProjects(filter ProjectFilter) ([]api.Project, error)

GetProjects returns all available projects.

func (*ClusterTx) GetStoragePoolDriver

func (c *ClusterTx) GetStoragePoolDriver(id int64) (string, error)

GetStoragePoolDriver returns the driver of the pool with the given ID.

func (*ClusterTx) GetStoragePoolID

func (c *ClusterTx) GetStoragePoolID(name string) (int64, error)

GetStoragePoolID returns the ID of the pool with the given name.

func (*ClusterTx) GetStoragePoolNodeConfigs

func (c *ClusterTx) GetStoragePoolNodeConfigs(poolID int64) (map[string]map[string]string, error)

GetStoragePoolNodeConfigs returns the node-specific configuration of all nodes grouped by node name, for the given poolID.

If the storage pool is not defined on all nodes, an error is returned.

func (*ClusterTx) GetStoragePoolUsedBy

func (c *ClusterTx) GetStoragePoolUsedBy(name string) ([]string, error)

GetStoragePoolUsedBy looks up all users of a storage pool.

func (*ClusterTx) GetStoragePoolsLocalConfig

func (c *ClusterTx) GetStoragePoolsLocalConfig() (map[string]map[string]string, error)

GetStoragePoolsLocalConfig returns a map associating each storage pool name to its node-specific config values (i.e. the ones where node_id is not NULL).

func (*ClusterTx) GetStorageVolumeNodes

func (c *ClusterTx) GetStorageVolumeNodes(poolID int64, projectName string, volumeName string, volumeType int) ([]NodeInfo, error)

GetStorageVolumeNodes returns the node info of all nodes on which the volume with the given name is defined. The volume name can be either a regular name or a volume snapshot name. If the volume is defined, but without a specific node, then the ErrNoClusterMember error is returned. If the volume is not found then the ErrNoSuchObject error is returned.

func (*ClusterTx) GetWarning

func (c *ClusterTx) GetWarning(UUID string) (*Warning, error)

GetWarning returns the warning with the given key.

func (*ClusterTx) GetWarningID

func (c *ClusterTx) GetWarningID(UUID string) (int64, error)

GetWarningID return the ID of the warning with the given key.

func (*ClusterTx) GetWarnings

func (c *ClusterTx) GetWarnings() ([]Warning, error)

GetWarnings returns all available warnings.

func (*ClusterTx) GetWarningsByProject

func (c *ClusterTx) GetWarningsByProject(projectName string) ([]Warning, error)

GetWarningsByProject returns all available warnings in the given project.

func (*ClusterTx) GetWarningsByStatus

func (c *ClusterTx) GetWarningsByStatus(status WarningStatus) ([]Warning, error)

GetWarningsByStatus returns all available warnings with the given status.

func (*ClusterTx) GetWarningsByType

func (c *ClusterTx) GetWarningsByType(typeCode WarningType) ([]Warning, error)

GetWarningsByType returns all available warnings with the given type.

func (*ClusterTx) InitProjectWithoutImages

func (c *ClusterTx) InitProjectWithoutImages(project string) error

InitProjectWithoutImages updates populates the images_profiles table with all images from the default project when a project is created with features.images=false.

func (*ClusterTx) InstanceConfigRef

func (c *ClusterTx) InstanceConfigRef(filter InstanceFilter) (map[string]map[string]map[string]string, error)

InstanceConfigRef returns entities used by instances.

func (*ClusterTx) InstanceDevicesRef

func (c *ClusterTx) InstanceDevicesRef(filter InstanceFilter) (map[string]map[string]map[string]map[string]string, error)

InstanceDevicesRef returns entities used by instances.

func (*ClusterTx) InstanceExists

func (c *ClusterTx) InstanceExists(project string, name string) (bool, error)

InstanceExists checks if a instance with the given key exists.

func (*ClusterTx) InstanceProfilesRef

func (c *ClusterTx) InstanceProfilesRef(filter InstanceFilter) (map[string]map[string][]string, error)

InstanceProfilesRef returns entities used by instances.

func (*ClusterTx) InstanceSnapshotConfigRef

func (c *ClusterTx) InstanceSnapshotConfigRef(filter InstanceSnapshotFilter) (map[string]map[string]map[string]map[string]string, error)

InstanceSnapshotConfigRef returns entities used by instance_snapshots.

func (*ClusterTx) InstanceSnapshotDevicesRef

func (c *ClusterTx) InstanceSnapshotDevicesRef(filter InstanceSnapshotFilter) (map[string]map[string]map[string]map[string]map[string]string, error)

InstanceSnapshotDevicesRef returns entities used by instance_snapshots.

func (*ClusterTx) InstanceSnapshotExists

func (c *ClusterTx) InstanceSnapshotExists(project string, instance string, name string) (bool, error)

InstanceSnapshotExists checks if a instance_snapshot with the given key exists.

func (*ClusterTx) NetworkCreated

func (c *ClusterTx) NetworkCreated(project string, name string) error

NetworkCreated sets the state of the given network to networkCreated.

func (*ClusterTx) NetworkErrored

func (c *ClusterTx) NetworkErrored(project string, name string) error

NetworkErrored sets the state of the given network to networkErrored.

func (*ClusterTx) NetworkNodeConfigs

func (c *ClusterTx) NetworkNodeConfigs(networkID int64) (map[string]map[string]string, error)

NetworkNodeConfigs returns the node-specific configuration of all nodes grouped by node name, for the given networkID.

If the network is not defined on all nodes, an error is returned.

func (*ClusterTx) NetworkNodeCreated

func (c *ClusterTx) NetworkNodeCreated(networkID int64) error

NetworkNodeCreated sets the state of the given network for the local member to networkCreated.

func (*ClusterTx) NetworkNodeJoin

func (c *ClusterTx) NetworkNodeJoin(networkID, nodeID int64) error

NetworkNodeJoin adds a new entry in the networks_nodes table.

It should only be used when a new node joins the cluster, when it's safe to assume that the relevant network has already been created on the joining node, and we just need to track it.

func (*ClusterTx) NetworkNodes

func (c *ClusterTx) NetworkNodes(networkID int64) (map[int64]NetworkNode, error)

NetworkNodes returns the nodes keyed by node ID that the given network is defined on.

func (*ClusterTx) NodeID

func (c *ClusterTx) NodeID(id int64)

NodeID sets the the node NodeID associated with this cluster transaction.

func (*ClusterTx) NodeIsEmpty

func (c *ClusterTx) NodeIsEmpty(id int64) (string, error)

NodeIsEmpty returns an empty string if the node with the given ID has no containers or images associated with it. Otherwise, it returns a message say what's left.

func (*ClusterTx) NodeIsOutdated

func (c *ClusterTx) NodeIsOutdated() (bool, error)

NodeIsOutdated returns true if there's some cluster node having an API or schema version greater than the node this method is invoked on.

func (*ClusterTx) ProfileConfigRef

func (c *ClusterTx) ProfileConfigRef(filter ProfileFilter) (map[string]map[string]map[string]string, error)

ProfileConfigRef returns entities used by profiles.

func (*ClusterTx) ProfileDevicesRef

func (c *ClusterTx) ProfileDevicesRef(filter ProfileFilter) (map[string]map[string]map[string]map[string]string, error)

ProfileDevicesRef returns entities used by profiles.

func (*ClusterTx) ProfileExists

func (c *ClusterTx) ProfileExists(project string, name string) (bool, error)

ProfileExists checks if a profile with the given key exists.

func (*ClusterTx) ProfileUsedByRef

func (c *ClusterTx) ProfileUsedByRef(filter ProfileFilter) (map[string]map[string][]string, error)

ProfileUsedByRef returns entities used by profiles.

func (*ClusterTx) ProjectConfigRef

func (c *ClusterTx) ProjectConfigRef(filter ProjectFilter) (map[string]map[string]string, error)

ProjectConfigRef returns entities used by projects.

func (*ClusterTx) ProjectExists

func (c *ClusterTx) ProjectExists(name string) (bool, error)

ProjectExists checks if a project with the given key exists.

func (*ClusterTx) ProjectHasImages

func (c *ClusterTx) ProjectHasImages(name string) (bool, error)

ProjectHasImages is a helper to check if a project has the images feature enabled.

func (*ClusterTx) ProjectHasProfiles

func (c *ClusterTx) ProjectHasProfiles(name string) (bool, error)

ProjectHasProfiles is a helper to check if a project has the profiles feature enabled.

func (*ClusterTx) ProjectUsedByRef

func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error)

ProjectUsedByRef returns entities used by projects.

func (*ClusterTx) RemoveNode

func (c *ClusterTx) RemoveNode(id int64) error

RemoveNode removes the node with the given id.

func (*ClusterTx) RemoveNodeRole

func (c *ClusterTx) RemoveNodeRole(id int64, role ClusterRole) error

RemoveNodeRole removes a role from the node.

func (*ClusterTx) RemoveOperation

func (c *ClusterTx) RemoveOperation(uuid string) error

RemoveOperation removes the operation with the given UUID.

func (*ClusterTx) RenameInstance

func (c *ClusterTx) RenameInstance(project string, name string, to string) error

RenameInstance renames the instance matching the given key parameters.

func (*ClusterTx) RenameInstanceSnapshot

func (c *ClusterTx) RenameInstanceSnapshot(project string, instance string, name string, to string) error

RenameInstanceSnapshot renames the instance_snapshot matching the given key parameters.

func (*ClusterTx) RenameNode

func (c *ClusterTx) RenameNode(old, new string) error

RenameNode changes the name of an existing node.

Return an error if a node with the same name already exists.

func (*ClusterTx) RenameProfile

func (c *ClusterTx) RenameProfile(project string, name string, to string) error

RenameProfile renames the profile matching the given key parameters.

func (*ClusterTx) RenameProject

func (c *ClusterTx) RenameProject(name string, to string) error

RenameProject renames the project matching the given key parameters.

func (*ClusterTx) SetDescription

func (c *ClusterTx) SetDescription(id int64, description string) error

SetDescription changes the description of the given node.

func (*ClusterTx) SetNodeHeartbeat

func (c *ClusterTx) SetNodeHeartbeat(address string, heartbeat time.Time) error

SetNodeHeartbeat updates the heartbeat column of the node with the given address.

func (*ClusterTx) SetNodePendingFlag

func (c *ClusterTx) SetNodePendingFlag(id int64, pending bool) error

SetNodePendingFlag toggles the pending flag for the node. A node is pending when it's been accepted in the cluster, but has not yet actually joined it.

func (*ClusterTx) SetNodeVersion

func (c *ClusterTx) SetNodeVersion(id int64, version [2]int) error

SetNodeVersion updates the schema and API version of the node with the given id. This is used only in tests.

func (*ClusterTx) StoragePoolCreated

func (c *ClusterTx) StoragePoolCreated(name string) error

StoragePoolCreated sets the state of the given pool to storagePoolCreated.

func (*ClusterTx) StoragePoolErrored

func (c *ClusterTx) StoragePoolErrored(name string) error

StoragePoolErrored sets the state of the given pool to storagePoolErrored.

func (*ClusterTx) StoragePoolNodeCreated

func (c *ClusterTx) StoragePoolNodeCreated(poolID int64) error

StoragePoolNodeCreated sets the state of the given storage pool for the local member to storagePoolCreated.

func (*ClusterTx) UpdateCephStoragePoolAfterNodeJoin

func (c *ClusterTx) UpdateCephStoragePoolAfterNodeJoin(poolID, nodeID int64) error

UpdateCephStoragePoolAfterNodeJoin updates internal state to reflect that nodeID is joining a cluster where poolID is a ceph pool.

func (*ClusterTx) UpdateCertificate

func (c *ClusterTx) UpdateCertificate(fingerprint string, object Certificate) error

UpdateCertificate updates the certificate matching the given key parameters.

func (*ClusterTx) UpdateCertificateProjects

func (c *ClusterTx) UpdateCertificateProjects(id int, projects []string) error

UpdateCertificateProjects updates the list of projects on a certificate.

func (*ClusterTx) UpdateConfig

func (c *ClusterTx) UpdateConfig(values map[string]string) error

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

func (*ClusterTx) UpdateInstance

func (c *ClusterTx) UpdateInstance(project string, name string, object Instance) error

UpdateInstance updates the instance matching the given key parameters.

func (*ClusterTx) UpdateInstanceConfig

func (c *ClusterTx) UpdateInstanceConfig(id int, values map[string]string) error

UpdateInstanceConfig inserts/updates/deletes the provided keys

func (*ClusterTx) UpdateInstanceLastUsedDate

func (c *ClusterTx) UpdateInstanceLastUsedDate(id int, date time.Time) error

UpdateInstanceLastUsedDate updates the last_use_date field of the instance with the given ID.

func (*ClusterTx) UpdateInstanceNode

func (c *ClusterTx) UpdateInstanceNode(project, oldName, newName, newNode string) error

UpdateInstanceNode changes the node hosting an instance.

It's meant to be used when moving a non-running instance backed by ceph from one cluster node to another.

func (*ClusterTx) UpdateInstancePowerState

func (c *ClusterTx) UpdateInstancePowerState(id int, state string) error

UpdateInstancePowerState sets the the power state of the container with the given ID.

func (*ClusterTx) UpdateInstanceSnapshot

func (c *ClusterTx) UpdateInstanceSnapshot(id int, description string, expiryDate time.Time) error

UpdateInstanceSnapshot updates the description and expiry date of the instance snapshot with the given ID.

func (*ClusterTx) UpdateInstanceSnapshotConfig

func (c *ClusterTx) UpdateInstanceSnapshotConfig(id int, values map[string]string) error

UpdateInstanceSnapshotConfig inserts/updates/deletes the provided config keys.

func (*ClusterTx) UpdateNetwork

func (c *ClusterTx) UpdateNetwork(id int64, description string, config map[string]string) error

UpdateNetwork updates the network with the given ID.

func (*ClusterTx) UpdateNode

func (c *ClusterTx) UpdateNode(id int64, name string, address string) error

UpdateNode updates the name an address of a node.

func (*ClusterTx) UpdateNodeFailureDomain

func (c *ClusterTx) UpdateNodeFailureDomain(id int64, domain string) error

UpdateNodeFailureDomain changes the failure domain of a node.

func (*ClusterTx) UpdateNodeRoles

func (c *ClusterTx) UpdateNodeRoles(id int64, roles []ClusterRole) error

UpdateNodeRoles changes the list of roles on a member.

func (*ClusterTx) UpdateProfile

func (c *ClusterTx) UpdateProfile(project string, name string, object Profile) error

UpdateProfile updates the profile matching the given key parameters.

func (*ClusterTx) UpdateProject

func (c *ClusterTx) UpdateProject(name string, object api.ProjectPut) error

UpdateProject updates the project matching the given key parameters.

func (*ClusterTx) UpdateStoragePoolAfterNodeJoin

func (c *ClusterTx) UpdateStoragePoolAfterNodeJoin(poolID, nodeID int64) error

UpdateStoragePoolAfterNodeJoin adds a new entry in the storage_pools_nodes table.

It should only be used when a new node joins the cluster, when it's safe to assume that the relevant pool has already been created on the joining node, and we just need to track it.

func (*ClusterTx) UpdateWarningState

func (c *ClusterTx) UpdateWarningState(UUID string, message string, status WarningStatus) error

UpdateWarningState updates the warning message and status with the given ID.

func (*ClusterTx) UpdateWarningStatus

func (c *ClusterTx) UpdateWarningStatus(UUID string, status WarningStatus) error

UpdateWarningStatus updates the status of the warning with the given UUID.

func (*ClusterTx) WarningExists

func (c *ClusterTx) WarningExists(UUID string) (bool, error)

WarningExists checks if a warning with the given key exists.

type Dump

type Dump struct {
	// Map table names to the names or their columns.
	Schema map[string][]string

	// Map a table name to all the rows it contains. Each row is a slice
	// of interfaces.
	Data map[string][][]interface{}
}

Dump is a dump of all the user data in the local db prior the migration to the cluster db.

func LoadPreClusteringData

func LoadPreClusteringData(tx *sql.Tx) (*Dump, error)

LoadPreClusteringData loads all the data that before the introduction of LXD clustering used to live in the node-level database.

This is used for performing a one-off data migration when a LXD instance is upgraded from a version without clustering to a version that supports clustering, since in those version all data lives in the cluster database (regardless of whether clustering is actually on or off).

type Image

type Image struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name"`
	Fingerprint  string `db:"primary=yes&comparison=like"`
	Type         int
	Filename     string
	Size         int64
	Public       bool
	Architecture int
	CreationDate time.Time
	ExpiryDate   time.Time
	UploadDate   time.Time
	Cached       bool
	LastUseDate  time.Time
	AutoUpdate   bool
}

Image is a value object holding db-related details about an image.

type ImageFilter

type ImageFilter struct {
	Project     string
	Fingerprint string // Matched with LIKE
	Public      bool
	Cached      bool
	AutoUpdate  bool
}

ImageFilter can be used to filter results yielded by GetImages.

type Instance

type Instance struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name"`
	Name         string `db:"primary=yes"`
	Node         string `db:"join=nodes.name"`
	Type         instancetype.Type
	Snapshot     bool `db:"ignore"`
	Architecture int
	Ephemeral    bool
	CreationDate time.Time
	Stateful     bool
	LastUseDate  time.Time
	Description  string `db:"coalesce=''"`
	Config       map[string]string
	Devices      map[string]map[string]string
	Profiles     []string
	ExpiryDate   time.Time
}

Instance is a value object holding db-related details about an instance.

func InstanceSnapshotToInstance

func InstanceSnapshotToInstance(instance *Instance, snapshot *InstanceSnapshot) Instance

InstanceSnapshotToInstance is a temporary convenience function to merge together an Instance struct and a SnapshotInstance struct into into a the legacy Instance struct for a snapshot.

type InstanceArgs

type InstanceArgs struct {
	// Don't set manually
	ID       int
	Node     string
	Type     instancetype.Type
	Snapshot bool

	// Creation only
	Project      string
	BaseImage    string
	CreationDate time.Time

	Architecture int
	Config       map[string]string
	Description  string
	Devices      deviceConfig.Devices
	Ephemeral    bool
	LastUsedDate time.Time
	Name         string
	Profiles     []string
	Stateful     bool
	ExpiryDate   time.Time
}

InstanceArgs is a value object holding all db-related details about an instance.

func InstanceToArgs

func InstanceToArgs(inst *Instance) InstanceArgs

InstanceToArgs is a convenience to convert an Instance db struct into the legacy InstanceArgs.

type InstanceBackup

type InstanceBackup struct {
	ID                   int
	InstanceID           int
	Name                 string
	CreationDate         time.Time
	ExpiryDate           time.Time
	InstanceOnly         bool
	OptimizedStorage     bool
	CompressionAlgorithm string
}

InstanceBackup is a value object holding all db-related details about an instance backup.

type InstanceFilter

type InstanceFilter struct {
	Project string
	Name    string
	Node    string
	Type    instancetype.Type
}

InstanceFilter can be used to filter results yielded by InstanceList.

type InstanceSnapshot

type InstanceSnapshot struct {
	ID           int
	Project      string `db:"primary=yes&join=projects.name&via=instance"`
	Instance     string `db:"primary=yes&join=instances.name"`
	Name         string `db:"primary=yes"`
	CreationDate time.Time
	Stateful     bool
	Description  string `db:"coalesce=''"`
	Config       map[string]string
	Devices      map[string]map[string]string
	ExpiryDate   time.Time
}

InstanceSnapshot is a value object holding db-related details about a snapshot.

type InstanceSnapshotFilter

type InstanceSnapshotFilter struct {
	Project  string
	Instance string
	Name     string
}

InstanceSnapshotFilter can be used to filter results yielded by GetInstanceSnapshots.

type LegacyPatch

type LegacyPatch struct {
	Hook func(*sql.Tx) 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 NetworkNode

type NetworkNode struct {
	ID    int64
	Name  string
	State NetworkState
}

NetworkNode represents a network node.

type NetworkState

type NetworkState int

NetworkState indicates the state of the network or network node.

type NetworkType

type NetworkType int

NetworkType indicates type of network.

const (
	NetworkTypeBridge   NetworkType = iota // Network type bridge.
	NetworkTypeMacvlan                     // Network type macvlan.
	NetworkTypeSriov                       // Network type sriov.
	NetworkTypeOVN                         // Network type ovn.
	NetworkTypePhysical                    // Network type physical.
)

Network types.

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 (*Node) Begin

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

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

func (*Node) Close

func (n *Node) Close() error

Close the database facade.

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

func (n *Node) Dir() string

Dir returns the directory of the underlying SQLite database file.

func (*Node) GetAppliedPatches

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

GetAppliedPatches returns the names of all patches currently applied on this node.

func (*Node) MarkPatchAsApplied

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

MarkPatchAsApplied marks the patch with the given name as applied on this node.

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 NodeInfo

type NodeInfo struct {
	ID            int64     // Stable node identifier
	Name          string    // User-assigned name of the node
	Address       string    // Network address of the node
	Description   string    // Node description (optional)
	Schema        int       // Schema version of the LXD code running the node
	APIExtensions int       // Number of API extensions of the LXD code running on the node
	Heartbeat     time.Time // Timestamp of the last heartbeat
	Roles         []string  // List of cluster roles
	Architecture  int       // Node architecture
	State         int       // Node state
}

NodeInfo holds information about a single LXD instance in a cluster.

func (NodeInfo) IsOffline

func (n NodeInfo) IsOffline(threshold time.Duration) bool

IsOffline returns true if the last successful heartbeat time of the node is older than the given threshold.

func (NodeInfo) ToAPI

func (n NodeInfo) ToAPI(cluster *Cluster, node *Node) (*api.ClusterMember, error)

ToAPI returns a LXD API entry.

func (NodeInfo) Version

func (n NodeInfo) Version() [2]int

Version returns the node's version, composed by its schema level and number of extensions.

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

func (n *NodeTx) CreateFirstRaftNode(address string) error

CreateFirstRaftNode adds a the first node of the cluster. It ensures that the database ID is 1, to match the server ID of the first raft log entry.

This method is supposed to be called when there are no rows in raft_nodes, and it will replace whatever existing row has ID 1.

func (*NodeTx) CreateRaftNode

func (n *NodeTx) CreateRaftNode(address string) (int64, error)

CreateRaftNode adds a node to the current list of LXD nodes that are part of the dqlite Raft cluster. It returns the ID of the newly inserted row.

func (*NodeTx) GetCertificates

func (n *NodeTx) GetCertificates() ([]Certificate, error)

GetCertificates returns all available local certificates.

func (*NodeTx) GetRaftNodeAddress

func (n *NodeTx) GetRaftNodeAddress(id int64) (string, error)

GetRaftNodeAddress returns the address of the LXD raft node with the given ID, if any matching row exists.

func (*NodeTx) GetRaftNodeAddresses

func (n *NodeTx) GetRaftNodeAddresses() ([]string, error)

GetRaftNodeAddresses returns the addresses of all LXD nodes that are members of the dqlite Raft cluster (possibly including the local node). If this LXD instance is not running in clustered mode, an empty list is returned.

func (*NodeTx) GetRaftNodes

func (n *NodeTx) GetRaftNodes() ([]RaftNode, error)

GetRaftNodes returns information about all LXD nodes that are members of the dqlite Raft cluster (possibly including the local node). If this LXD instance is not running in clustered mode, an empty list is returned.

func (*NodeTx) RemoteRaftNode

func (n *NodeTx) RemoteRaftNode(id int64) error

RemoteRaftNode removes a node from the current list of LXD nodes that are part of the dqlite Raft cluster.

func (*NodeTx) ReplaceCertificates

func (n *NodeTx) ReplaceCertificates(certs []Certificate) error

ReplaceCertificates removes all existing certificates from the local certificates table and replaces them with the ones provided.

func (*NodeTx) ReplaceRaftNodes

func (n *NodeTx) ReplaceRaftNodes(nodes []RaftNode) error

ReplaceRaftNodes replaces the current list of raft nodes.

func (*NodeTx) Tx

func (n *NodeTx) Tx() *sql.Tx

Tx returns the low level database handle to the node-local SQLite transaction.

FIXME: this is a transitional method needed for compatibility with some

legacy call sites. It should be removed when there are no more
consumers.

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.

type Operation

type Operation struct {
	ID          int64         // Stable database identifier
	UUID        string        // User-visible identifier
	NodeAddress string        // Address of the node the operation is running on
	Type        OperationType // Type of the operation
}

Operation holds information about a single LXD operation running on a node in the cluster.

type OperationType

type OperationType int64

OperationType is a numeric code indentifying the type of an Operation.

const (
	OperationUnknown OperationType = iota
	OperationClusterBootstrap
	OperationClusterJoin
	OperationBackupCreate
	OperationBackupRename
	OperationBackupRestore
	OperationBackupRemove
	OperationConsoleShow
	OperationInstanceCreate
	OperationInstanceUpdate
	OperationInstanceRename
	OperationInstanceMigrate
	OperationInstanceLiveMigrate
	OperationInstanceFreeze
	OperationInstanceUnfreeze
	OperationInstanceDelete
	OperationInstanceStart
	OperationInstanceStop
	OperationInstanceRestart
	OperationCommandExec
	OperationSnapshotCreate
	OperationSnapshotRename
	OperationSnapshotRestore
	OperationSnapshotTransfer
	OperationSnapshotUpdate
	OperationSnapshotDelete
	OperationImageDownload
	OperationImageDelete
	OperationImageToken
	OperationImageRefresh
	OperationVolumeCopy
	OperationVolumeCreate
	OperationVolumeMigrate
	OperationVolumeMove
	OperationVolumeSnapshotCreate
	OperationVolumeSnapshotDelete
	OperationVolumeSnapshotUpdate
	OperationProjectRename
	OperationImagesExpire
	OperationImagesPruneLeftover
	OperationImagesUpdate
	OperationImagesSynchronize
	OperationLogsExpire
	OperationInstanceTypesUpdate
	OperationBackupsExpire
	OperationSnapshotsExpire
	OperationCustomVolumeSnapshotsExpire
	OperationCustomVolumeBackupCreate
	OperationCustomVolumeBackupRemove
	OperationCustomVolumeBackupRename
	OperationCustomVolumeBackupRestore
	OperationWarningsPruneResolved
	OperationClusterJoinToken
	OperationVolumeSnapshotRename
)

Possible values for OperationType

WARNING: The type codes are stored in the database, so this list of

definitions should be normally append-only. Any other change
requires a database update.

func (OperationType) Description

func (t OperationType) Description() string

Description return a human-readable description of the operation type.

func (OperationType) Permission

func (t OperationType) Permission() string

Permission returns the needed RBAC permission to cancel the oepration

type Profile

type Profile struct {
	ID          int
	Project     string `db:"primary=yes&join=projects.name"`
	Name        string `db:"primary=yes"`
	Description string `db:"coalesce=''"`
	Config      map[string]string
	Devices     map[string]map[string]string
	UsedBy      []string
}

Profile is a value object holding db-related details about a profile.

type ProfileFilter

type ProfileFilter struct {
	Project string
	Name    string
}

ProfileFilter can be used to filter results yielded by ProfileList.

type ProjectFilter

type ProjectFilter struct {
	Name string // If non-empty, return only the project with this name.
}

ProjectFilter can be used to filter results yielded by ProjectList.

type RaftNode

type RaftNode = client.NodeInfo

RaftNode holds information about a single node in the dqlite raft cluster.

This is just a convenience alias for the equivalent data structure in the dqlite client package.

type RaftRole

type RaftRole = client.NodeRole

RaftRole captures the role of dqlite/raft node.

type StoragePoolNode

type StoragePoolNode struct {
	ID    int64
	Name  string
	State StoragePoolState
}

StoragePoolNode represents a storage pool node.

type StoragePoolState

type StoragePoolState int

StoragePoolState indicates the state of the storage pool or storage pool node.

type StoragePoolVolumeBackup

type StoragePoolVolumeBackup struct {
	ID                   int
	VolumeID             int64
	Name                 string
	CreationDate         time.Time
	ExpiryDate           time.Time
	VolumeOnly           bool
	OptimizedStorage     bool
	CompressionAlgorithm string
}

StoragePoolVolumeBackup is a value object holding all db-related details about a storage volume backup.

type StorageVolumeArgs

type StorageVolumeArgs struct {
	ID   int64
	Name string

	// At least one of Type or TypeName must be set.
	Type     int
	TypeName string

	// At least one of PoolID or PoolName must be set.
	PoolID   int64
	PoolName string

	Snapshot bool

	Config       map[string]string
	Description  string
	CreationDate time.Time
	ExpiryDate   time.Time

	// At least on of ProjectID or ProjectName must be set.
	ProjectID   int64
	ProjectName string

	ContentType string

	NodeID int64
}

StorageVolumeArgs is a value object holding all db-related details about a storage volume.

type Warning

type Warning struct {
	ID             int
	Node           string
	Project        string
	EntityTypeCode int
	EntityID       int
	UUID           string
	TypeCode       WarningType
	Status         WarningStatus
	FirstSeenDate  time.Time
	LastSeenDate   time.Time
	UpdatedDate    time.Time
	LastMessage    string
	Count          int
}

Warning is a value object holding db-related details about a warning.

func (Warning) ToAPI

func (w Warning) ToAPI(c *Cluster) (api.Warning, error)

ToAPI returns a LXD API entry.

type WarningSeverity

type WarningSeverity int

WarningSeverity represents the warning severity.

const (
	// WarningSeverityLow represents the low WarningSeverity
	WarningSeverityLow WarningSeverity = 1
	// WarningSeverityModerate represents the moderate WarningSeverity
	WarningSeverityModerate WarningSeverity = 2
	// WarningSeverityHigh represents the high WarningSeverity
	WarningSeverityHigh WarningSeverity = 3
)

type WarningStatus

type WarningStatus int

WarningStatus represents the warning status.

const (
	// WarningStatusNew represents the New WarningStatus
	WarningStatusNew WarningStatus = 1
	// WarningStatusAcknowledged represents the Acknowledged WarningStatus
	WarningStatusAcknowledged WarningStatus = 2
	// WarningStatusResolved represents the Resolved WarningStatus
	WarningStatusResolved WarningStatus = 3
)

type WarningType

type WarningType int

WarningType is a numeric code indentifying the type of warning.

const (
	// WarningUndefined represents an undefined warning
	WarningUndefined WarningType = iota
	// WarningMissingCGroupBlkio represents the missing CGroup blkio warning
	WarningMissingCGroupBlkio
	// WarningMissingCGroupBlkioWeight represents the missing CGroup blkio.weight warning
	WarningMissingCGroupBlkioWeight
	// WarningMissingCGroupCPUController represents the missing CGroup CPU controller warning
	WarningMissingCGroupCPUController
	// WarningMissingCGroupCPUsetController represents the missing GCgroup CPUset controller warning
	WarningMissingCGroupCPUsetController
	// WarningMissingCGroupCPUacctController represents the missing GCgroup CPUacct controller warning
	WarningMissingCGroupCPUacctController
	// WarningMissingCGroupDevicesController represents the missing GCgroup devices controller warning
	WarningMissingCGroupDevicesController
	// WarningMissingCGroupFreezerController represents the missing GCgroup freezer controller warning
	WarningMissingCGroupFreezerController
	// WarningMissingCGroupHugetlbController represents the missing GCgroup hugetlb controller warning
	WarningMissingCGroupHugetlbController
	// WarningMissingCGroupMemoryController represents the missing GCgroup memory controller warning
	WarningMissingCGroupMemoryController
	// WarningMissingCGroupNetworkPriorityController represents the missing GCgroup network priority controller warning
	WarningMissingCGroupNetworkPriorityController
	// WarningMissingCGroupPidsController represents the missing GCgroup pids controller warning
	WarningMissingCGroupPidsController
	// WarningMissingCGroupMemorySwapAccounting represents the missing GCgroup memory swap accounting warning
	WarningMissingCGroupMemorySwapAccounting
	// WarningClusterTimeSkew represents the cluster time skew warning
	WarningClusterTimeSkew
	// WarningAppArmorNotAvailable represents the AppArmor not available warning
	WarningAppArmorNotAvailable
	//WarningMissingVirtiofsd represents the missing virtiofsd warning
	WarningMissingVirtiofsd
	// WarningUnableToConnectToMAAS represents the unable to connect to MAAS warning
	WarningUnableToConnectToMAAS
	// WarningAppArmorDisabledDueToRawDnsmasq represents the disabled AppArmor due to raw.dnsmasq warning
	WarningAppArmorDisabledDueToRawDnsmasq
	// WarningLargerIPv6PrefixThanSupported represents the larger IPv6 prefix than supported warning
	WarningLargerIPv6PrefixThanSupported
	// WarningProxyBridgeNetfilterNotEnabled represents the proxy bridge netfilter not enable warning
	WarningProxyBridgeNetfilterNotEnabled
	// WarningNetworkStartupFailure represents the network startup failure warning
	WarningNetworkStartupFailure
	// WarningOfflineClusterMember represents the offline cluster members warning
	WarningOfflineClusterMember
	// WarningInstanceAutostartFailure represents the failure of instance autostart process after three retries
	WarningInstanceAutostartFailure
)

func (WarningType) Severity

func (t WarningType) Severity() WarningSeverity

Severity returns the severity of the warning type.

Directories

Path Synopsis
db
file
Package file contains helpers to write auto-generated Go source files.
Package file contains helpers to write auto-generated Go source files.
lex
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