db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: Apache-2.0 Imports: 37 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 (
	StoragePoolVolumeTypeContainer = iota
	StoragePoolVolumeTypeImage
	StoragePoolVolumeTypeCustom
	StoragePoolVolumeTypeVM
)

XXX: this was extracted from 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
	StoragePoolVolumeContentTypeISO
)

Content types.

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

Content type names.

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

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

	// ErrNoClusterMember is used to indicate no cluster member has been found for a resource.
	ErrNoClusterMember = fmt.Errorf("No cluster member found")
)

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 Incus-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: "incus",
	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 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.

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(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 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 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 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, 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 database directory (e.g. /var/lib/incus/database) - timeout: Give up trying to open the database after this amount of time.

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

func (c *Cluster) AddImageToLocalNode(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 (*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) CreateImage

func (c *Cluster) CreateImage(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 (*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) CreateNetworkForward

func (c *Cluster) CreateNetworkForward(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 (*Cluster) CreateNetworkLoadBalancer

func (c *Cluster) CreateNetworkLoadBalancer(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 (*Cluster) CreateNetworkPeer

func (c *Cluster) CreateNetworkPeer(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 (*Cluster) CreateNetworkZone

func (c *Cluster) CreateNetworkZone(projectName string, info *api.NetworkZonesPost) (int64, error)

CreateNetworkZone creates a new Network zone.

func (*Cluster) CreateNetworkZoneRecord

func (c *Cluster) CreateNetworkZoneRecord(zone int64, info api.NetworkZoneRecordsPost) (int64, error)

CreateNetworkZoneRecord creates a new network zone record.

func (*Cluster) CreateStoragePool

func (c *Cluster) CreateStoragePool(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 (*Cluster) CreateStoragePoolBucket

func (c *Cluster) 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 (*Cluster) CreateStoragePoolBucketKey

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

CreateStoragePoolBucketKey creates a new Storage Bucket Key.

func (*Cluster) CreateStoragePoolVolume

func (c *Cluster) CreateStoragePoolVolume(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 (*Cluster) CreateStoragePoolVolumeBackup

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

CreateStoragePoolVolumeBackup creates a new storage volume backup.

func (*Cluster) CreateStorageVolumeSnapshot

func (c *Cluster) CreateStorageVolumeSnapshot(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 (*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) DeleteImage

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

DeleteImage deletes the image with the given ID.

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

func (c *Cluster) DeleteNetworkForward(networkID int64, forwardID int64) error

DeleteNetworkForward deletes an existing Network Forward.

func (*Cluster) DeleteNetworkLoadBalancer

func (c *Cluster) DeleteNetworkLoadBalancer(networkID int64, loadBalancerID int64) error

DeleteNetworkLoadBalancer deletes an existing Network Load Balancer.

func (*Cluster) DeleteNetworkPeer

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

DeleteNetworkPeer deletes an existing Network Peer.

func (*Cluster) DeleteNetworkZone

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

DeleteNetworkZone deletes the Network zone.

func (*Cluster) DeleteNetworkZoneRecord

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

DeleteNetworkZoneRecord deletes the network zone record.

func (*Cluster) DeleteReadyStateFromLocalInstances

func (c *Cluster) DeleteReadyStateFromLocalInstances() error

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

func (*Cluster) DeleteStoragePoolBucket

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

DeleteStoragePoolBucket deletes an existing Storage Bucket.

func (*Cluster) DeleteStoragePoolBucketKey

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

DeleteStoragePoolBucketKey deletes an existing Storage Bucket Key.

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(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) 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) GetExpiredInstanceBackups

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

GetExpiredInstanceBackups returns a list of expired instance backups.

func (*Cluster) GetImage

func (c *Cluster) GetImage(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 (*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) GetImagesOnLocalNode

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

GetImagesOnLocalNode returns all images that the local server holds.

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. Returns snapshots slice ordered by when they were created, oldest first.

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) 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 member. Returns snapshots slice ordered by when they were created, oldest first.

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

func (c *Cluster) 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 (*Cluster) GetNetworkForwardListenAddresses

func (c *Cluster) GetNetworkForwardListenAddresses(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 (*Cluster) GetNetworkForwards

func (c *Cluster) 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 (*Cluster) GetNetworkInAnyState

func (c *Cluster) GetNetworkInAnyState(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 (*Cluster) GetNetworkLoadBalancer

func (c *Cluster) 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 (*Cluster) GetNetworkLoadBalancerListenAddresses

func (c *Cluster) GetNetworkLoadBalancerListenAddresses(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 (*Cluster) GetNetworkLoadBalancers

func (c *Cluster) 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 (*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) GetNetworkPeer

func (c *Cluster) GetNetworkPeer(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 (*Cluster) GetNetworkPeerNames

func (c *Cluster) GetNetworkPeerNames(networkID int64) (map[int64]string, error)

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

func (*Cluster) GetNetworkPeers

func (c *Cluster) GetNetworkPeers(networkID int64) (map[int64]*api.NetworkPeer, error)

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

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

func (c *Cluster) GetNetworkZone(name string) (int64, string, *api.NetworkZone, error)

GetNetworkZone returns the Network zone with the given name.

func (*Cluster) GetNetworkZoneByProject

func (c *Cluster) GetNetworkZoneByProject(projectName string, name string) (int64, *api.NetworkZone, error)

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

func (*Cluster) GetNetworkZoneKeys

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

GetNetworkZoneKeys returns a map of key names to keys.

func (*Cluster) GetNetworkZoneRecord

func (c *Cluster) GetNetworkZoneRecord(zone int64, name string) (int64, *api.NetworkZoneRecord, error)

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

func (*Cluster) GetNetworkZoneRecordNames

func (c *Cluster) GetNetworkZoneRecordNames(zone int64) ([]string, error)

GetNetworkZoneRecordNames returns the names of existing Network zone records.

func (*Cluster) GetNetworkZonesByProject

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

GetNetworkZonesByProject returns the names of existing Network zones.

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) 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(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 (*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) 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) GetStoragePools

func (c *Cluster) 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 (*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) 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) InstanceList

func (c *Cluster) 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 (*Cluster) IsRemoteStorage

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

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

func (*Cluster) LocalNodeIsEvacuated

func (c *Cluster) LocalNodeIsEvacuated() bool

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

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

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

RemoveStoragePool deletes storage pool.

func (*Cluster) RemoveStoragePoolVolume

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

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

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(projectName string, 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) SetImageCachedAndLastUseDate

func (c *Cluster) SetImageCachedAndLastUseDate(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 (*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) 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) 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) UpdateNetworkForward

func (c *Cluster) UpdateNetworkForward(networkID int64, forwardID int64, info *api.NetworkForwardPut) error

UpdateNetworkForward updates an existing Network Forward.

func (*Cluster) UpdateNetworkLoadBalancer

func (c *Cluster) UpdateNetworkLoadBalancer(networkID int64, loadBalancerID int64, info *api.NetworkLoadBalancerPut) error

UpdateNetworkLoadBalancer updates an existing Network Load Balancer.

func (*Cluster) UpdateNetworkPeer

func (c *Cluster) UpdateNetworkPeer(networkID int64, peerID int64, info *api.NetworkPeerPut) error

UpdateNetworkPeer updates an existing Network Peer.

func (*Cluster) UpdateNetworkZone

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

UpdateNetworkZone updates the Network zone with the given ID.

func (*Cluster) UpdateNetworkZoneRecord

func (c *Cluster) UpdateNetworkZoneRecord(id int64, config api.NetworkZoneRecordPut) error

UpdateNetworkZoneRecord updates the network zone record 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) UpdateStoragePoolBucket

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

UpdateStoragePoolBucket updates an existing Storage Bucket.

func (*Cluster) UpdateStoragePoolBucketKey

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

UpdateStoragePoolBucketKey updates an existing Storage Bucket Key.

func (*Cluster) UpdateStoragePoolVolume

func (c *Cluster) UpdateStoragePoolVolume(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 (*Cluster) UpdateStorageVolumeSnapshot

func (c *Cluster) UpdateStorageVolumeSnapshot(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 (*Cluster) UpsertWarning

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

UpsertWarning creates or updates a warning.

func (*Cluster) UpsertWarningLocalNode

func (c *Cluster) UpsertWarningLocalNode(projectName string, entityTypeCode int, 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 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 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) 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 cluster config keys.

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) 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) 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 members 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) 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) DeleteImageAlias

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

DeleteImageAlias deletes the alias with the given name.

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

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

GetCustomVolumesInProject returns all custom volumes in the given project.

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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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 cluster members that are part of the cluster.

If this server is not clustered, a list with a single member 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 members in the 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) GetNodesWithOperations

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

GetNodesWithOperations returns a list of nodes that have operations.

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 (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) 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) 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) 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) 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) 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) GetStoragePoolVolumeWithID

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

GetStoragePoolVolumeWithID returns the volume with the given ID.

func (*ClusterTx) GetStoragePoolVolumes

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

GetStoragePoolVolumes returns all storage volumes attached to a given storage pool. 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) 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) 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) 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) 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) 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) RenameNode

func (c *ClusterTx) RenameNode(ctx context.Context, old string, 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) 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) Tx

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

Tx retrieves the underlying transaction on the cluster database.

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 cluster configuration keys in the config table. Config keys set to empty values will be deleted.

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

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

UpdateNetwork updates the network 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) 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 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.

type DB

type DB struct {
	Node    *Node
	Cluster *Cluster
}

DB represents access to 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.

func (*DB) UpdateCertificate

func (db *DB) UpdateCertificate(ctx context.Context, fingerprint string, cert cluster.Certificate, projectNames []string) error

UpdateCertificate updates a certificate in the db.

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.

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 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) 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 daemon running the member
	APIExtensions int               // Number of API extensions of the daemon running the member
	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 member 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 an 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 server-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 server-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 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 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 servers that are members of the dqlite Raft cluster (possibly including the local member). If this server 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 cluster members that are members of the dqlite Raft cluster (possibly including the local member). If this server 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 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 server-level configuration keys in the config table. Config keys set to empty values will be deleted.

type RaftNode

type RaftNode struct {
	client.NodeInfo
	Name string
}

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
}

StorageVolumeFilter used for filtering storage volumes with GetStoragePoolVolumes().

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