Defines interface for DB access.
Functions in this module are imported into the cinder.db namespace. Call these functions from cinder.db namespace, not the cinder.db.api namespace.
All functions in this module return objects that implement a dictionary-like interface. Currently, many of these objects are sqlalchemy objects that implement a dictionary interface. However, a future goal is to have all of these objects be simple dictionaries.
Related Flags
connection: | string specifying the sqlalchemy connection to use, like: sqlite:///var/lib/cinder/cinder.sqlite. |
---|---|
enable_new_services: | |
when adding a new service to the database, is it in the pool of available hardware (Default: True) |
Bases: object
Class for conditional value selection for conditional_update.
Bases: object
Class for normal condition values for conditional_update.
Bases: cinder.db.api.Condition
Class for negated condition values for conditional_update.
By default NULL values will be treated like Python treats None instead of how SQL treats it.
So for example when values are (1, 2) it will evaluate to True when we have value 3 or NULL, instead of only with 3 like SQL does.
Create a backup from the values dictionary.
Destroy the backup or raise if it does not exist.
Get a backup or raise if it does not exist.
Get all backups.
Get all backups belonging to a host.
Get all backups belonging to a project.
Get all backups belonging to a volume.
Set the given properties on a backup and update it.
Raises NotFound if backup does not exist.
Return a filter to check if a CG is being used as creation source.
Returned filter is meant to be used in the Conditional Update mechanism and checks if provided CG ID or CG Snapshot ID is currently being used to create another CG.
This filter will not include CGs that have used the ID but have already finished their creation (status is no longer creating).
Filter uses a subquery that allows it to be used on updates to the consistencygroups table.
Return a filter that checks if a CG has CG Snapshots.
Return a filter to check if a CG has volumes.
When attached_or_with_snapshots parameter is given a True value only attached volumes or those with snapshots will be considered.
Create a cgsnapshot from the values dictionary.
Get a filter that checks if a CGSnapshot is being created from a CG.
Destroy the cgsnapshot or raise if it does not exist.
Get a cgsnapshot or raise if it does not exist.
Get all cgsnapshots.
Get all cgsnapshots belonging to a consistency group.
Get all cgsnapshots belonging to a project.
Set the given properties on a cgsnapshot and update it.
Raises NotFound if cgsnapshot does not exist.
Create a cluster from the values dictionary.
Destroy the cluster or raise if it does not exist or has hosts.
Raises ClusterNotFound: | |
---|---|
If cluster doesn’t exist. |
Get a cluster that matches the criteria.
Parameters: |
|
---|---|
Raises ClusterNotFound: | |
If cluster doesn’t exist. |
Get all clusters that match the criteria.
Parameters: |
|
---|
Set the given properties on an cluster and update it.
Raises ClusterNotFound if cluster does not exist.
Compare-and-swap conditional update.
Update will only occur in the DB if conditions are met.
Method accepts additional filters, which are basically anything that can be passed to a sqlalchemy query’s filter method, for example:
[~sql.exists().where(models.Volume.id == models.Snapshot.volume_id)]
We can select values based on conditions using Case objects in the ‘values’ argument. For example:
has_snapshot_filter = sql.exists().where(
models.Snapshot.volume_id == models.Volume.id)
case_values = db.Case([(has_snapshot_filter, 'has-snapshot')],
else_='no-snapshot')
db.conditional_update(context, models.Volume, {'status': case_values},
{'status': 'available'})
And we can use DB fields for example to store previous status in the corresponding field even though we don’t know which value is in the db from those we allowed:
db.conditional_update(context, models.Volume,
{'status': 'deleting',
'previous_status': models.Volume.status},
{'status': ('available', 'error')})
Parameters: |
|
---|
:returns number of db rows that were updated.
Create a consistencygroup from the values dictionary.
Destroy the consistencygroup or raise if it does not exist.
Get a consistencygroup or raise if it does not exist.
Get all consistencygroups.
Get all consistencygroups belonging to a project.
Include all consistency groups matching the filters into a cluster.
When partial_rename is set we will not set the cluster_name with cluster parameter value directly, we’ll replace provided cluster_name or host filter value with cluster instead.
This is useful when we want to replace just the cluster name but leave the backend and pool information as it is. If we are using cluster_name to filter, we’ll use that same DB field to replace the cluster value and leave the rest as it is. Likewise if we use the host to filter.
Returns the number of consistency groups that have been changed.
Set the given properties on a consistencygroup and update it.
Raises NotFound if consistencygroup does not exist.
Force the engine to establish new connections.
Query for an DriverInitiatorData that has the specified key
Updates DriverInitiatorData entry.
Sets the value for the specified key within the namespace.
If the entry already exists return False, if it inserted successfully return True.
Get all volume summary.
Get all volume summary belonging to a project.
Create a group from the values dictionary.
Return a filter to check if a Group is being used as creation source.
Returned filter is meant to be used in the Conditional Update mechanism and checks if provided Group ID or Group Snapshot ID is currently being used to create another Group.
This filter will not include Groups that have used the ID but have already finished their creation (status is no longer creating).
Filter uses a subquery that allows it to be used on updates to the groups table.
Destroy the group or raise if it does not exist.
Get a group or raise if it does not exist.
Get all groups.
Get all groups belonging to a project.
Return a filter that checks if a Group has Group Snapshots.
Return a filter to check if a Group has volumes.
When attached_or_with_snapshots parameter is given a True value only attached volumes or those with snapshots will be considered.
Create a group snapshot from the values dictionary.
Get a filter to check if a grp snapshot is being created from a grp.
Destroy the group snapshot or raise if it does not exist.
Get a group snapshot or raise if it does not exist.
Get all group snapshots.
Get all group snapshots belonging to a group.
Get all group snapshots belonging to a project.
Set the given properties on a group snapshot and update it.
Raises NotFound if group snapshot does not exist.
Add group type access for project.
Get all group type access of a group type.
Remove group type access for project.
Create a new group type.
Delete a group type.
Get group type by id.
Parameters: |
|
---|---|
Returns: | group type |
Get all group types.
Parameters: |
|
||
---|---|---|---|
Returns: | list/dict of matching group types |
Get group type by name.
Delete the given group specs item.
Get all group specs for a group type.
Create or update group type specs.
This adds or modifies the key/value pairs specified in the group specs dict argument.
Get group types by name or id.
Set the given properties on a group and update it.
Raises NotFound if group does not exist.
Create a group volume_type mapping entry.
Create a new image volume cache entry.
Delete an image volume cache entry specified by volume id.
Query for all image volume cache entry for a host.
Query for an image volume cache entry.
Query to see if a volume id is an image-volume contained in the cache
Check if object is an ORM field.
Creates a new message with the specified values.
Deletes message with the specified ID.
Return a message with the specified ID.
Purge deleted rows older than given age from cinder tables
Raises InvalidParameterValue if age_in_days is incorrect. :returns: number of deleted rows
Associate qos_specs from volume type.
Get all associated volume types for a given qos_specs.
Create a qos_specs.
Delete the qos_specs.
Disassociate qos_specs from volume type.
Disassociate qos_specs from all entities.
Get all specification for a given qos_specs.
Get all qos_specs.
Get all specification for a given qos_specs.
Delete specified key in the qos_specs.
Update qos specs.
This adds or modifies the key/value pairs specified in the specs dict argument for a given qos_specs.
Retrieve all allocated quotas associated with a given project.
Update allocated quota to subprojects or raise if it does not exist.
Raises: | cinder.exception.ProjectQuotaNotFound |
---|
Create a quota class for the given name and resource.
Destroy the quota class or raise if it does not exist.
Destroy all quotas associated with a given quota class.
Retrieve a quota class or raise if it does not exist.
Retrieve all quotas associated with a given quota class.
Retrieve all default quotas.
Update a quota class or raise if it does not exist.
Update resource name in quota_class.
Create a quota for the given project and resource.
Destroy the quota or raise if it does not exist.
Destroy all quotas associated with a given project.
Retrieve a quota or raise if it does not exist.
Retrieve all quotas associated with a given project.
Check quotas and create appropriate reservations.
Update a quota or raise if it does not exist.
Update resource of quotas.
Retrieve a quota usage or raise if it does not exist.
Retrieve all usage associated with a given resource.
Update resource field in quota_usages.
Commit quota reservations.
Roll back any expired reservations.
Roll back quota reservations.
Create a service from the values dictionary.
Destroy the service or raise if it does not exist.
Get a service that matches the criteria.
A possible filter is is_up=True and it will filter nodes that are down.
Parameters: |
|
---|---|
Raises ServiceNotFound: | |
If service doesn’t exist. |
Get all services that match the criteria.
A possible filter is is_up=True and it will filter nodes that are down.
Parameters: |
|
---|
Set the given properties on an service and update it.
Raises NotFound if service does not exist.
Create a snapshot from the values dictionary.
Get count and gigabytes used for snapshots for specified project.
Destroy the snapshot or raise if it does not exist.
Get a snapshot or raise if it does not exist.
Get all the snapshots inside the window.
Specifying a project_id will filter for a certain project.
Get all snapshots.
Get all snapshots belonging to a project.
Get all snapshots belonging to a cgsnapshot.
Get all snapshots belonging to a group snapshot.
Get all snapshots for a volume.
Get all snapshots belonging to a host.
Parameters: |
|
---|
Delete the given metadata item.
Get all metadata for a snapshot.
Update metadata if it exists, otherwise create it.
Set the given properties on an snapshot and update it.
Raises NotFound if snapshot does not exist.
Accept a volume transfer.
Create an entry in the transfers table.
Destroy a record in the volume transfer table.
Get a volume transfer record or raise if it does not exist.
Get all volume transfer records.
Get all volume transfer records for specified project.
Delete the given metadata item.
Get all administration metadata for a volume.
Update metadata if it exists, otherwise create it.
Attach a volume.
Ensure that a volume is set as attached.
Create a volume from the values dictionary.
Get (volume_count, gigabytes) for project.
Get (volume_count, gigabytes) for project.
Destroy the volume or raise if it does not exist.
Ensure that a volume is set as detached.
Get a volume or raise if it does not exist.
Get all the volumes inside the window.
Specifying a project_id will filter for a certain project.
Get all volumes.
Get all volumes belonging to a generic volume group.
Get all volumes belonging to a consistency group.
Get all volumes belonging to a host.
Get all volumes belonging to a project.
Add Glance metadata for specified volume (multiple pairs).
Update the Glance metadata for a volume.
Update the Glance metadata for a volume by copying all of the key:value pairs from the originating volume.
This is so that a volume created from the volume (clone) will retain the original metadata.
Update the Glance metadata for a snapshot.
This will copy all of the key:value pairs from the originating volume, to ensure that a volume created from the snapshot will retain the original metadata.
Update the Glance metadata from a volume (created from a snapshot).
This will copy all of the key:value pairs from the originating snapshot, to ensure that the Glance metadata from the original volume is retained.
Update the Glance metadata for the specified volume.
Delete the glance metadata for a snapshot.
Delete the glance metadata for a volume.
Return the glance metadata for a volume.
Return the glance metadata for all volumes.
Return the glance metadata for a volume list.
Include all volumes matching the filters into a cluster.
When partial_rename is set we will not set the cluster_name with cluster parameter value directly, we’ll replace provided cluster_name or host filter value with cluster instead.
This is useful when we want to replace just the cluster name but leave the backend and pool information as it is. If we are using cluster_name to filter, we’ll use that same DB field to replace the cluster value and leave the rest as it is. Likewise if we use the host to filter.
Returns the number of volumes that have been changed.
Delete the given metadata item.
Get all metadata for a volume.
Update metadata if it exists, otherwise create it.
Return the Glance metadata for the specified snapshot.
Add volume type access for project.
Get all volume type access of a volume type.
Remove volume type access for project.
Create a new volume type.
Delete a volume type.
Delete the given extra specs item.
Get all extra specs for a volume type.
Create or update volume type extra specs.
This adds or modifies the key/value pairs specified in the extra specs dict argument.
Get volume type by id.
Parameters: |
|
---|---|
Returns: | volume type |
Get all volume types.
Parameters: |
|
||
---|---|---|---|
Returns: | list/dict of matching volume types |
Get all volumes in a group.
Get volume type by name.
Associate a volume type with specific qos specs.
Get volume types that are associated with specific qos specs.
Disassociate a volume type from specific qos specs.
Disassociate all volume types from specific qos specs.
Get all qos specs for given volume type.
Get volume types by name or id.
Set the given properties on a volume and update it.
Raises NotFound if volume does not exist.
Update volume status according to attached instance id
Set the given properties on a list of volumes and update them.
Raises NotFound if a volume does not exist.
Soft delete a worker, change the service_id and update the worker.
Create a worker entry from optional arguments.
Delete a worker (no soft delete).
Get a worker or raise exception if it does not exist.
Get all workers that match given criteria.
Update a worker with given values.
Implementation of SQLAlchemy backend.
SQLAlchemy models for cinder data.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a backup of a volume to Swift.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a cgsnapshot.
Bases: oslo_db.sqlalchemy.models.TimestampMixin, oslo_db.sqlalchemy.models.ModelBase
Base class for Cinder Models.
Delete this object.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a cluster of hosts.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a consistencygroup.
Bases: sqlalchemy.ext.declarative.api.Base, oslo_db.sqlalchemy.models.TimestampMixin, oslo_db.sqlalchemy.models.ModelBase
Represents private key-value pair specific an initiator for drivers
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents encryption requirement for a volume type.
Encryption here is a set of performance characteristics describing cipher, provider, and key_size for a certain volume type.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a generic volume group.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a group snapshot.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represent projects associated group_types.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents additional specs as key/value pairs for a group_type.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represent possible group_types of groups offered.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represent mapping between groups and volume_types.
Bases: sqlalchemy.ext.declarative.api.Base, oslo_db.sqlalchemy.models.ModelBase
Represents an image volume cache entry
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a message
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents QoS specs as key/value pairs.
QoS specs is standalone entity that can be associated/disassociated with volume types (one to many relation). Adjacency list relationship pattern is used in this model in order to represent following hierarchical data with in flat table, e.g, following structure:
qos-specs-1 'Rate-Limit'
|
+------> consumer = 'front-end'
+------> total_bytes_sec = 1048576
+------> total_iops_sec = 500
qos-specs-2 'QoS_Level1'
|
+------> consumer = 'back-end'
+------> max-iops = 1000
+------> min-iops = 200
is represented by:
id specs_id key value
------ -------- ------------- -----
UUID-1 NULL QoSSpec_Name Rate-Limit
UUID-2 UUID-1 consumer front-end
UUID-3 UUID-1 total_bytes_sec 1048576
UUID-4 UUID-1 total_iops_sec 500
UUID-5 NULL QoSSpec_Name QoS_Level1
UUID-6 UUID-5 consumer back-end
UUID-7 UUID-5 max-iops 1000
UUID-8 UUID-5 min-iops 200
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a single quota override for a project.
If there is no row for a given project id and resource, then the default for the quota class is used. If there is no row for a given quota class and resource, then the default for the deployment is used. If the row is present but the hard limit is Null, then the resource is unlimited.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a single quota override for a quota class.
If there is no row for a given quota class and resource, then the default for the deployment is used. If the row is present but the hard limit is Null, then the resource is unlimited.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents the current usage for a given resource.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a resource reservation for quotas.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a running service on a host.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a snapshot of volume.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a metadata key/value pair for a snapshot.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a volume transfer request.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a block storage device that can be attached to a vm.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents an administrator metadata key/value pair for a volume.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a volume attachment for a vm.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Glance metadata for a bootable volume.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents a metadata key/value pair for a volume.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents additional specs as key/value pairs for a volume_type.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represent projects associated volume_types.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represent possible volume_types of volumes offered.
Bases: sqlalchemy.ext.declarative.api.Base, cinder.db.sqlalchemy.models.CinderBase
Represents all resources that are being worked on by a node.
Tests are lacking for the db api layer and for the sqlalchemy driver. Failures in the drivers would be detected in other test cases, though.