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.
Create a cgsnapshot from the values dictionary.
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.
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)
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’)})
WARNING: SQLAlchemy does not allow selecting order of SET clauses, so for now we cannot do things like
{‘previous_status’: model.status, ‘status’: ‘retyping’}
because it will result in both previous_status and status being set to ‘retyping’. Issue has been reported [1] and a patch to fix it [2] has been submitted. [1]: https://bitbucket.org/zzzeek/sqlalchemy/issues/3541/ [2]: https://github.com/zzzeek/sqlalchemy/pull/200
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.
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 DriverPrivateData that has the specified key
Create DriverPrivateData from the values dictionary.
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.
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 or raise if it does not exist.
Get all services.
Get all services for a given binary.
Get all services for a given topic.
Get the state of a service by node name and binary.
Get a service by host it’s on and topic it listens to.
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 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 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.
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 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
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 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, oslo_db.sqlalchemy.models.ModelBase
Represents an image volume cache entry
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
+——> consumer = ‘front-end’ +——> total_bytes_sec = 1048576 +——> total_iops_sec = 500
+——> 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.
Register Models and create metadata.
Called from cinder.db.sqlalchemy.__init__ as part of loading the driver, it will never need to be called explicitly elsewhere unless the connection is lost and needs to be reestablished.
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.