db

package
v0.0.0-...-54b8d16 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterMemberStateCreated   = 0
	ClusterMemberStatePending   = 1
	ClusterMemberStateEvacuated = 2
)

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 ClusterRoleDatabase = ClusterRole("database")

ClusterRoleDatabase represents the database role in a cluster.

View Source
const ClusterRoleDatabaseLeader = ClusterRole("database-leader")

ClusterRoleDatabaseLeader represents the database leader role in a cluster.

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

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

View Source
const ClusterRoleEventHub = ClusterRole("event-hub")

ClusterRoleEventHub represents a cluster member who operates as an event hub.

View Source
const ClusterRoleOVNChassis = ClusterRole("ovn-chassis")

ClusterRoleOVNChassis represents a cluster member who operates as an OVN chassis.

View Source
const DefaultOfflineThreshold = 20

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

Variables

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 ErrListStop = fmt.Errorf("search stopped")

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

View Source
var (
	// ErrNoClusterMember is used to indicate no cluster member has been found for a resource.
	ErrNoClusterMember = fmt.Errorf("No cluster member found")
)
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 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{
	"bgp.ipv4.nexthop",
	"bgp.ipv6.nexthop",
	"bridge.external_interfaces",
	"parent",
}

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

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

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

View Source
var SmartErrors = map[int][]error{
	http.StatusConflict:           {sqlite3.ErrConstraintUnique},
	http.StatusServiceUnavailable: {driver.ErrNoAvailableLeader},
}

SmartErrors are used to return more appropriate errors to the caller.

View Source
var StorageRemoteDriverNames func() []string

StorageRemoteDriverNames returns a list of remote storage driver names.

Functions

func ClusterGroupToAPI

func ClusterGroupToAPI(clusterGroup *cluster.ClusterGroup, nodes []string) *api.ClusterGroup

ClusterGroupToAPI is a convenience to convert a ClusterGroup db struct into an API cluster group struct.

func CreateInstanceConfig

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

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

func DqliteLatestSegment

func DqliteLatestSegment() (string, error)

DqliteLatestSegment returns the latest segment ID in the global database.

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 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 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(closingCtx context.Context, 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. Accepts a closingCtx context argument used to indicate when the daemon is shutting down.

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

func (c *Cluster) DeleteNetworkPeer(networkID int64, peerID int64) error

DeleteNetworkPeer deletes an existing Network Peer.

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(ctx context.Context, f func(context.Context, *ClusterTx) error) error

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

func (*Cluster) GetNetworkPeersTargetNetworkIDs

func (c *Cluster) GetNetworkPeersTargetNetworkIDs(projectName string, networkType NetworkType) (map[NetworkPeer]int64, error)

GetNetworkPeersTargetNetworkIDs returns a map of peer connections to target network IDs for networks in the specified project and network type.

func (*Cluster) GetNodeID

func (c *Cluster) GetNodeID() int64

GetNodeID returns the current nodeID (0 if not set).

func (*Cluster) LocalNodeIsEvacuated

func (c *Cluster) LocalNodeIsEvacuated() bool

LocalNodeIsEvacuated returns whether the local member is in the evacuated state.

func (*Cluster) NodeID

func (c *Cluster) NodeID(id int64)

NodeID sets 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) Transaction

func (c *Cluster) Transaction(ctx context.Context, f func(context.Context, *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) UpdateNetworkZone

func (c *Cluster) UpdateNetworkZone(id int64, config *api.NetworkZonePut) error

UpdateNetworkZone updates the Network zone with the given ID.

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

func (c *ClusterTx) AddImageToLocalNode(ctx context.Context, project, fingerprint string) error

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

func (*ClusterTx) AddNodeToClusterGroup

func (c *ClusterTx) AddNodeToClusterGroup(ctx context.Context, groupName string, nodeName string) error

AddNodeToClusterGroup adds a given node to the given cluster group.

func (*ClusterTx) BootstrapNode

func (c *ClusterTx) BootstrapNode(name string, address string) error

BootstrapNode sets the name and address of the first cluster member, with id: 1.

func (*ClusterTx) ClearNode

func (c *ClusterTx) ClearNode(ctx context.Context, id int64) error

ClearNode removes any instance or image associated with this node.

func (*ClusterTx) Config

func (c *ClusterTx) Config(ctx context.Context) (map[string]string, error)

Config fetches all LXD cluster config keys.

func (*ClusterTx) CopyDefaultImageProfiles

func (c *ClusterTx) CopyDefaultImageProfiles(ctx context.Context, id int, newID int) error

CopyDefaultImageProfiles copies default profiles from id to new_id.

func (*ClusterTx) CreateImage

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

CreateImage creates a new image.

func (*ClusterTx) CreateImageAlias

func (c *ClusterTx) CreateImageAlias(ctx context.Context, projectName, aliasName string, imageID int, desc string) error

CreateImageAlias inserts an alias ento the database.

func (*ClusterTx) CreateImageSource

func (c *ClusterTx) CreateImageSource(ctx context.Context, id int, server string, protocol string, certificate string, alias string) error

CreateImageSource inserts a new image source.

func (*ClusterTx) CreateInstanceBackup

func (c *ClusterTx) CreateInstanceBackup(ctx context.Context, args InstanceBackup) error

CreateInstanceBackup creates a new backup.

func (*ClusterTx) CreateInstanceConfig

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

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

func (*ClusterTx) CreateNetwork

func (c *ClusterTx) CreateNetwork(ctx context.Context, projectName string, name string, description string, netType NetworkType, config map[string]string) (int64, error)

CreateNetwork creates a new network.

func (*ClusterTx) CreateNetworkACL

func (c *ClusterTx) CreateNetworkACL(ctx context.Context, projectName string, info *api.NetworkACLsPost) (int64, error)

CreateNetworkACL creates a new Network ACL.

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

func (c *ClusterTx) CreateNetworkForward(ctx context.Context, networkID int64, memberSpecific bool, info *api.NetworkForwardsPost) (int64, error)

CreateNetworkForward creates a new Network Forward. If memberSpecific is true, then the forward is associated to the current member, rather than being associated to all members.

func (*ClusterTx) CreateNetworkLoadBalancer

func (c *ClusterTx) CreateNetworkLoadBalancer(ctx context.Context, networkID int64, memberSpecific bool, info *api.NetworkLoadBalancersPost) (int64, error)

CreateNetworkLoadBalancer creates a new Network Load Balancer. If memberSpecific is true, then the load balancer is associated to the current member, rather than being associated to all members.

func (*ClusterTx) CreateNetworkPeer

func (c *ClusterTx) CreateNetworkPeer(ctx context.Context, networkID int64, info *api.NetworkPeersPost) (int64, bool, error)

CreateNetworkPeer creates a new Network Peer and returns its ID. If there is a mutual peering on the target network side the both peer entries are upated to link to each other's repspective network ID. Returns the local peer ID and true if a mutual peering has been created.

func (*ClusterTx) CreateNetworkZone

func (c *ClusterTx) CreateNetworkZone(ctx context.Context, projectName string, info *api.NetworkZonesPost) (int64, error)

CreateNetworkZone creates a new Network zone.

func (*ClusterTx) CreateNetworkZoneRecord

func (c *ClusterTx) CreateNetworkZoneRecord(ctx context.Context, zone int64, info api.NetworkZoneRecordsPost) (int64, error)

CreateNetworkZoneRecord creates a new network zone record.

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

func (c *ClusterTx) CreatePendingNetwork(ctx context.Context, 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(ctx context.Context, node string, name string, driver string, conf map[string]string) error

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

func (*ClusterTx) CreateStoragePool

func (c *ClusterTx) CreateStoragePool(ctx context.Context, poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error)

CreateStoragePool creates new storage pool. Also creates a local member entry with state storagePoolPending.

func (*ClusterTx) CreateStoragePoolBucket

func (c *ClusterTx) CreateStoragePoolBucket(ctx context.Context, poolID int64, projectName string, memberSpecific bool, info api.StorageBucketsPost) (int64, error)

CreateStoragePoolBucket creates a new Storage Bucket. If memberSpecific is true, then the storage bucket is associated to the current member, rather than being associated to all members.

func (*ClusterTx) CreateStoragePoolBucketKey

func (c *ClusterTx) CreateStoragePoolBucketKey(ctx context.Context, bucketID int64, info api.StorageBucketKeysPost) (int64, error)

CreateStoragePoolBucketKey creates a new Storage Bucket Key.

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

func (c *ClusterTx) CreateStoragePoolVolume(ctx context.Context, projectName string, volumeName string, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, contentType int, creationDate time.Time) (int64, error)

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

func (*ClusterTx) CreateStoragePoolVolumeBackup

func (c *ClusterTx) CreateStoragePoolVolumeBackup(ctx context.Context, args StoragePoolVolumeBackup) error

CreateStoragePoolVolumeBackup creates a new storage volume backup.

func (*ClusterTx) CreateStorageVolumeSnapshot

func (c *ClusterTx) CreateStorageVolumeSnapshot(ctx context.Context, projectName string, volumeName string, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, creationDate time.Time, expiryDate time.Time) (int64, error)

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

func (*ClusterTx) DeleteImage

func (c *ClusterTx) DeleteImage(ctx context.Context, id int) error

DeleteImage deletes the image with the given ID.

func (*ClusterTx) DeleteImageAlias

func (c *ClusterTx) DeleteImageAlias(ctx context.Context, projectName string, name string) error

DeleteImageAlias deletes the alias with the given name.

func (*ClusterTx) DeleteInstance

func (c *ClusterTx) DeleteInstance(ctx context.Context, project, name string) error

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

func (*ClusterTx) DeleteInstanceBackup

func (c *ClusterTx) DeleteInstanceBackup(ctx context.Context, name string) error

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

func (*ClusterTx) DeleteInstanceConfigKey

func (c *ClusterTx) DeleteInstanceConfigKey(ctx context.Context, id int64, key string) error

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

func (*ClusterTx) DeleteNetwork

func (c *ClusterTx) DeleteNetwork(ctx context.Context, project string, name string) error

DeleteNetwork deletes the network with the given name.

func (*ClusterTx) DeleteNetworkACL

func (c *ClusterTx) DeleteNetworkACL(ctx context.Context, id int64) error

DeleteNetworkACL deletes the Network ACL.

func (*ClusterTx) DeleteNetworkForward

func (c *ClusterTx) DeleteNetworkForward(ctx context.Context, networkID int64, forwardID int64) error

DeleteNetworkForward deletes an existing Network Forward.

func (*ClusterTx) DeleteNetworkLoadBalancer

func (c *ClusterTx) DeleteNetworkLoadBalancer(ctx context.Context, networkID int64, loadBalancerID int64) error

DeleteNetworkLoadBalancer deletes an existing Network Load Balancer.

func (*ClusterTx) DeleteNetworkZone

func (c *ClusterTx) DeleteNetworkZone(ctx context.Context, id int64) error

DeleteNetworkZone deletes the Network zone.

func (*ClusterTx) DeleteNetworkZoneRecord

func (c *ClusterTx) DeleteNetworkZoneRecord(ctx context.Context, id int64) error

DeleteNetworkZoneRecord deletes the network zone record.

func (*ClusterTx) DeleteReadyStateFromLocalInstances

func (c *ClusterTx) DeleteReadyStateFromLocalInstances(ctx context.Context) error

DeleteReadyStateFromLocalInstances deletes the volatile.last_state.ready config key from all local instances.

func (*ClusterTx) DeleteStoragePoolBucket

func (c *ClusterTx) DeleteStoragePoolBucket(ctx context.Context, poolID int64, bucketID int64) error

DeleteStoragePoolBucket deletes an existing Storage Bucket.

func (*ClusterTx) DeleteStoragePoolBucketKey

func (c *ClusterTx) DeleteStoragePoolBucketKey(ctx context.Context, bucketID int64, keyID int64) error

DeleteStoragePoolBucketKey deletes an existing Storage Bucket Key.

func (*ClusterTx) DeleteStoragePoolVolumeBackup

func (c *ClusterTx) DeleteStoragePoolVolumeBackup(ctx context.Context, name string) error

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

func (*ClusterTx) GetAllNodesWithOperations

func (c *ClusterTx) GetAllNodesWithOperations(ctx context.Context) ([]string, error)

GetAllNodesWithOperations returns a list of nodes that have operations in any project.

func (*ClusterTx) GetCachedImageSourceFingerprint

func (c *ClusterTx) GetCachedImageSourceFingerprint(ctx context.Context, 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 (*ClusterTx) GetCandidateMembers

func (c *ClusterTx) GetCandidateMembers(ctx context.Context, allMembers []NodeInfo, targetArchitectures []int, targetClusterGroup string, allowedClusterGroups []string, offlineThreshold time.Duration) ([]NodeInfo, error)

GetCandidateMembers returns cluster members that are online, in created state and don't need manual targeting. It excludes members that do not support any of the targetArchitectures (if non-nil) or not in targetClusterGroup (if non-empty). It also takes into account any restrictions on allowedClusterGroups (if non-nil).

func (*ClusterTx) GetClusterGroupNodes

func (c *ClusterTx) GetClusterGroupNodes(ctx context.Context, groupName string) ([]string, error)

GetClusterGroupNodes returns a list of nodes of the given cluster group.

func (*ClusterTx) GetClusterGroupURIs

func (c *ClusterTx) GetClusterGroupURIs(ctx context.Context, filter cluster.ClusterGroupFilter) ([]string, error)

GetClusterGroupURIs returns all available ClusterGroup URIs. generator: ClusterGroup URIs

func (*ClusterTx) GetClusterGroupsWithNode

func (c *ClusterTx) GetClusterGroupsWithNode(ctx context.Context, nodeName string) ([]string, error)

GetClusterGroupsWithNode returns a list of cluster group names the given node belongs to.

func (*ClusterTx) GetCreatedNetworkNamesByProject

func (c *ClusterTx) GetCreatedNetworkNamesByProject(ctx context.Context, project string) ([]string, error)

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

func (*ClusterTx) GetCreatedNetworks

func (c *ClusterTx) GetCreatedNetworks(ctx context.Context) (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) GetCreatedNetworksByProject

func (c *ClusterTx) GetCreatedNetworksByProject(ctx context.Context, projectName string) (map[int64]api.Network, error)

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

func (*ClusterTx) GetCreatedStoragePoolNames

func (c *ClusterTx) GetCreatedStoragePoolNames(ctx context.Context) ([]string, error)

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

func (*ClusterTx) GetCustomVolumesInProject

func (c *ClusterTx) GetCustomVolumesInProject(ctx context.Context, project string) ([]StorageVolumeArgs, error)

GetCustomVolumesInProject returns all custom volumes in the given project.

func (*ClusterTx) GetExpiredInstanceBackups

func (c *ClusterTx) GetExpiredInstanceBackups(ctx context.Context) ([]InstanceBackup, error)

GetExpiredInstanceBackups returns a list of expired instance backups.

func (*ClusterTx) GetExpiredStorageVolumeBackups

func (c *ClusterTx) GetExpiredStorageVolumeBackups(ctx context.Context) ([]StoragePoolVolumeBackup, error)

GetExpiredStorageVolumeBackups returns a list of expired storage volume backups.

func (*ClusterTx) GetExpiredStorageVolumeSnapshots

func (c *ClusterTx) GetExpiredStorageVolumeSnapshots(ctx context.Context, memberSpecific bool) ([]StorageVolumeArgs, error)

GetExpiredStorageVolumeSnapshots returns a list of expired volume snapshots. If memberSpecific is true, then the search is restricted to volumes that belong to this member or belong to all members.

func (*ClusterTx) GetFailureDomainsNames

func (c *ClusterTx) GetFailureDomainsNames(ctx context.Context) (map[uint64]string, error)

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

func (*ClusterTx) GetImage

func (c *ClusterTx) GetImage(ctx context.Context, fingerprintPrefix string, filter cluster.ImageFilter) (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. publicOnly, when true, will return the image only if it is public; a false value will return any image matching the fingerprint prefix.

func (*ClusterTx) GetImageAlias

func (c *ClusterTx) GetImageAlias(ctx context.Context, projectName string, imageName string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)

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

func (*ClusterTx) GetImageAliases

func (c *ClusterTx) GetImageAliases(ctx context.Context, projectName string) ([]string, error)

GetImageAliases returns the names of the aliases of all images.

func (*ClusterTx) GetImageByFingerprintPrefix

func (c *ClusterTx) GetImageByFingerprintPrefix(ctx context.Context, fingerprintPrefix string, filter cluster.ImageFilter) (int, *api.Image, error)

GetImageByFingerprintPrefix 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. publicOnly, when true, will return the image only if it is public; a false value will return any image matching the fingerprint prefix.

func (*ClusterTx) GetImageFromAnyProject

func (c *ClusterTx) GetImageFromAnyProject(ctx context.Context, fingerprint string) (int, *api.Image, error)

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

func (*ClusterTx) GetImageSource

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

GetImageSource returns the image source with the given ID.

func (*ClusterTx) GetImages

func (c *ClusterTx) GetImages(ctx context.Context) (map[string][]string, error)

GetImages returns all images.

func (*ClusterTx) GetImagesFingerprints

func (c *ClusterTx) GetImagesFingerprints(ctx context.Context, projectName string, publicOnly bool) ([]string, error)

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

func (*ClusterTx) GetImagesOnLocalNode

func (c *ClusterTx) GetImagesOnLocalNode(ctx context.Context) (map[string][]string, error)

GetImagesOnLocalNode returns all images that the local server holds.

func (*ClusterTx) GetImagesOnNode

func (c *ClusterTx) GetImagesOnNode(ctx context.Context, id int64) (map[string][]string, error)

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

func (*ClusterTx) GetInstanceBackup

func (c *ClusterTx) GetInstanceBackup(ctx context.Context, projectName string, name string) (InstanceBackup, error)

GetInstanceBackup returns the backup with the given name.

func (*ClusterTx) GetInstanceBackupWithID

func (c *ClusterTx) GetInstanceBackupWithID(ctx context.Context, backupID int) (InstanceBackup, error)

GetInstanceBackupWithID returns the backup with the given ID.

func (*ClusterTx) GetInstanceBackups

func (c *ClusterTx) GetInstanceBackups(ctx context.Context, projectName string, name string) ([]string, error)

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

func (*ClusterTx) GetInstanceConfig

func (c *ClusterTx) GetInstanceConfig(ctx context.Context, 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 (*ClusterTx) GetInstanceID

func (c *ClusterTx) GetInstanceID(ctx context.Context, project, name string) (int, error)

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

func (*ClusterTx) GetInstanceNames

func (c *ClusterTx) GetInstanceNames(ctx context.Context, project string) ([]string, error)

GetInstanceNames returns the names of all containers the given project.

func (*ClusterTx) GetInstancePool

func (c *ClusterTx) GetInstancePool(ctx context.Context, projectName string, instanceName string) (string, error)

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

func (*ClusterTx) GetInstanceProjectAndName

func (c *ClusterTx) GetInstanceProjectAndName(ctx context.Context, id int) (project string, name string, err error)

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

func (*ClusterTx) GetInstanceSnapshotID

func (c *ClusterTx) GetInstanceSnapshotID(ctx context.Context, project, instance, name string) (int, error)

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

func (*ClusterTx) GetInstanceSnapshotsNames

func (c *ClusterTx) GetInstanceSnapshotsNames(ctx context.Context, project, name string) ([]string, error)

GetInstanceSnapshotsNames returns the names of all snapshots of the instance in the given project with the given name. Returns snapshots slice ordered by when they were created, oldest first.

func (*ClusterTx) GetInstanceSnapshotsWithName

func (c *ClusterTx) GetInstanceSnapshotsWithName(ctx context.Context, project string, name string) ([]cluster.Instance, error)

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

func (*ClusterTx) GetInstancesByMemberAddress

func (c *ClusterTx) GetInstancesByMemberAddress(ctx context.Context, offlineThreshold time.Duration, projects []string, instType instancetype.Type) (map[string][]Instance, error)

GetInstancesByMemberAddress returns the instances associated to each cluster member address. The member address of instances running on the local member is set to the empty string, to distinguish it from remote nodes. Instances whose member is down are added to the special address "0.0.0.0".

func (*ClusterTx) GetInstancesWithProfile

func (c *ClusterTx) GetInstancesWithProfile(ctx context.Context, 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 (*ClusterTx) GetLocalExpiredInstanceSnapshots

func (c *ClusterTx) GetLocalExpiredInstanceSnapshots(ctx context.Context) ([]cluster.InstanceSnapshot, error)

GetLocalExpiredInstanceSnapshots returns a list of expired snapshots.

func (*ClusterTx) GetLocalImagesFingerprints

func (c *ClusterTx) GetLocalImagesFingerprints(ctx context.Context) ([]string, error)

GetLocalImagesFingerprints returns the fingerprints of all local images.

func (*ClusterTx) GetLocalInstanceWithVsockID

func (c *ClusterTx) GetLocalInstanceWithVsockID(ctx context.Context, vsockID int) (*cluster.Instance, error)

GetLocalInstanceWithVsockID returns all available instances with the given config key and value.

func (*ClusterTx) GetLocalInstancesInProject

func (c *ClusterTx) GetLocalInstancesInProject(ctx context.Context, filter cluster.InstanceFilter) ([]cluster.Instance, error)

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

func (*ClusterTx) GetLocalNodeAddress

func (c *ClusterTx) GetLocalNodeAddress(ctx context.Context) (string, error)

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

func (*ClusterTx) GetLocalNodeName

func (c *ClusterTx) GetLocalNodeName(ctx context.Context) (string, error)

GetLocalNodeName returns the name of the node this method is invoked on. Usually you should not use this function directly but instead use the cached State.ServerName value.

func (*ClusterTx) GetLocalStoragePoolVolumeSnapshotsWithType

func (c *ClusterTx) GetLocalStoragePoolVolumeSnapshotsWithType(ctx context.Context, 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 member. Returns snapshots slice ordered by when they were created, oldest first.

func (*ClusterTx) GetNetworkACL

func (c *ClusterTx) GetNetworkACL(ctx context.Context, projectName string, name string) (int64, *api.NetworkACL, error)

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

func (*ClusterTx) GetNetworkACLIDsByNames

func (c *ClusterTx) GetNetworkACLIDsByNames(ctx context.Context, project string) (map[string]int64, error)

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

func (*ClusterTx) GetNetworkACLNameAndProjectWithID

func (c *ClusterTx) GetNetworkACLNameAndProjectWithID(ctx context.Context, networkACLID int) (networkACLName string, projectName string, err error)

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

func (*ClusterTx) GetNetworkACLURIs

func (c *ClusterTx) GetNetworkACLURIs(ctx context.Context, projectID int, project string) ([]string, error)

GetNetworkACLURIs returns the URIs for the network ACLs with the given project.

func (*ClusterTx) GetNetworkACLs

func (c *ClusterTx) GetNetworkACLs(ctx context.Context, project string) ([]string, error)

GetNetworkACLs returns the names of existing Network ACLs.

func (*ClusterTx) GetNetworkForward

func (c *ClusterTx) GetNetworkForward(ctx context.Context, networkID int64, memberSpecific bool, listenAddress string) (int64, *api.NetworkForward, error)

GetNetworkForward returns the Network Forward ID and info for the given network ID and listen address. If memberSpecific is true, then the search is restricted to forwards that belong to this member or belong to all members.

func (*ClusterTx) GetNetworkForwardListenAddresses

func (c *ClusterTx) GetNetworkForwardListenAddresses(ctx context.Context, networkID int64, memberSpecific bool) (map[int64]string, error)

GetNetworkForwardListenAddresses returns map of Network Forward Listen Addresses for the given network ID keyed on Forward ID. If memberSpecific is true, then the search is restricted to forwards that belong to this member or belong to all members.

func (*ClusterTx) GetNetworkForwards

func (c *ClusterTx) GetNetworkForwards(ctx context.Context, networkID int64, memberSpecific bool, listenAddresses ...string) (map[int64]*api.NetworkForward, error)

GetNetworkForwards returns map of Network Forwards for the given network ID keyed on Forward ID. If memberSpecific is true, then the search is restricted to forwards that belong to this member or belong to all members. Can optionally retrieve only specific network forwards by listen address.

func (*ClusterTx) GetNetworkID

func (c *ClusterTx) GetNetworkID(ctx context.Context, projectName string, name string) (int64, error)

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

func (*ClusterTx) GetNetworkInAnyState

func (c *ClusterTx) GetNetworkInAnyState(ctx context.Context, projectName string, networkName string) (int64, *api.Network, map[int64]NetworkNode, error)

GetNetworkInAnyState returns the network with the given name. The network can be in any state. Returns network ID, network info, and network cluster member info.

func (*ClusterTx) GetNetworkLoadBalancer

func (c *ClusterTx) GetNetworkLoadBalancer(ctx context.Context, networkID int64, memberSpecific bool, listenAddress string) (int64, *api.NetworkLoadBalancer, error)

GetNetworkLoadBalancer returns the Network Load Balancer ID and info for the given network ID and listen address. If memberSpecific is true, then the search is restricted to load balancers that belong to this member or belong to all members.

func (*ClusterTx) GetNetworkLoadBalancerListenAddresses

func (c *ClusterTx) GetNetworkLoadBalancerListenAddresses(ctx context.Context, networkID int64, memberSpecific bool) (map[int64]string, error)

GetNetworkLoadBalancerListenAddresses returns map of Network Load Balancer Listen Addresses for the given network ID keyed on Load Balancer ID. If memberSpecific is true, then the search is restricted to load balancers that belong to this member or belong to all members.

func (*ClusterTx) GetNetworkLoadBalancers

func (c *ClusterTx) GetNetworkLoadBalancers(ctx context.Context, networkID int64, memberSpecific bool, listenAddresses ...string) (map[int64]*api.NetworkLoadBalancer, error)

GetNetworkLoadBalancers returns map of Network Load Balancers for the given network ID keyed on Load Balancer ID. If memberSpecific is true, then the search is restricted to load balancers that belong to this member or belong to all members. Can optionally retrieve only specific network load balancers by listen address.

func (*ClusterTx) GetNetworkNameAndProjectWithID

func (c *ClusterTx) GetNetworkNameAndProjectWithID(ctx context.Context, networkID int) (networkName string, projectName string, err error)

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

func (*ClusterTx) GetNetworkPeer

func (c *ClusterTx) GetNetworkPeer(ctx context.Context, networkID int64, peerName string) (int64, *api.NetworkPeer, error)

GetNetworkPeer returns the Network Peer ID and info for the given network ID and peer name.

func (*ClusterTx) GetNetworkPeerNames

func (c *ClusterTx) GetNetworkPeerNames(ctx context.Context, networkID int64) (map[int64]string, error)

GetNetworkPeerNames returns map of Network Peer names for the given network ID keyed on Peer ID.

func (*ClusterTx) GetNetworkPeers

func (c *ClusterTx) GetNetworkPeers(ctx context.Context, networkID int64) (map[int64]*api.NetworkPeer, error)

GetNetworkPeers returns map of Network Peers for the given network ID keyed on Peer ID.

func (*ClusterTx) GetNetworkURIs

func (c *ClusterTx) GetNetworkURIs(ctx context.Context, projectID int, project string) ([]string, error)

GetNetworkURIs returns the URIs for the networks with the given project.

func (*ClusterTx) GetNetworkWithInterface

func (c *ClusterTx) GetNetworkWithInterface(ctx context.Context, devName string) (int64, *api.Network, error)

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

func (*ClusterTx) GetNetworkZone

func (c *ClusterTx) GetNetworkZone(ctx context.Context, name string) (int64, string, *api.NetworkZone, error)

GetNetworkZone returns the Network zone with the given name.

func (*ClusterTx) GetNetworkZoneByProject

func (c *ClusterTx) GetNetworkZoneByProject(ctx context.Context, projectName string, name string) (int64, *api.NetworkZone, error)

GetNetworkZoneByProject returns the Network zone with the given name in the given project.

func (*ClusterTx) GetNetworkZoneKeys

func (c *ClusterTx) GetNetworkZoneKeys(ctx context.Context) (map[string]string, error)

GetNetworkZoneKeys returns a map of key names to keys.

func (*ClusterTx) GetNetworkZoneRecord

func (c *ClusterTx) GetNetworkZoneRecord(ctx context.Context, zone int64, name string) (int64, *api.NetworkZoneRecord, error)

GetNetworkZoneRecord returns the network zone record for the given zone and name.

func (*ClusterTx) GetNetworkZoneRecordNames

func (c *ClusterTx) GetNetworkZoneRecordNames(ctx context.Context, zone int64) ([]string, error)

GetNetworkZoneRecordNames returns the names of existing Network zone records.

func (*ClusterTx) GetNetworkZones

func (c *ClusterTx) GetNetworkZones(ctx context.Context) (map[string]string, error)

GetNetworkZones returns the names of existing Network zones mapped to project name.

func (*ClusterTx) GetNetworkZonesByProject

func (c *ClusterTx) GetNetworkZonesByProject(ctx context.Context, project string) ([]string, error)

GetNetworkZonesByProject returns the names of existing Network zones.

func (*ClusterTx) GetNetworks

func (c *ClusterTx) GetNetworks(ctx context.Context, project string) ([]string, error)

GetNetworks returns the names of existing networks.

func (*ClusterTx) GetNetworksLocalConfig

func (c *ClusterTx) GetNetworksLocalConfig(ctx context.Context) (map[string]map[string]string, error)

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

func (*ClusterTx) GetNextInstanceSnapshotIndex

func (c *ClusterTx) GetNextInstanceSnapshotIndex(ctx context.Context, project string, name string, pattern string) (nextIndex int)

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

func (*ClusterTx) GetNextStorageVolumeSnapshotIndex

func (c *ClusterTx) GetNextStorageVolumeSnapshotIndex(ctx context.Context, pool, name string, typ int, pattern string) (nextIndex 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 (*ClusterTx) GetNodeAddressOfInstance

func (c *ClusterTx) GetNodeAddressOfInstance(ctx context.Context, project string, name string, instType 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(ctx context.Context, address string) (NodeInfo, error)

GetNodeByAddress returns the node with the given network address.

func (*ClusterTx) GetNodeByName

func (c *ClusterTx) GetNodeByName(ctx context.Context, name string) (NodeInfo, error)

GetNodeByName returns the node with the given name.

func (*ClusterTx) GetNodeFailureDomain

func (c *ClusterTx) GetNodeFailureDomain(ctx context.Context, id int64) (string, error)

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

func (*ClusterTx) GetNodeID

func (c *ClusterTx) GetNodeID() int64

GetNodeID gets the ID of the node associated with this cluster transaction.

func (*ClusterTx) GetNodeMaxVersion

func (c *ClusterTx) GetNodeMaxVersion(ctx context.Context) ([2]int, error)

GetNodeMaxVersion returns the highest schema and API versions possible on the cluster.

func (*ClusterTx) GetNodeOfflineThreshold

func (c *ClusterTx) GetNodeOfflineThreshold(ctx context.Context) (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(ctx context.Context, nodeID int) (NodeInfo, error)

GetNodeWithID returns the node with the given ID.

func (*ClusterTx) GetNodeWithLeastInstances

func (c *ClusterTx) GetNodeWithLeastInstances(ctx context.Context, members []NodeInfo) (*NodeInfo, error)

GetNodeWithLeastInstances returns the name of the member with the least number of instances that are either already created or being created with an operation.

func (*ClusterTx) GetNodes

func (c *ClusterTx) GetNodes(ctx context.Context) ([]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(ctx context.Context) (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(ctx context.Context) (map[string]uint64, error)

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

func (*ClusterTx) GetNodesWithImage

func (c *ClusterTx) GetNodesWithImage(ctx context.Context, fingerprint string) ([]string, error)

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

func (*ClusterTx) GetNodesWithImageAndAutoUpdate

func (c *ClusterTx) GetNodesWithImageAndAutoUpdate(ctx context.Context, fingerprint string, autoUpdate bool) ([]string, error)

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

func (*ClusterTx) GetNodesWithOperations

func (c *ClusterTx) GetNodesWithOperations(ctx context.Context, project string) ([]string, error)

GetNodesWithOperations returns a list of nodes that have operations.

func (*ClusterTx) GetNodesWithoutImage

func (c *ClusterTx) GetNodesWithoutImage(ctx context.Context, fingerprint string) ([]string, error)

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

func (*ClusterTx) GetNonPendingNetworkIDs

func (c *ClusterTx) GetNonPendingNetworkIDs(ctx context.Context) (map[string]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(ctx context.Context) (map[string]int64, error)

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

Pending storage pools are skipped.

func (*ClusterTx) GetOperationsOfType

func (c *ClusterTx) GetOperationsOfType(ctx context.Context, projectName string, opType operationtype.Type) ([]cluster.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(ctx context.Context, address string) (NodeInfo, error)

GetPendingNodeByAddress returns the pending node with the given network address.

func (*ClusterTx) GetPoolNamesFromIDs

func (c *ClusterTx) GetPoolNamesFromIDs(ctx context.Context, poolIDs []int64) ([]string, error)

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

func (*ClusterTx) GetPoolsWithImage

func (c *ClusterTx) GetPoolsWithImage(ctx context.Context, imageFingerprint string) ([]int64, error)

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

func (*ClusterTx) GetProfile

func (c *ClusterTx) GetProfile(ctx context.Context, project, name string) (int64, *api.Profile, error)

GetProfile returns the profile with the given name.

func (*ClusterTx) GetProfileNames

func (c *ClusterTx) GetProfileNames(ctx context.Context, project string) ([]string, error)

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

func (*ClusterTx) GetProfiles

func (c *ClusterTx) GetProfiles(ctx context.Context, projectName string, profileNames []string) ([]api.Profile, error)

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

func (*ClusterTx) GetProjectInstancesAndProfiles

func (c *ClusterTx) GetProjectInstancesAndProfiles(ctx context.Context, projects ...*api.Project) (map[string]*ProjectArgs, error)

GetProjectInstancesAndProfiles gets all instances and profiles associated with some projects in as few queries as possible. Returns a map[projectName]args.

func (c *ClusterTx) GetProjectNetworkForwardListenAddressesByUplink(ctx context.Context, uplinkNetworkName string, memberSpecific bool) (map[string]map[string][]string, error)

GetProjectNetworkForwardListenAddressesByUplink returns map of Network Forward Listen Addresses that belong to networks connected to the specified uplinkNetworkName. Returns a map keyed on project name and network name containing a slice of listen addresses.

func (*ClusterTx) GetProjectNetworkForwardListenAddressesOnMember

func (c *ClusterTx) GetProjectNetworkForwardListenAddressesOnMember(ctx context.Context) (map[string]map[int64][]string, error)

GetProjectNetworkForwardListenAddressesOnMember returns map of Network Forward Listen Addresses that belong to to this specific cluster member. Will not include forwards that do not have a specific member. Returns a map keyed on project name and network ID containing a slice of listen addresses.

func (c *ClusterTx) GetProjectNetworkLoadBalancerListenAddressesByUplink(ctx context.Context, uplinkNetworkName string, memberSpecific bool) (map[string]map[string][]string, error)

GetProjectNetworkLoadBalancerListenAddressesByUplink returns map of Network Load Balancer Listen Addresses that belong to networks connected to the specified uplinkNetworkName. Returns a map keyed on project name and network name containing a slice of listen addresses.

func (*ClusterTx) GetProjectNetworkLoadBalancerListenAddressesOnMember

func (c *ClusterTx) GetProjectNetworkLoadBalancerListenAddressesOnMember(ctx context.Context) (map[string]map[int64][]string, error)

GetProjectNetworkLoadBalancerListenAddressesOnMember returns map of Network Load Balancer Listen Addresses that belong to to this specific cluster member. Will not include load balancers that do not have a specific member. Returns a map keyed on project name and network ID containing a slice of listen addresses.

func (*ClusterTx) GetProjectsUsingImage

func (c *ClusterTx) GetProjectsUsingImage(ctx context.Context, fingerprint string) ([]string, error)

GetProjectsUsingImage get the project names using an image by fingerprint.

func (*ClusterTx) GetStorageDrivers

func (c *ClusterTx) GetStorageDrivers(ctx context.Context) ([]string, error)

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

func (*ClusterTx) GetStoragePool

func (c *ClusterTx) GetStoragePool(ctx context.Context, 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 (*ClusterTx) GetStoragePoolBucket

func (c *ClusterTx) GetStoragePoolBucket(ctx context.Context, poolID int64, projectName string, memberSpecific bool, bucketName string) (*StorageBucket, error)

GetStoragePoolBucket returns the Storage Bucket for the given Storage Pool ID, Project Name and Bucket Name. If memberSpecific is true, then the search is restricted to buckets that belong to this member or belong to all members.

func (*ClusterTx) GetStoragePoolBucketKey

func (c *ClusterTx) GetStoragePoolBucketKey(ctx context.Context, bucketID int64, keyName string) (*StorageBucketKey, error)

GetStoragePoolBucketKey returns the Storage Bucket Key for the given Bucket ID and Key Name.

func (*ClusterTx) GetStoragePoolBucketKeys

func (c *ClusterTx) GetStoragePoolBucketKeys(ctx context.Context, bucketID int64, filters ...StorageBucketKeyFilter) ([]*StorageBucketKey, error)

GetStoragePoolBucketKeys returns all storage buckets keys attached to a given storage bucket. If there are no bucket keys, it returns an empty list and no error. Accepts filters for narrowing down the results returned.

func (*ClusterTx) GetStoragePoolBuckets

func (c *ClusterTx) GetStoragePoolBuckets(ctx context.Context, memberSpecific bool, filters ...StorageBucketFilter) ([]*StorageBucket, error)

GetStoragePoolBuckets returns all storage buckets. If there are no buckets, it returns an empty list and no error. Accepts filters for narrowing down the results returned. If memberSpecific is true, then the search is restricted to buckets that belong to this member or belong to all members.

func (*ClusterTx) GetStoragePoolDriver

func (c *ClusterTx) GetStoragePoolDriver(ctx context.Context, id int64) (string, error)

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

func (*ClusterTx) GetStoragePoolDrivers

func (c *ClusterTx) GetStoragePoolDrivers(ctx context.Context) (map[string]string, error)

GetStoragePoolDrivers maps all storage pool names to driver name.

func (*ClusterTx) GetStoragePoolID

func (c *ClusterTx) GetStoragePoolID(ctx context.Context, name string) (int64, error)

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

func (*ClusterTx) GetStoragePoolInAnyState

func (c *ClusterTx) GetStoragePoolInAnyState(ctx context.Context, poolName 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 (*ClusterTx) GetStoragePoolLocalBucket

func (c *ClusterTx) GetStoragePoolLocalBucket(ctx context.Context, bucketName string) (*StorageBucket, error)

GetStoragePoolLocalBucket returns the local Storage Bucket for the given bucket name. The search is restricted to buckets that belong to this member.

func (*ClusterTx) GetStoragePoolLocalBucketByAccessKey

func (c *ClusterTx) GetStoragePoolLocalBucketByAccessKey(ctx context.Context, accessKey string) (*StorageBucket, error)

GetStoragePoolLocalBucketByAccessKey returns the local Storage Bucket for the given bucket access key. The search is restricted to buckets that belong to this member.

func (*ClusterTx) GetStoragePoolNames

func (c *ClusterTx) GetStoragePoolNames(ctx context.Context) ([]string, error)

GetStoragePoolNames returns the names of all storage pools.

func (*ClusterTx) GetStoragePoolNodeConfigs

func (c *ClusterTx) GetStoragePoolNodeConfigs(ctx context.Context, 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) GetStoragePoolNodeVolumeID

func (c *ClusterTx) GetStoragePoolNodeVolumeID(ctx context.Context, 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 (*ClusterTx) GetStoragePoolVolume

func (c *ClusterTx) GetStoragePoolVolume(ctx context.Context, poolID int64, projectName string, volumeType int, volumeName string, memberSpecific bool) (*StorageVolume, error)

GetStoragePoolVolume returns the storage volume attached to a given storage pool.

func (*ClusterTx) GetStoragePoolVolumeBackup

func (c *ClusterTx) GetStoragePoolVolumeBackup(ctx context.Context, projectName string, poolName string, backupName string) (StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackup returns the volume backup with the given name.

func (*ClusterTx) GetStoragePoolVolumeBackupWithID

func (c *ClusterTx) GetStoragePoolVolumeBackupWithID(ctx context.Context, backupID int) (StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackupWithID returns the volume backup with the given ID.

func (*ClusterTx) GetStoragePoolVolumeBackups

func (c *ClusterTx) GetStoragePoolVolumeBackups(ctx context.Context, projectName string, volumeName string, poolID int64) ([]StoragePoolVolumeBackup, error)

GetStoragePoolVolumeBackups returns a list of volume backups.

func (*ClusterTx) GetStoragePoolVolumeBackupsNames

func (c *ClusterTx) GetStoragePoolVolumeBackupsNames(ctx context.Context, projectName string, volumeName string, poolID int64) ([]string, error)

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

func (*ClusterTx) GetStoragePoolVolumeWithID

func (c *ClusterTx) GetStoragePoolVolumeWithID(ctx context.Context, volumeID int) (StorageVolumeArgs, error)

GetStoragePoolVolumeWithID returns the volume with the given ID.

func (*ClusterTx) GetStoragePoolVolumesWithType

func (c *ClusterTx) GetStoragePoolVolumesWithType(ctx context.Context, volumeType int, memberSpecific bool) ([]StorageVolumeArgs, error)

GetStoragePoolVolumesWithType return a list of all volumes of the given type. If memberSpecific is true, then the search is restricted to volumes that belong to this member or belong to all members.

func (*ClusterTx) GetStoragePoolWithID

func (c *ClusterTx) GetStoragePoolWithID(ctx context.Context, poolID int) (int64, *api.StoragePool, map[int64]StoragePoolNode, error)

GetStoragePoolWithID returns the storage pool with the given ID.

func (*ClusterTx) GetStoragePools

func (c *ClusterTx) GetStoragePools(ctx context.Context, state *StoragePoolState, poolNames ...string) (map[int64]api.StoragePool, map[int64]map[int64]StoragePoolNode, error)

GetStoragePools returns map of Storage Pools keyed on ID and Storage Pool member info keyed on ID and Member ID. Can optionally accept a state filter, if nil, then pools in any state are returned. Can optionally accept one or more poolNames to further filter the returned pools.

func (*ClusterTx) GetStoragePoolsLocalConfig

func (c *ClusterTx) GetStoragePoolsLocalConfig(ctx context.Context) (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(ctx context.Context, 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 an api.StatusError with code set to http.StatusNotFound is returned.

func (*ClusterTx) GetStorageVolumeSnapshotExpiry

func (c *ClusterTx) GetStorageVolumeSnapshotExpiry(ctx context.Context, volumeID int64) (time.Time, error)

GetStorageVolumeSnapshotExpiry gets the expiry date of a storage volume snapshot.

func (*ClusterTx) GetStorageVolumeSnapshotWithID

func (c *ClusterTx) GetStorageVolumeSnapshotWithID(ctx context.Context, snapshotID int) (StorageVolumeArgs, error)

GetStorageVolumeSnapshotWithID returns the volume snapshot with the given ID.

func (*ClusterTx) GetStorageVolumeURIs

func (c *ClusterTx) GetStorageVolumeURIs(ctx context.Context, project string) ([]string, error)

GetStorageVolumeURIs returns the URIs of the storage volumes, specifying target node if applicable.

func (*ClusterTx) GetStorageVolumes

func (c *ClusterTx) GetStorageVolumes(ctx context.Context, memberSpecific bool, filters ...StorageVolumeFilter) ([]*StorageVolume, error)

GetStorageVolumes returns all storage volumes. If there are no volumes, it returns an empty list and no error. Accepts filters for narrowing down the results returned. If memberSpecific is true, then the search is restricted to volumes that belong to this member or belong to all members.

func (*ClusterTx) ImageExists

func (c *ClusterTx) ImageExists(ctx context.Context, project string, fingerprint string) (bool, error)

ImageExists returns whether an image with the given fingerprint exists.

func (*ClusterTx) ImageIsReferencedByOtherProjects

func (c *ClusterTx) ImageIsReferencedByOtherProjects(ctx context.Context, 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 (*ClusterTx) InstanceList

func (c *ClusterTx) InstanceList(ctx context.Context, instanceFunc func(inst InstanceArgs, project api.Project) error, filters ...cluster.InstanceFilter) 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 arguments to specify a subset of instances.

func (*ClusterTx) InstancesToInstanceArgs

func (c *ClusterTx) InstancesToInstanceArgs(ctx context.Context, fillProfiles bool, instances ...cluster.Instance) (map[int]InstanceArgs, error)

InstancesToInstanceArgs converts many cluster.Instance to a map of InstanceArgs in as few queries as possible. Accepts fillProfiles argument that controls whether or not the returned InstanceArgs have their Profiles field populated. This avoids the need to load profile info from the database if it is already available in the caller's context and can be populated afterwards.

func (*ClusterTx) IsRemoteStorage

func (c *ClusterTx) IsRemoteStorage(ctx context.Context, poolID int64) (bool, error)

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

func (*ClusterTx) LocateImage

func (c *ClusterTx) LocateImage(ctx context.Context, 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 (*ClusterTx) MoveImageAlias

func (c *ClusterTx) MoveImageAlias(ctx context.Context, source int, destination int) error

MoveImageAlias changes the image ID associated with an alias.

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(ctx context.Context, 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(ctx context.Context, 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 node NodeID associated with this cluster transaction.

func (*ClusterTx) NodeIsEmpty

func (c *ClusterTx) NodeIsEmpty(ctx context.Context, id int64) (string, error)

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

func (*ClusterTx) NodeIsOutdated

func (c *ClusterTx) NodeIsOutdated(ctx context.Context) (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) RemoveNode

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

RemoveNode removes the node with the given id.

func (*ClusterTx) RemoveNodeFromClusterGroup

func (c *ClusterTx) RemoveNodeFromClusterGroup(ctx context.Context, groupName string, nodeName string) error

RemoveNodeFromClusterGroup removes a given node from the given group name.

func (*ClusterTx) RemoveStoragePool

func (c *ClusterTx) RemoveStoragePool(ctx context.Context, poolName string) (*api.StoragePool, error)

RemoveStoragePool deletes storage pool.

func (*ClusterTx) RemoveStoragePoolVolume

func (c *ClusterTx) RemoveStoragePoolVolume(ctx context.Context, projectName string, volumeName string, volumeType int, poolID int64) error

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

func (*ClusterTx) RemoveUnreferencedProfiles

func (c *ClusterTx) RemoveUnreferencedProfiles(ctx context.Context) error

RemoveUnreferencedProfiles removes unreferenced profiles.

func (*ClusterTx) RenameImageAlias

func (c *ClusterTx) RenameImageAlias(ctx context.Context, id int, name string) error

RenameImageAlias renames the alias with the given ID.

func (*ClusterTx) RenameInstanceBackup

func (c *ClusterTx) RenameInstanceBackup(ctx context.Context, oldName, newName string) error

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

func (*ClusterTx) RenameNetwork

func (c *ClusterTx) RenameNetwork(ctx context.Context, project string, oldName string, newName string) error

RenameNetwork renames a network.

func (*ClusterTx) RenameNetworkACL

func (c *ClusterTx) RenameNetworkACL(ctx context.Context, id int64, newName string) error

RenameNetworkACL renames a Network ACL.

func (*ClusterTx) RenameNode

func (c *ClusterTx) RenameNode(ctx context.Context, oldName string, newName string) error

RenameNode changes the name of an existing node.

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

func (*ClusterTx) RenameStoragePoolVolume

func (c *ClusterTx) RenameStoragePoolVolume(ctx context.Context, projectName string, oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error

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

func (*ClusterTx) RenameVolumeBackup

func (c *ClusterTx) RenameVolumeBackup(ctx context.Context, oldName, newName string) error

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

func (*ClusterTx) SetDescription

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

SetDescription changes the description of the given node.

func (*ClusterTx) SetImageCachedAndLastUseDate

func (c *ClusterTx) SetImageCachedAndLastUseDate(ctx context.Context, projectName string, fingerprint string, lastUsed time.Time) error

SetImageCachedAndLastUseDate sets the cached and last_use_date field of the image with the given fingerprint.

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

func (c *ClusterTx) Tx() *sql.Tx

Tx retrieves the underlying transaction on the cluster database.

func (*ClusterTx) UnsetImageCached

func (c *ClusterTx) UnsetImageCached(ctx context.Context, projectName string, fingerprint string) error

UnsetImageCached unsets the cached field of the image with the given fingerprint.

func (*ClusterTx) UpdateCephStoragePoolAfterNodeJoin

func (c *ClusterTx) UpdateCephStoragePoolAfterNodeJoin(ctx context.Context, poolID int64, nodeID int64) error

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

func (*ClusterTx) UpdateClusterConfig

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

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

func (*ClusterTx) UpdateImage

func (c *ClusterTx) UpdateImage(ctx context.Context, 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 (*ClusterTx) UpdateImageAlias

func (c *ClusterTx) UpdateImageAlias(ctx context.Context, aliasID int, imageID int, desc string) error

UpdateImageAlias updates the alias with the given ID.

func (*ClusterTx) UpdateImageLastUseDate

func (c *ClusterTx) UpdateImageLastUseDate(ctx context.Context, projectName string, fingerprint string, lastUsed time.Time) error

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

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(ctx context.Context, project string, oldName string, newName string, newMemberName string, poolID int64, volumeType int) error

UpdateInstanceNode changes the name of an instance and the cluster member hosting it. 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 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) UpdateInstanceSnapshotCreationDate

func (c *ClusterTx) UpdateInstanceSnapshotCreationDate(ctx context.Context, instanceID int, date time.Time) error

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

func (*ClusterTx) UpdateInstanceStatefulFlag

func (c *ClusterTx) UpdateInstanceStatefulFlag(ctx context.Context, id int, stateful bool) error

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

func (*ClusterTx) UpdateNetwork

func (c *ClusterTx) UpdateNetwork(ctx context.Context, project string, name, description string, config map[string]string) error

UpdateNetwork updates the network with the given name.

func (*ClusterTx) UpdateNetworkACL

func (c *ClusterTx) UpdateNetworkACL(ctx context.Context, id int64, config api.NetworkACLPut) error

UpdateNetworkACL updates the Network ACL with the given ID.

func (*ClusterTx) UpdateNetworkForward

func (c *ClusterTx) UpdateNetworkForward(ctx context.Context, networkID int64, forwardID int64, info api.NetworkForwardPut) error

UpdateNetworkForward updates an existing Network Forward.

func (*ClusterTx) UpdateNetworkLoadBalancer

func (c *ClusterTx) UpdateNetworkLoadBalancer(ctx context.Context, networkID int64, loadBalancerID int64, info api.NetworkLoadBalancerPut) error

UpdateNetworkLoadBalancer updates an existing Network Load Balancer.

func (*ClusterTx) UpdateNetworkPeer

func (c *ClusterTx) UpdateNetworkPeer(ctx context.Context, networkID int64, peerID int64, info api.NetworkPeerPut) error

UpdateNetworkPeer updates an existing Network Peer.

func (*ClusterTx) UpdateNetworkZoneRecord

func (c *ClusterTx) UpdateNetworkZoneRecord(ctx context.Context, id int64, config api.NetworkZoneRecordPut) error

UpdateNetworkZoneRecord updates the network zone record with the given ID.

func (*ClusterTx) UpdateNodeClusterGroups

func (c *ClusterTx) UpdateNodeClusterGroups(ctx context.Context, id int64, groups []string) error

UpdateNodeClusterGroups changes the list of cluster groups the member belongs to.

func (*ClusterTx) UpdateNodeConfig

func (c *ClusterTx) UpdateNodeConfig(ctx context.Context, id int64, config map[string]string) error

UpdateNodeConfig updates the replaces the node's config with the specified config.

func (*ClusterTx) UpdateNodeFailureDomain

func (c *ClusterTx) UpdateNodeFailureDomain(ctx context.Context, 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) UpdateNodeStatus

func (c *ClusterTx) UpdateNodeStatus(id int64, state int) error

UpdateNodeStatus changes the state of a node.

func (*ClusterTx) UpdateStoragePool

func (c *ClusterTx) UpdateStoragePool(ctx context.Context, poolName, description string, poolConfig map[string]string) error

UpdateStoragePool updates a storage pool.

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

func (c *ClusterTx) UpdateStoragePoolBucket(ctx context.Context, poolID int64, bucketID int64, info api.StorageBucketPut) error

UpdateStoragePoolBucket updates an existing Storage Bucket.

func (*ClusterTx) UpdateStoragePoolBucketKey

func (c *ClusterTx) UpdateStoragePoolBucketKey(ctx context.Context, bucketID int64, bucketKeyID int64, info api.StorageBucketKeyPut) error

UpdateStoragePoolBucketKey updates an existing Storage Bucket Key.

func (*ClusterTx) UpdateStoragePoolVolume

func (c *ClusterTx) UpdateStoragePoolVolume(ctx context.Context, projectName string, 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 (*ClusterTx) UpdateStorageVolumeNode

func (c *ClusterTx) UpdateStorageVolumeNode(ctx context.Context, projectName string, oldName string, newName string, newMemberName string, poolID int64, volumeType int) error

UpdateStorageVolumeNode changes the name of a storage volume and the cluster member hosting it. It's meant to be used when moving a storage volume backed by ceph from one cluster node to another.

func (*ClusterTx) UpdateStorageVolumeSnapshot

func (c *ClusterTx) UpdateStorageVolumeSnapshot(ctx context.Context, projectName string, 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 (*ClusterTx) UpdateWarningState

func (c *ClusterTx) UpdateWarningState(UUID string, message string, status warningtype.Status) error

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

func (*ClusterTx) UpdateWarningStatus

func (c *ClusterTx) UpdateWarningStatus(UUID string, status warningtype.Status) error

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

func (*ClusterTx) UpsertWarning

func (c *ClusterTx) UpsertWarning(ctx context.Context, nodeName string, projectName string, entityType entity.Type, entityID int, typeCode warningtype.Type, message string) error

UpsertWarning creates or updates a warning.

func (*ClusterTx) UpsertWarningLocalNode

func (c *ClusterTx) UpsertWarningLocalNode(ctx context.Context, projectName string, entityType entity.Type, entityID int, typeCode warningtype.Type, message string) error

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

type DB

type DB struct {
	Node    *Node
	Cluster *Cluster
}

DB represents access to LXD's global and local databases.

func (*DB) GetProject

func (db *DB) GetProject(ctx context.Context, projectName string) (*cluster.Project, error)

GetProject returns the project with the given key.

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][][]any
}

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

func LoadPreClusteringData

func LoadPreClusteringData(ctx context.Context, 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 Instance

type Instance struct {
	ID       int64
	Name     string
	Project  string
	Location string
	Type     instancetype.Type
}

Instance represents basic instance info.

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     []api.Profile
	Stateful     bool
	ExpiryDate   time.Time
}

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

func (*InstanceArgs) ToAPI

func (i *InstanceArgs) ToAPI() (*api.Instance, error)

ToAPI converts InstanceArgs to api.Instance. The returned Instance has ExpandedConfig and ExpandedDevices set.

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 NetworkNode

type NetworkNode struct {
	ID    int64
	Name  string
	State NetworkState
}

NetworkNode represents a network node.

type NetworkPeer

type NetworkPeer struct {
	NetworkName string
	PeerName    string
}

NetworkPeer represents a peer connection.

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 DirectAccess

func DirectAccess(db *sql.DB) *Node

DirectAccess is a bit of a hack which allows getting a database Node struct from any standard Go sql.DB. This is primarily used to access the "db.bin" read-only copy of the database during startup.

func NewTestNode

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

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

func OpenNode

func OpenNode(dir string, fresh func(*Node) error) (*Node, error)

OpenNode creates a new Node object.

The fresh hook parameter is used by the daemon to mark all known patch names as applied when a brand new database is created.

Return the newly created Node object.

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

func (n *Node) DqliteDir() string

DqliteDir returns the global database directory used by dqlite.

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(ctx context.Context, f func(context.Context, *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         []ClusterRole     // List of cluster roles
	Architecture  int               // Node architecture
	State         int               // Node state
	Config        map[string]string // Configuration for the node
	Groups        []string          // Cluster groups
}

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(ctx context.Context, tx *ClusterTx, args NodeInfoArgs) (*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 NodeInfoArgs

type NodeInfoArgs struct {
	LeaderAddress        string
	FailureDomains       map[uint64]string
	MemberFailureDomains map[string]uint64
	OfflineThreshold     time.Duration
	MaxMemberVersion     [2]int
	RaftNodes            []RaftNode
}

NodeInfoArgs provides information about the cluster environment for use with NodeInfo.ToAPI().

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(ctx context.Context) (map[string]string, error)

Config fetches all LXD node-level config keys.

func (*NodeTx) CreateFirstRaftNode

func (n *NodeTx) CreateFirstRaftNode(address string, name 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, name 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(ctx context.Context) ([]cluster.Certificate, error)

GetCertificates returns all available local certificates.

func (*NodeTx) GetRaftNodeAddress

func (n *NodeTx) GetRaftNodeAddress(ctx context.Context, 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(ctx context.Context) ([]string, error)

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

func (*NodeTx) GetRaftNodes

func (n *NodeTx) GetRaftNodes(ctx context.Context) ([]RaftNode, error)

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

func (*NodeTx) RemoveRaftNode

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

RemoveRaftNode 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 []cluster.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) 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 ProjectArgs

type ProjectArgs struct {
	Profiles  []api.Profile
	Instances []api.Instance
}

ProjectArgs is all the instances and profiles associated with a project. If Project.Config["features.profiles"] is false, Profiles is the default project's profiles.

type RaftNode

type RaftNode struct {
	client.NodeInfo
	Name string `yaml:"name"`
}

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 StorageBucket

type StorageBucket struct {
	api.StorageBucket

	ID       int64
	Project  string
	PoolID   int64
	PoolName string
}

StorageBucket represents a database storage bucket record.

type StorageBucketFilter

type StorageBucketFilter struct {
	PoolID   *int64
	PoolName *string
	Project  *string
	Name     *string
}

StorageBucketFilter used for filtering storage buckets with GetStorageBuckets().

type StorageBucketKey

type StorageBucketKey struct {
	api.StorageBucketKey

	ID int64
}

StorageBucketKey represents a database storage bucket key record.

type StorageBucketKeyFilter

type StorageBucketKeyFilter struct {
	Name *string
}

StorageBucketKeyFilter used for filtering storage bucket keys with GetStoragePoolBucketKeys().

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.

const (
	StoragePoolPending StoragePoolState = iota // Storage pool defined but not yet created globally or on specific node.
	StoragePoolCreated                         // Storage pool created globally or on specific node.

)

Storage pools state.

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 StorageVolume

type StorageVolume struct {
	api.StorageVolume

	ID int64
}

StorageVolume represents a database storage volume record.

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 StorageVolumeFilter

type StorageVolumeFilter struct {
	Type    *int
	Project *string
	Name    *string
	PoolID  *int64
}

StorageVolumeFilter used for filtering storage volumes with GetStorageVolumes().

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