Jump to: navigation, search

Manila/docs/db

< Manila‎ | docs
Revision as of 13:46, 3 October 2013 by Yulia Portnova (talk | contribs) (The manila.db.api Module)

The Database Layer

The manila.db.api Module

Defines interface for DB access. The underlying driver is loaded as a LazyPluggable. Functions in this module are imported into the manila.db namespace. Call these functions from manila.db namespace, not the manila.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

db_backend: string to lookup in the list of LazyPluggable backends. sqlalchemy is the only supported backend right now. sql_connection: string specifying the sqlalchemy connection to use, like: sqlite:///var/lib/manila/manila.sqlite. enable_new_services: when adding a new service to the database, is it in the pool of available hardware (Default: True)

migration_create(context, values)

Indented line

Create a migration record.

migration_get(context, migration_id)

   Finds a migration by the id.

migration_get_all_unconfirmed(context, confirm_window)

   Finds all unconfirmed migrations within the confirmation window.

migration_get_by_instance_and_status(context, instance_uuid, status)

   Finds a migration by the instance uuid its migrating.

migration_update(context, id, values)

   Update a migration instance.

quota_class_create(context, class_name, resource, limit)

   Create a quota class for the given name and resource.

quota_class_destroy(context, class_name, resource)

   Destroy the quota class or raise if it does not exist.

quota_class_destroy_all_by_name(context, class_name)

   Destroy all quotas associated with a given quota class.

quota_class_get(context, class_name, resource)

   Retrieve a quota class or raise if it does not exist.

quota_class_get_all_by_name(context, class_name)

   Retrieve all quotas associated with a given quota class.

quota_class_update(context, class_name, resource, limit)

   Update a quota class or raise if it does not exist.

quota_create(context, project_id, resource, limit)

   Create a quota for the given project and resource.

quota_destroy(context, project_id, resource)

   Destroy the quota or raise if it does not exist.

quota_destroy_all_by_project(context, project_id)

   Destroy all quotas associated with a given project.

quota_get(context, project_id, resource)

   Retrieve a quota or raise if it does not exist.

quota_get_all_by_project(context, project_id)

   Retrieve all quotas associated with a given project.

quota_reserve(context, resources, quotas, deltas, expire, until_refresh, max_age, project_id=None)

   Check quotas and create appropriate reservations.

quota_update(context, project_id, resource, limit)

   Update a quota or raise if it does not exist.

quota_usage_create(context, project_id, resource, in_use, reserved, until_refresh)

   Create a quota usage for the given project and resource.

quota_usage_get(context, project_id, resource)

   Retrieve a quota usage or raise if it does not exist.

quota_usage_get_all_by_project(context, project_id)

   Retrieve all usage associated with a given resource.

reservation_commit(context, reservations, project_id=None)

   Commit quota reservations.

reservation_create(context, uuid, usage, project_id, resource, delta, expire)

   Create a reservation for the given project and resource.

reservation_destroy(context, uuid)

   Destroy the reservation or raise if it does not exist.

reservation_expire(context)

   Roll back any expired reservations.

reservation_get(context, uuid)

   Retrieve a reservation or raise if it does not exist.

reservation_get_all_by_project(context, project_id)

   Retrieve all reservations associated with a given project.

reservation_rollback(context, reservations, project_id=None)

   Roll back quota reservations.

service_create(context, values)

   Create a service from the values dictionary.

service_destroy(context, service_id)

   Destroy the service or raise if it does not exist.

service_get(context, service_id)

   Get a service or raise if it does not exist.

service_get_all(context, disabled=None)

   Get all services.

service_get_all_by_host(context, host)

   Get all services for a given host.

service_get_all_by_topic(context, topic)

   Get all services for a given topic.

service_get_all_share_sorted(context)

   Get all share services sorted by share count.
   Returns:	a list of (Service, share_count) tuples.

service_get_by_args(context, host, binary)

   Get the state of an service by node name and binary.

service_get_by_host_and_topic(context, host, topic)

   Get a service by host it’s on and topic it listens to.

service_update(context, service_id, values)

   Set the given properties on an service and update it.
   Raises NotFound if service does not exist.

share_access_create(context, values)

   Allow access to share.

share_access_delete(context, access_id)

   Deny access to share.

share_access_get(context, access_id)

   Allow access to share.

share_access_get_all_for_share(context, share_id)

   Allow access to share.

share_access_update(context, access_id, values)

   Update access record.

share_create(context, values)

   Create new share.

share_data_get_for_project(context, project_id, session=None)

   Get (share_count, gigabytes) for project.

share_delete(context, share_id)

   Delete share.

share_get(context, share_id)

   Get share by id.

share_get_all(context)

   Get all shares.

share_get_all_by_host(context, host)

   Returns all shares with given host.

share_get_all_by_project(context, project_id)

   Returns all shares with given project ID.

share_snapshot_create(context, values)

   Create a snapshot from the values dictionary.

share_snapshot_data_get_for_project(context, project_id, session=None)

   Get count and gigabytes used for snapshots for specified project.

share_snapshot_destroy(context, snapshot_id)

   Destroy the snapshot or raise if it does not exist.

share_snapshot_get(context, snapshot_id)

   Get a snapshot or raise if it does not exist.

share_snapshot_get_all(context)

   Get all snapshots.

share_snapshot_get_all_by_project(context, project_id)

   Get all snapshots belonging to a project.

share_snapshot_get_all_for_share(context, share_id)

   Get all snapshots for a share.

share_snapshot_update(context, snapshot_id, values)

   Set the given properties on an snapshot and update it.
   Raises NotFound if snapshot does not exist.

share_update(context, share_id, values)

   Update share fields.

snapshot_data_get_for_project(context, project_id, session=None)

   Get (snapshot_count, gigabytes) for project.

The Sqlalchemy Driver

The manila.db.sqlalchemy.api Module

Implementation of SQLAlchemy backend. The manila.db.sqlalchemy.models Module

SQLAlchemy models for Manila data

class ManilaBase

   Bases: object
   Base class for Manila Models.
   ManilaBase.created_at = Column(None, DateTime(), table=None, default=ColumnDefault(<function <lambda> at 0x505faa0>))
   ManilaBase.delete(session=None)
       Delete this object.
   ManilaBase.deleted = Column(None, Boolean(), table=None, default=ColumnDefault(False))
   ManilaBase.deleted_at = Column(None, DateTime(), table=None)
   ManilaBase.get(key, default=None)
   ManilaBase.iteritems()
       Make the model object behave like a dict.
       Includes attributes from joins.
   ManilaBase.metadata = None
   ManilaBase.next()
   ManilaBase.save(session=None)
       Save this object.
   ManilaBase.update(values)
       Make the model object behave like a dict.
   ManilaBase.updated_at = Column(None, DateTime(), table=None, onupdate=ColumnDefault(<function <lambda> at 0x505fb18>))

class ManilaNode(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents a running manila service on a host.
   ManilaNode.created_at None
   ManilaNode.deleted None
   ManilaNode.deleted_at None
   ManilaNode.id None
   ManilaNode.service_id None
   ManilaNode.updated_at None

class Migration(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents a running host-to-host migration.
   Migration.created_at None
   Migration.deleted None
   Migration.deleted_at None
   Migration.dest_compute None
   Migration.dest_host None
   Migration.id None
   Migration.instance_uuid None
   Migration.new_instance_type_id None
   Migration.old_instance_type_id None
   Migration.source_compute None
   Migration.status None
   Migration.updated_at None

class Quota(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   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.
   Quota.created_at None
   Quota.deleted None
   Quota.deleted_at None
   Quota.hard_limit None
   Quota.id None
   Quota.project_id None
   Quota.resource None
   Quota.updated_at None

class QuotaClass(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   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.
   QuotaClass.class_name None
   QuotaClass.created_at None
   QuotaClass.deleted None
   QuotaClass.deleted_at None
   QuotaClass.hard_limit None
   QuotaClass.id None
   QuotaClass.resource None
   QuotaClass.updated_at None

class QuotaUsage(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents the current usage for a given resource.
   QuotaUsage.created_at None
   QuotaUsage.deleted None
   QuotaUsage.deleted_at None
   QuotaUsage.id None
   QuotaUsage.in_use None
   QuotaUsage.project_id None
   QuotaUsage.reserved None
   QuotaUsage.resource None
   QuotaUsage.total None
   QuotaUsage.until_refresh None
   QuotaUsage.updated_at None

class Reservation(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents a resource reservation for quotas.
   Reservation.created_at None
   Reservation.deleted None
   Reservation.deleted_at None
   Reservation.delta None
   Reservation.expire None
   Reservation.id None
   Reservation.project_id None
   Reservation.resource None
   Reservation.updated_at None
   Reservation.usage_id None
   Reservation.uuid None

class Service(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents a running service on a host.
   Service.availability_zone None
   Service.binary None
   Service.created_at None
   Service.deleted None
   Service.deleted_at None
   Service.disabled None
   Service.host None
   Service.id None
   Service.report_count None
   Service.topic None
   Service.updated_at None

class Share(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents an NFS and CIFS shares.
   Share.availability_zone None
   Share.created_at None
   Share.deleted None
   Share.deleted_at None
   Share.display_description None
   Share.display_name None
   Share.export_location None
   Share.host None
   Share.id None
   Share.launched_at None
   Share.name None
   Share.project_id None
   Share.scheduled_at None
   Share.share_proto None
   Share.size None
   Share.snapshot_id None
   Share.status None
   Share.terminated_at None
   Share.updated_at None
   Share.user_id None

class ShareAccessMapping(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents access to NFS.
   ShareAccessMapping.STATE_ACTIVE = 'active'
   ShareAccessMapping.STATE_DELETED = 'deleted'
   ShareAccessMapping.STATE_DELETING = 'deleting'
   ShareAccessMapping.STATE_ERROR = 'error'
   ShareAccessMapping.STATE_NEW = 'new'
   ShareAccessMapping.access_to None
   ShareAccessMapping.access_type None
   ShareAccessMapping.created_at None
   ShareAccessMapping.deleted None
   ShareAccessMapping.deleted_at None
   ShareAccessMapping.id None
   ShareAccessMapping.share_id None
   ShareAccessMapping.state None
   ShareAccessMapping.updated_at None

class ShareSnapshot(**kwargs)

   Bases: sqlalchemy.ext.declarative.Base, manila.db.sqlalchemy.models.ManilaBase
   Represents a snapshot of a share.
   ShareSnapshot.created_at None
   ShareSnapshot.deleted None
   ShareSnapshot.deleted_at None
   ShareSnapshot.display_description None
   ShareSnapshot.display_name None
   ShareSnapshot.export_location None
   ShareSnapshot.id None
   ShareSnapshot.name None
   ShareSnapshot.progress None
   ShareSnapshot.project_id None
   ShareSnapshot.share None
   ShareSnapshot.share_id None
   ShareSnapshot.share_name None
   ShareSnapshot.share_proto None
   ShareSnapshot.share_size None
   ShareSnapshot.size None
   ShareSnapshot.status None
   ShareSnapshot.updated_at None
   ShareSnapshot.user_id None

register_models()

   Register Models and create metadata.
   Called from manila.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.

The manila.db.sqlalchemy.session Module

Session Handling for SQLAlchemy backend.

get_engine()

   Return a SQLAlchemy engine.

get_maker(engine, autocommit=True, expire_on_commit=False)

   Return a SQLAlchemy sessionmaker using the given engine.

get_session(autocommit=True, expire_on_commit=False)

   Return a SQLAlchemy session.

is_db_connection_error(args)

   Return True if error in connecting to db.

ping_listener(dbapi_conn, connection_rec, connection_proxy)

   Ensures that MySQL connections checked out of the pool are alive.
   Borrowed from: http://groups.google.com/group/sqlalchemy/msg/a4ce563d802c929f

synchronous_switch_listener(dbapi_conn, connection_rec)

   Switch sqlite connections to non-synchronous mode

Tests

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.