Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigValueSet(cluster *Cluster, key string, value string) error
- func ContainerConfigClear(tx *sql.Tx, id int) error
- func ContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error
- func ContainerProfilesInsert(tx *sql.Tx, id int, profiles []string) error
- func ContainerUpdate(tx *sql.Tx, id int, description string, architecture int, ephemeral bool) error
- func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error
- func NetworkConfigClear(tx *sql.Tx, networkID, nodeID int64) error
- func NetworkUpdateDescription(tx *sql.Tx, id int64, description string) error
- func OpenNode(dir string, fresh func(*Node) error, legacyPatches map[int]*LegacyPatch) (*Node, *Dump, error)
- func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error
- func ProfileConfigClear(tx *sql.Tx, id int64) error
- func ProfileDescriptionUpdate(tx *sql.Tx, id int64, description string) error
- func StoragePoolConfigClear(tx *sql.Tx, poolID, nodeID int64) error
- func StoragePoolUpdateDescription(tx *sql.Tx, id int64, description string) error
- func StoragePoolVolumeTypeToName(volumeType int) (string, error)
- func StorageVolumeConfigAdd(tx *sql.Tx, volumeID int64, volumeConfig map[string]string) error
- func StorageVolumeConfigClear(tx *sql.Tx, volumeID int64) error
- func StorageVolumeDescriptionUpdate(tx *sql.Tx, volumeID int64, description string) error
- func TxCommit(tx *sql.Tx) error
- func UpdateSchemasDotGo() error
- type CertInfo
- type Cluster
- func (c *Cluster) Begin() (*sql.Tx, error)
- func (c *Cluster) CertDelete(fingerprint string) error
- func (c *Cluster) CertSave(cert *CertInfo) error
- func (c *Cluster) CertUpdate(fingerprint string, certName string, certType int) error
- func (c *Cluster) CertificateGet(fingerprint string) (cert *CertInfo, err error)
- func (c *Cluster) CertificatesGet() (certs []*CertInfo, err error)
- func (c *Cluster) Close() error
- func (c *Cluster) ContainerConfig(containerId int) (map[string]string, error)
- func (c *Cluster) ContainerConfigGet(id int, key string) (string, error)
- func (c *Cluster) ContainerConfigRemove(id int, name string) error
- func (c *Cluster) ContainerCreate(args ContainerArgs) (int, error)
- func (c *Cluster) ContainerGet(name string) (ContainerArgs, error)
- func (c *Cluster) ContainerGetSnapshots(name string) ([]string, error)
- func (c *Cluster) ContainerId(name string) (int, error)
- func (c *Cluster) ContainerLastUsedUpdate(id int, date time.Time) error
- func (c *Cluster) ContainerName(id int) (string, error)
- func (c *Cluster) ContainerNextSnapshot(name string) int
- func (c *Cluster) ContainerPool(containerName string) (string, error)
- func (c *Cluster) ContainerProfiles(containerId int) ([]string, error)
- func (c *Cluster) ContainerRemove(name string) error
- func (c *Cluster) ContainerRename(oldName string, newName string) error
- func (c *Cluster) ContainerSetState(id int, state string) error
- func (c *Cluster) ContainerSetStateful(id int, stateful bool) error
- func (c *Cluster) ContainersList(cType ContainerType) ([]string, error)
- func (c *Cluster) ContainersResetState() error
- func (c *Cluster) DB() *sql.DB
- func (c *Cluster) Devices(qName string, isprofile bool) (types.Devices, error)
- func (c *Cluster) EnterExclusive() error
- func (c *Cluster) ExitExclusive(f func(*ClusterTx) error) error
- func (c *Cluster) ImageAliasAdd(name string, imageID int, desc string) error
- func (c *Cluster) ImageAliasDelete(name string) error
- func (c *Cluster) ImageAliasGet(name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)
- func (c *Cluster) ImageAliasRename(id int, name string) error
- func (c *Cluster) ImageAliasUpdate(id int, imageID int, desc string) error
- func (c *Cluster) ImageAliasesGet() ([]string, error)
- func (c *Cluster) ImageAliasesMove(source int, destination int) error
- func (c *Cluster) ImageAssociateNode(fingerprint string) error
- func (c *Cluster) ImageDelete(id int) error
- func (c *Cluster) ImageExists(fingerprint string) (bool, error)
- func (c *Cluster) ImageGet(fingerprint string, public bool, strictMatching bool) (int, *api.Image, error)
- func (c *Cluster) ImageGetPoolNamesFromIDs(poolIDs []int64) ([]string, error)
- func (c *Cluster) ImageGetPools(imageFingerprint string) ([]int64, error)
- func (c *Cluster) ImageInsert(fp string, fname string, sz int64, public bool, autoUpdate bool, ...) error
- func (c *Cluster) ImageLastAccessInit(fingerprint string) error
- func (c *Cluster) ImageLastAccessUpdate(fingerprint string, date time.Time) error
- func (c *Cluster) ImageLocate(fingerprint string) (string, error)
- func (c *Cluster) ImageSourceGet(imageId int) (int, api.ImageSource, error)
- func (c *Cluster) ImageSourceGetCachedFingerprint(server string, protocol string, alias string) (string, error)
- func (c *Cluster) ImageSourceInsert(imageId int, server string, protocol string, certificate string, alias string) error
- func (c *Cluster) ImageUpdate(id int, fname string, sz int64, public bool, autoUpdate bool, ...) error
- func (c *Cluster) ImageUploadedAt(id int, uploadedAt time.Time) error
- func (c *Cluster) ImagesGet(public bool) ([]string, error)
- func (c *Cluster) ImagesGetExpired(expiry int64) ([]string, error)
- func (c *Cluster) ImportPreClusteringData(dump *Dump) error
- func (c *Cluster) NetworkConfigGet(id int64) (map[string]string, error)
- func (c *Cluster) NetworkCreate(name, description string, config map[string]string) (int64, error)
- func (c *Cluster) NetworkDelete(name string) error
- func (c *Cluster) NetworkGet(name string) (int64, *api.Network, error)
- func (c *Cluster) NetworkGetInterface(devName string) (int64, *api.Network, error)
- func (c *Cluster) NetworkRename(oldName string, newName string) error
- func (c *Cluster) NetworkUpdate(name, description string, config map[string]string) error
- func (c *Cluster) Networks() ([]string, error)
- func (c *Cluster) NetworksNotPending() ([]string, error)
- func (c *Cluster) NodeID(id int64)
- func (c *Cluster) ProfileCleanupLeftover() error
- func (c *Cluster) ProfileConfig(name string) (map[string]string, error)
- func (c *Cluster) ProfileContainersGet(profile string) ([]string, error)
- func (c *Cluster) ProfileCreate(profile string, description string, config map[string]string, ...) (int64, error)
- func (c *Cluster) ProfileCreateDefault() error
- func (c *Cluster) ProfileDelete(name string) error
- func (c *Cluster) ProfileGet(name string) (int64, *api.Profile, error)
- func (c *Cluster) ProfileUpdate(name string, newName string) error
- func (c *Cluster) Profiles() ([]string, error)
- func (c *Cluster) StoragePoolConfigGet(poolID int64) (map[string]string, error)
- func (c *Cluster) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, ...) (int64, error)
- func (c *Cluster) StoragePoolDelete(poolName string) (*api.StoragePool, error)
- func (c *Cluster) StoragePoolGet(poolName string) (int64, *api.StoragePool, error)
- func (c *Cluster) StoragePoolGetID(poolName string) (int64, error)
- func (c *Cluster) StoragePoolInsertZfsDriver() error
- func (c *Cluster) StoragePoolNodeVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error)
- func (c *Cluster) StoragePoolNodeVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error)
- func (c *Cluster) StoragePoolNodeVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)
- func (c *Cluster) StoragePoolNodeVolumesGetType(volumeType int, poolID int64) ([]string, error)
- func (c *Cluster) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error
- func (c *Cluster) StoragePoolVolumeCreate(volumeName, volumeDescription string, volumeType int, poolID int64, ...) (int64, error)
- func (c *Cluster) StoragePoolVolumeDelete(volumeName string, volumeType int, poolID int64) error
- func (c *Cluster) StoragePoolVolumeGetType(volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error)
- func (c *Cluster) StoragePoolVolumeGetTypeID(volumeName string, volumeType int, poolID, nodeID int64) (int64, error)
- func (c *Cluster) StoragePoolVolumeRename(oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error
- func (c *Cluster) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, ...) error
- func (c *Cluster) StoragePoolVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)
- func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) (int, error)
- func (c *Cluster) StoragePoolVolumesGetType(volumeType int, poolID, nodeID int64) ([]string, error)
- func (c *Cluster) StoragePools() ([]string, error)
- func (c *Cluster) StoragePoolsGetDrivers() ([]string, error)
- func (c *Cluster) StoragePoolsNotPending() ([]string, error)
- func (c *Cluster) StorageVolumeCleanupImages(fingerprints []string) error
- func (c *Cluster) StorageVolumeConfigGet(volumeID int64) (map[string]string, error)
- func (c *Cluster) StorageVolumeDescriptionGet(volumeID int64) (string, error)
- func (c *Cluster) StorageVolumeMoveToLVMThinPoolNameKey() error
- func (c *Cluster) StorageVolumeNodeGet(volumeID int64) (string, error)
- func (c *Cluster) Transaction(f func(*ClusterTx) error) error
- type ClusterTx
- func (c *ClusterTx) Config() (map[string]string, error)
- func (c *ClusterTx) ContainerNodeAddress(name string) (string, error)
- func (c *ClusterTx) ContainersByNodeName() (map[string]string, error)
- func (c *ClusterTx) ContainersListByNodeAddress() (map[string][]string, error)
- func (c *ClusterTx) NetworkConfigAdd(networkID, nodeID int64, config map[string]string) error
- func (c *ClusterTx) NetworkConfigs() (map[string]map[string]string, error)
- func (c *ClusterTx) NetworkCreatePending(node, name string, conf map[string]string) error
- func (c *ClusterTx) NetworkCreated(name string) error
- func (c *ClusterTx) NetworkErrored(name string) error
- func (c *ClusterTx) NetworkID(name string) (int64, error)
- func (c *ClusterTx) NetworkIDsNotPending() (map[string]int64, error)
- func (c *ClusterTx) NetworkNodeConfigs(networkID int64) (map[string]map[string]string, error)
- func (c *ClusterTx) NetworkNodeJoin(networkID, nodeID int64) error
- func (c *ClusterTx) NodeAdd(name string, address string) (int64, error)
- func (c *ClusterTx) NodeAddress() (string, error)
- func (c *ClusterTx) NodeByAddress(address string) (NodeInfo, error)
- func (c *ClusterTx) NodeByName(name string) (NodeInfo, error)
- func (c *ClusterTx) NodeClear(id int64) error
- func (c *ClusterTx) NodeHeartbeat(address string, heartbeat time.Time) error
- func (c *ClusterTx) NodeID(id int64)
- func (c *ClusterTx) NodeIsEmpty(id int64) (string, error)
- func (c *ClusterTx) NodeName() (string, error)
- func (c *ClusterTx) NodeOfflineThreshold() (time.Duration, error)
- func (c *ClusterTx) NodePending(id int64, pending bool) error
- func (c *ClusterTx) NodePendingByAddress(address string) (NodeInfo, error)
- func (c *ClusterTx) NodeRemove(id int64) error
- func (c *ClusterTx) NodeRename(old, new string) error
- func (c *ClusterTx) NodeUpdate(id int64, name string, address string) error
- func (c *ClusterTx) Nodes() ([]NodeInfo, error)
- func (c *ClusterTx) NodesCount() (int, error)
- func (c *ClusterTx) OperationAdd(uuid string) (int64, error)
- func (c *ClusterTx) OperationByUUID(uuid string) (Operation, error)
- func (c *ClusterTx) OperationRemove(uuid string) error
- func (c *ClusterTx) OperationsUUIDs() ([]string, error)
- func (c *ClusterTx) StoragePoolConfigAdd(poolID, nodeID int64, config map[string]string) error
- func (c *ClusterTx) StoragePoolConfigs() (map[string]map[string]string, error)
- func (c *ClusterTx) StoragePoolCreatePending(node, name, driver string, conf map[string]string) error
- func (c *ClusterTx) StoragePoolCreated(name string) error
- func (c *ClusterTx) StoragePoolErrored(name string) error
- func (c *ClusterTx) StoragePoolID(name string) (int64, error)
- func (c *ClusterTx) StoragePoolIDsNotPending() (map[string]int64, error)
- func (c *ClusterTx) StoragePoolNodeConfigs(poolID int64) (map[string]map[string]string, error)
- func (c *ClusterTx) StoragePoolNodeJoin(poolID, nodeID int64) error
- func (c *ClusterTx) StorageVolumeNodeAddresses(poolID int64, name string, typ int) ([]string, error)
- func (c *ClusterTx) UpdateConfig(values map[string]string) error
- type ContainerArgs
- type ContainerType
- type Dump
- type LegacyPatch
- type Node
- type NodeInfo
- type NodeTx
- func (n *NodeTx) Config() (map[string]string, error)
- func (n *NodeTx) RaftNodeAdd(address string) (int64, error)
- func (n *NodeTx) RaftNodeAddress(id int64) (string, error)
- func (n *NodeTx) RaftNodeAddresses() ([]string, error)
- func (n *NodeTx) RaftNodeDelete(id int64) error
- func (n *NodeTx) RaftNodeFirst(address string) error
- func (n *NodeTx) RaftNodes() ([]RaftNode, error)
- func (n *NodeTx) RaftNodesReplace(nodes []RaftNode) error
- func (n *NodeTx) Tx() *sql.Tx
- func (n *NodeTx) UpdateConfig(values map[string]string) error
- type Operation
- type RaftNode
Constants ¶
const ( StoragePoolVolumeTypeContainer = iota StoragePoolVolumeTypeImage StoragePoolVolumeTypeCustom )
XXX: this was extracted from lxd/storage_volume_utils.go, we find a way to
factor it independently from both the db and main packages.
const ( StoragePoolVolumeTypeNameContainer string = "container" StoragePoolVolumeTypeNameImage string = "image" StoragePoolVolumeTypeNameCustom string = "custom" )
Leave the string type in here! This guarantees that go treats this is as a typed string constant. Removing it causes go to treat these as untyped string constants which is not what we want.
const DefaultOfflineThreshold = 20
DefaultOfflineThreshold is the default value for the cluster.offline_threshold configuration key, expressed in seconds.
Variables ¶
var ( // DbErrAlreadyDefined hapens when the given entry already exists, // for example a container. DbErrAlreadyDefined = fmt.Errorf("The container/snapshot already exists") /* NoSuchObjectError is in the case of joins (and probably other) queries, * we don't get back sql.ErrNoRows when no rows are returned, even though we do * on selects without joins. Instead, you can use this error to * propagate up and generate proper 404s to the client when something * isn't found so we don't abuse sql.ErrNoRows any more than we * already do. */ NoSuchObjectError = fmt.Errorf("No such object") Upgrading = fmt.Errorf("The cluster database is upgrading") )
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.
var ImageSourceProtocol = map[int]string{
0: "lxd",
1: "direct",
2: "simplestreams",
}
var NetworkNodeConfigKeys = []string{
"bridge.external_interfaces",
}
NetworkNodeConfigKeys lists all network config keys which are node-specific.
var StoragePoolNodeConfigKeys = []string{
"size",
"source",
"volatile.initial_source",
}
StoragePoolNodeConfigKeys lists all storage pool config keys which are node-specific.
Functions ¶
func ContainerConfigInsert ¶
func ContainerProfilesInsert ¶
func ContainerUpdate ¶
func OpenNode ¶
func OpenNode(dir string, fresh func(*Node) error, legacyPatches map[int]*LegacyPatch) (*Node, *Dump, error)
OpenNode creates a new Node object.
The fresh hook parameter is used by the daemon to mark all known patch names as applied when a brand new database is created.
The legacyPatches parameter is used as a mean to apply the legacy V10, V11, V15, V29 and V30 non-db updates during the database upgrade sequence, to avoid any change in semantics wrt the old logic (see PR #3322).
Return the newly created Node object, and a Dump of the pre-clustering data if we've migrating to a cluster-aware version.
func StoragePoolConfigClear ¶
Delete storage pool config.
func StoragePoolUpdateDescription ¶
Update the storage pool description.
func StoragePoolVolumeTypeToName ¶
StoragePoolVolumeTypeToName converts a volume integer type code to its human-readable name.
func StorageVolumeConfigAdd ¶
Add new storage volume config into database.
func StorageVolumeConfigClear ¶
Delete storage volume config.
func StorageVolumeDescriptionUpdate ¶
Update description of a storage volume.
func UpdateSchemasDotGo ¶
func UpdateSchemasDotGo() error
UpdateSchemasDotGo updates the schema.go files in the local/ and cluster/ sub-packages.
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 ¶
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 NewTestCluster ¶
NewTestCluster creates a new Cluster for testing purposes, along with a function that can be used to clean it up when done.
func OpenCluster ¶
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). - api: Number of API extensions that this node supports.
The address and api parameters will be used to determine if the cluster database matches our version, and possibly trigger a schema update. If the schema update can't be performed right now, because some nodes are still behind, an Upgrading error is returned.
func (*Cluster) CertDelete ¶
CertDelete deletes a certificate from the db.
func (*Cluster) CertSave ¶
CertSave stores a CertBaseInfo object in the db, it will ignore the ID field from the CertInfo.
func (*Cluster) CertUpdate ¶
func (*Cluster) CertificateGet ¶
CertificateGet gets an CertBaseInfo object from the database. The argument fingerprint will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.
func (*Cluster) CertificatesGet ¶
CertificatesGet returns all certificates from the DB as CertBaseInfo objects.
func (*Cluster) ContainerConfig ¶
ContainerConfig gets the container configuration map from the DB
func (*Cluster) ContainerConfigGet ¶
func (*Cluster) ContainerConfigRemove ¶
func (*Cluster) ContainerCreate ¶
func (c *Cluster) ContainerCreate(args ContainerArgs) (int, error)
func (*Cluster) ContainerGet ¶
func (c *Cluster) ContainerGet(name string) (ContainerArgs, error)
func (*Cluster) ContainerGetSnapshots ¶
func (*Cluster) ContainerLastUsedUpdate ¶
func (*Cluster) ContainerNextSnapshot ¶
* 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) ContainerPool ¶
Get the storage pool of a given container.
func (*Cluster) ContainerProfiles ¶
Get a list of profiles for a given container id.
func (*Cluster) ContainerRemove ¶
func (*Cluster) ContainerRename ¶
func (*Cluster) ContainerSetStateful ¶
func (*Cluster) ContainersList ¶
func (c *Cluster) ContainersList(cType ContainerType) ([]string, error)
func (*Cluster) ContainersResetState ¶
func (*Cluster) 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) EnterExclusive ¶
EnterExclusive acquires a lock on the cluster db, so any successive call to Transaction will block until ExitExclusive has been called.
func (*Cluster) ExitExclusive ¶
ExitExclusive runs the given transaction and then releases the lock acquired with EnterExclusive.
func (*Cluster) ImageAliasAdd ¶
Insert an alias ento the database.
func (*Cluster) ImageAliasDelete ¶
func (*Cluster) ImageAliasGet ¶
func (*Cluster) ImageAliasUpdate ¶
func (*Cluster) ImageAliasesGet ¶
func (*Cluster) ImageAliasesMove ¶
func (*Cluster) ImageAssociateNode ¶
ImageAssociateNode creates a new entry in the images_nodes table for tracking that the current node has the given image.
func (*Cluster) ImageDelete ¶
func (*Cluster) ImageExists ¶
Whether an image with the given fingerprint exists.
func (*Cluster) ImageGet ¶
func (c *Cluster) ImageGet(fingerprint string, public bool, strictMatching bool) (int, *api.Image, error)
ImageGet gets an Image object from the database. If strictMatching is false, The fingerprint argument will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.
func (*Cluster) ImageGetPoolNamesFromIDs ¶
Get the names of all storage pools on which a given image exists.
func (*Cluster) ImageGetPools ¶
Get the names of all storage pools on which a given image exists.
func (*Cluster) ImageInsert ¶
func (*Cluster) ImageLastAccessInit ¶
func (*Cluster) ImageLastAccessUpdate ¶
func (*Cluster) ImageLocate ¶
ImageLocate 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) ImageSourceGet ¶
func (*Cluster) ImageSourceGetCachedFingerprint ¶
func (c *Cluster) ImageSourceGetCachedFingerprint(server string, protocol string, alias string) (string, error)
Try to find a source entry of a locally cached image that matches the given remote details (server, protocol and alias). Return the fingerprint linked to the matching entry, if any.
func (*Cluster) ImageSourceInsert ¶
func (*Cluster) ImageUpdate ¶
func (*Cluster) ImageUploadedAt ¶
ImageUploadedAt updates the upload_date column and an image row.
func (*Cluster) ImagesGetExpired ¶
func (*Cluster) ImportPreClusteringData ¶
ImportPreClusteringData imports the data loaded with LoadPreClusteringData.
func (*Cluster) NetworkConfigGet ¶
func (*Cluster) NetworkCreate ¶
func (*Cluster) NetworkDelete ¶
func (*Cluster) NetworkGetInterface ¶
func (*Cluster) NetworkRename ¶
func (*Cluster) NetworkUpdate ¶
func (*Cluster) NetworksNotPending ¶
NetworksNotPending returns the names of all networks that are not pending.
func (*Cluster) NodeID ¶
NodeID sets the the node NodeID associated with this cluster instance. It's used for backward-compatibility of all db-related APIs that were written before clustering and don't accept a node NodeID, so in those cases we automatically use this value as implicit node NodeID.
func (*Cluster) ProfileCleanupLeftover ¶
func (*Cluster) ProfileConfig ¶
Get the profile configuration map from the DB
func (*Cluster) ProfileContainersGet ¶
func (*Cluster) ProfileCreate ¶
func (*Cluster) ProfileCreateDefault ¶
func (*Cluster) ProfileDelete ¶
func (*Cluster) StoragePoolConfigGet ¶
Get config of a storage pool.
func (*Cluster) StoragePoolCreate ¶
func (c *Cluster) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error)
Create new storage pool.
func (*Cluster) StoragePoolDelete ¶
func (c *Cluster) StoragePoolDelete(poolName string) (*api.StoragePool, error)
Delete storage pool.
func (*Cluster) StoragePoolGet ¶
Get a single storage pool.
func (*Cluster) StoragePoolGetID ¶
Get id of a single storage pool.
func (*Cluster) StoragePoolInsertZfsDriver ¶
func (*Cluster) StoragePoolNodeVolumeGetType ¶
func (c *Cluster) StoragePoolNodeVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error)
Get a single storage volume attached to a given storage pool of a given type, on the current node.
func (*Cluster) StoragePoolNodeVolumeGetTypeID ¶
func (c *Cluster) StoragePoolNodeVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error)
Get ID of a storage volume on a given storage pool of a given storage volume type, on the current node.
func (*Cluster) StoragePoolNodeVolumesGet ¶
func (c *Cluster) StoragePoolNodeVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)
Get all storage volumes attached to a given storage pool on the current node.
func (*Cluster) StoragePoolNodeVolumesGetType ¶
Get all storage volumes attached to a given storage pool of a given volume type, on the current node.
func (*Cluster) StoragePoolUpdate ¶
func (c *Cluster) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error
Update storage pool.
func (*Cluster) StoragePoolVolumeCreate ¶
func (c *Cluster) StoragePoolVolumeCreate(volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string) (int64, error)
Create new storage volume attached to a given storage pool.
func (*Cluster) StoragePoolVolumeDelete ¶
Delete storage volume attached to a given storage pool.
func (*Cluster) StoragePoolVolumeGetType ¶
func (c *Cluster) StoragePoolVolumeGetType(volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error)
StoragePoolVolumeGetType returns a single storage volume attached to a given storage pool of a given type, on the node with the given ID.
func (*Cluster) StoragePoolVolumeGetTypeID ¶
func (c *Cluster) StoragePoolVolumeGetTypeID(volumeName string, volumeType int, poolID, nodeID int64) (int64, error)
StoragePoolVolumeGetTypeID returns the ID of a storage volume on a given storage pool of a given storage volume type, on the given node.
func (*Cluster) StoragePoolVolumeRename ¶
func (c *Cluster) StoragePoolVolumeRename(oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error
Rename storage volume attached to a given storage pool.
func (*Cluster) StoragePoolVolumeUpdate ¶
func (c *Cluster) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error
Update storage volume attached to a given storage pool.
func (*Cluster) StoragePoolVolumesGet ¶
func (c *Cluster) StoragePoolVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error)
StoragePoolVolumesGet returns all storage volumes attached to a given storage pool on any node.
func (*Cluster) StoragePoolVolumesGetNames ¶
Get the names of all storage volumes attached to a given storage pool.
func (*Cluster) StoragePoolVolumesGetType ¶
StoragePoolVolumesGetType get all storage volumes attached to a given storage pool of a given volume type, on the given node.
func (*Cluster) StoragePools ¶
Get all storage pools.
func (*Cluster) StoragePoolsGetDrivers ¶
Get the names of all storage volumes attached to a given storage pool.
func (*Cluster) StoragePoolsNotPending ¶
StoragePoolsNotPending returns the names of all storage pools that are not pending.
func (*Cluster) StorageVolumeCleanupImages ¶
func (*Cluster) StorageVolumeConfigGet ¶
Get config of a storage volume.
func (*Cluster) StorageVolumeDescriptionGet ¶
Get the description of a storage volume.
func (*Cluster) StorageVolumeMoveToLVMThinPoolNameKey ¶
func (*Cluster) StorageVolumeNodeGet ¶
StorageVolumeNodeGet returns the name of the node a storage volume is on.
func (*Cluster) Transaction ¶
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.
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 ¶
NewTestClusterTx returns a fresh ClusterTx object, along with a function that can be called to cleanup state when done with it.
func (*ClusterTx) ContainerNodeAddress ¶
ContainerNodeAddress returns the address of the node hosting the container with the given name.
It returns the empty string if the container is hosted on this node.
func (*ClusterTx) ContainersByNodeName ¶
ContainersByNodeName returns a map associating each container to the name of its node.
func (*ClusterTx) ContainersListByNodeAddress ¶
ContainersListByNodeAddress returns the names of all containers grouped by cluster node address.
The node address of containers running on the local node is set to the empty string, to distinguish it from remote nodes.
Containers whose node is down are addeded to the special address "0.0.0.0".
func (*ClusterTx) NetworkConfigAdd ¶
NetworkConfigAdd adds a new entry in the networks_config table
func (*ClusterTx) NetworkConfigs ¶
NetworkConfigs returns a map associating each network name to its config values.
func (*ClusterTx) NetworkCreatePending ¶
NetworkCreatePending creates a new pending network on the node with the given name.
func (*ClusterTx) NetworkCreated ¶
NetworkCreated sets the state of the given network to "Created".
func (*ClusterTx) NetworkErrored ¶
NetworkErrored sets the state of the given network to "Errored".
func (*ClusterTx) NetworkIDsNotPending ¶
NetworkIDsNotPending returns a map associating each network name to its ID.
Pending networks are skipped.
func (*ClusterTx) NetworkNodeConfigs ¶
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) NetworkNodeJoin ¶
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) NodeAdd ¶
NodeAdd adds a node to the current list of LXD nodes that are part of the cluster. It returns the ID of the newly inserted row.
func (*ClusterTx) NodeAddress ¶
NodeAddress returns the address of the node this method is invoked on.
func (*ClusterTx) NodeByAddress ¶
NodeByAddress returns the node with the given network address.
func (*ClusterTx) NodeByName ¶
NodeByName returns the node with the given name.
func (*ClusterTx) NodeHeartbeat ¶
NodeHeartbeat updates the heartbeat column of the node with the given address.
func (*ClusterTx) NodeID ¶
NodeID sets the the node NodeID associated with this cluster transaction.
func (*ClusterTx) NodeIsEmpty ¶
NodeIsEmpty returns an empty string if the node with the given ID has no containers or images associated with it. Otherwise, it returns a message say what's left.
func (*ClusterTx) NodeOfflineThreshold ¶
NodeOfflineThreshold 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) NodePending ¶
NodePending 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) NodePendingByAddress ¶
NodePendingByAddress returns the pending node with the given network address.
func (*ClusterTx) NodeRemove ¶
NodeRemove removes the node with the given id.
func (*ClusterTx) NodeRename ¶
NodeRename changes the name of an existing node.
Return an error if a node with the same name already exists.
func (*ClusterTx) NodeUpdate ¶
NodeUpdate updates the name an address of a node.
func (*ClusterTx) Nodes ¶
Nodes 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) NodesCount ¶
NodesCount 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) OperationAdd ¶
OperationAdd adds a new operations to the table.
func (*ClusterTx) OperationByUUID ¶
OperationByUUID returns the operation with the given UUID.
func (*ClusterTx) OperationRemove ¶
OperationRemove removes the operation with the given UUID.
func (*ClusterTx) OperationsUUIDs ¶
OperationsUUIDs returns the UUIDs of all operations associated with this node.
func (*ClusterTx) StoragePoolConfigAdd ¶
StoragePoolConfigAdd adds a new entry in the storage_pools_config table
func (*ClusterTx) StoragePoolConfigs ¶
StoragePoolConfigs returns a map associating each storage pool name to its config values.
The config values are the ones defined for the node this function is run on. They are used by cluster.Join when a new node joins the cluster and its configuration needs to be migrated to the cluster database.
func (*ClusterTx) StoragePoolCreatePending ¶
func (c *ClusterTx) StoragePoolCreatePending(node, name, driver string, conf map[string]string) error
StoragePoolCreatePending creates a new pending storage pool on the node with the given name.
func (*ClusterTx) StoragePoolCreated ¶
StoragePoolCreated sets the state of the given pool to "Created".
func (*ClusterTx) StoragePoolErrored ¶
StoragePoolErrored sets the state of the given pool to "Errored".
func (*ClusterTx) StoragePoolID ¶
StoragePoolID returns the ID of the pool with the given name.
func (*ClusterTx) StoragePoolIDsNotPending ¶
StoragePoolIDsNotPending returns a map associating each storage pool name to its ID.
Pending storage pools are skipped.
func (*ClusterTx) StoragePoolNodeConfigs ¶
StoragePoolNodeConfigs 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) StoragePoolNodeJoin ¶
StoragePoolNodeJoin 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) StorageVolumeNodeAddresses ¶
func (c *ClusterTx) StorageVolumeNodeAddresses(poolID int64, name string, typ int) ([]string, error)
StorageVolumeNodeAddresses returns the addresses of all nodes on which the volume with the given name if defined.
The empty string is used in place of the address of the current node.
type ContainerArgs ¶
type ContainerArgs struct { // Don't set manually Id int Node string Description string Architecture int BaseImage string Config map[string]string CreationDate time.Time LastUsedDate time.Time Ctype ContainerType Devices types.Devices Ephemeral bool Name string Profiles []string Stateful bool }
ContainerArgs is a value object holding all db-related details about a container.
type ContainerType ¶
type ContainerType int
ContainerType encodes the type of container (either regular or snapshot).
const ( CTypeRegular ContainerType = 0 CTypeSnapshot ContainerType = 1 )
type Dump ¶
type Dump struct { // Map table names to the names or their columns. Schema map[string][]string // Map a table name to all the rows it contains. Each row is a slice // of interfaces. Data map[string][][]interface{} }
Dump is a dump of all the user data in lxd.db prior the migration to the cluster db.
func LoadPreClusteringData ¶
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 LegacyPatch ¶
type LegacyPatch struct { NeedsDB bool // Whether the patch does any DB-related work Hook func(*sql.DB) error // The actual patch logic }
LegacyPatch is a "database" update that performs non-database work. They are needed for historical reasons, since there was a time were db updates could do non-db work and depend on functionality external to the db package. See UpdatesApplyAll below.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node mediates access to LXD's data stored in the node-local SQLite database.
func ForLegacyPatches ¶
ForLegacyPatches is a aid for the hack in initializeDbObject, which sets the db-related Deamon attributes upfront, to be backward compatible with the legacy patches that need to interact with the database.
func NewTestNode ¶
NewTestNode creates a new Node for testing purposes, along with a function that can be used to clean it up when done.
func (*Node) 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) PatchesMarkApplied ¶
func (*Node) Transaction ¶
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 }
NodeInfo holds information about a single LXD instance in a cluster.
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 ¶
NewTestNodeTx returns a fresh NodeTx object, along with a function that can be called to cleanup state when done with it.
func (*NodeTx) RaftNodeAdd ¶
RaftNodeAdd 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) RaftNodeAddress ¶
RaftNodeAddress returns the address of the LXD raft node with the given ID, if any matching row exists.
func (*NodeTx) RaftNodeAddresses ¶
RaftNodeAddresses returns the addresses of all LXD nodes that are members of the dqlite Raft cluster (possibly including the local node). If this LXD instance is not running in clustered mode, an empty list is returned.
func (*NodeTx) RaftNodeDelete ¶
RaftNodeDelete removes a node from the current list of LXD nodes that are part of the dqlite Raft cluster.
func (*NodeTx) RaftNodeFirst ¶
RaftNodeFirst adds a the first node if the cluster. It ensures that the database ID is 1, to match the server ID of 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) RaftNodes ¶
RaftNodes returns information about all LXD nodes that are members of the dqlite Raft cluster (possibly including the local node). If this LXD instance is not running in clustered mode, an empty list is returned.
func (*NodeTx) RaftNodesReplace ¶
RaftNodesReplace replaces the current list of raft nodes.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package query implements helpers around database/sql to execute various kinds of very common SQL queries.
|
Package query implements helpers around database/sql to execute various kinds of very common SQL queries. |
Package schema offers utilities to create and maintain a database schema.
|
Package schema offers utilities to create and maintain a database schema. |