跳转到: 导航, 搜索

Manila/docs/db

< Manila‎ | docs

数据库层

manila.db.api 模块

定义数据库访问接口。底层驱动程序作为 LazyPluggable 加载。此模块中的函数被导入到 manila.db 命名空间中。从 manila.db 命名空间调用这些函数,而不是 manila.db.api 命名空间。此模块中的所有函数都返回实现类似字典接口的对象。目前,这些对象中的许多都是实现字典接口的 sqlalchemy 对象。但是,未来的目标是使所有这些对象都为简单的字典。

相关标志

db_backend:在 LazyPluggable 后端列表中查找的字符串。目前 sqlalchemy 是唯一支持的后端。sql_connection:指定要使用的 sqlalchemy 连接的字符串,例如:sqlite:///var/lib/manila/manila.sqlite。enable_new_services:在将新服务添加到数据库时,它是否在可用硬件池中(默认:True)

migration_create(context, values)

创建一个迁移记录。

migration_get(context, migration_id)

按 ID 查找迁移。

migration_get_all_unconfirmed(context, confirm_window)

查找确认窗口内的所有未确认的迁移。

migration_get_by_instance_and_status(context, instance_uuid, status)

按正在迁移的实例 UUID 查找迁移。

migration_update(context, id, values)

更新迁移实例。

quota_class_create(context, class_name, resource, limit)

为给定的名称和资源创建一个配额类。

quota_class_destroy(context, class_name, resource)

销毁配额类或在不存在时引发异常。

quota_class_destroy_all_by_name(context, class_name)

销毁与给定配额类关联的所有配额。

quota_class_get(context, class_name, resource)

检索配额类或在不存在时引发异常。

quota_class_get_all_by_name(context, class_name)

检索与给定配额类关联的所有配额。

quota_class_update(context, class_name, resource, limit)

更新配额类或在不存在时引发异常。

quota_create(context, project_id, resource, limit)

为给定的项目和资源创建一个配额。

quota_destroy(context, project_id, resource)

销毁配额或在不存在时引发异常。

quota_destroy_all_by_project(context, project_id)

销毁与给定项目关联的所有配额。

quota_get(context, project_id, resource)

检索配额或在不存在时引发异常。

quota_get_all_by_project(context, project_id)

检索与给定项目关联的所有配额。

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

检查配额并创建适当的预留。

quota_update(context, project_id, resource, limit)

更新配额或在不存在时引发异常。

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

为给定的项目和资源创建一个配额使用情况。

quota_usage_get(context, project_id, resource)

检索配额使用情况或在不存在时引发异常。

quota_usage_get_all_by_project(context, project_id)

检索与给定项目关联的所有使用情况。

reservation_commit(context, reservations, project_id=None)

提交配额预留。

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

为给定的项目和资源创建一个预留。

reservation_destroy(context, uuid)

销毁预留或在不存在时引发异常。

reservation_expire(context)

回滚任何过期的预留。

reservation_get(context, uuid)

检索预留或在不存在时引发异常。

reservation_get_all_by_project(context, project_id)

检索与给定项目关联的所有预留。

reservation_rollback(context, reservations, project_id=None)

回滚配额预留。

service_create(context, values)

从 values 字典创建服务。

service_destroy(context, service_id)

销毁服务或在不存在时引发异常。

service_get(context, service_id)

获取服务或在不存在时引发异常。

service_get_all(context, disabled=None)

获取所有服务。

service_get_all_by_host(context, host)

获取给定主机的所有服务。

service_get_all_by_topic(context, topic)

获取给定主题的所有服务。

service_get_all_share_sorted(context)

获取按共享计数排序的所有共享服务。
返回:(Service, share_count) 元组列表。

service_get_by_args(context, host, binary)

按节点名称和二进制获取服务状态。

service_get_by_host_and_topic(context, host, topic)

按其所在主机和监听主题获取服务。

service_update(context, service_id, values)

设置服务上的给定属性并更新它。
如果服务不存在,则引发 NotFound。

share_access_create(context, values)

允许访问共享。

share_access_delete(context, access_id)

拒绝访问共享。

share_access_get(context, access_id)

允许访问共享。

share_access_get_all_for_share(context, share_id)

允许访问共享。

share_access_update(context, access_id, values)

更新访问记录。

share_create(context, values)

创建新的共享。

share_data_get_for_project(context, project_id, session=None)

获取项目的 (share_count, gigabytes)。

share_delete(context, share_id)

删除共享。

share_get(context, share_id)

按 ID 获取共享。

share_get_all(context)

获取所有共享。

share_get_all_by_host(context, host)

返回具有给定主机的所有共享。

share_get_all_by_share_server(context, share_server_id)

返回具有给定共享服务器的所有共享。

share_get_all_by_project(context, project_id)

返回具有给定项目 ID 的所有共享。

share_snapshot_create(context, values)

从 values 字典创建快照。

share_snapshot_data_get_for_project(context, project_id, session=None)

获取指定项目的快照使用的计数和千兆字节数。

share_snapshot_destroy(context, snapshot_id)

销毁快照或在不存在时引发异常。

share_snapshot_get(context, snapshot_id)

获取快照或在不存在时引发异常。

share_snapshot_get_all(context)

获取所有快照。

share_snapshot_get_all_by_project(context, project_id)

获取属于项目的快照。

share_snapshot_get_all_for_share(context, share_id)

获取共享的所有快照。

share_snapshot_update(context, snapshot_id, values)

设置快照上的给定属性并更新它。
如果快照不存在,则引发 NotFound。

share_update(context, share_id, values)

更新共享字段。

snapshot_data_get_for_project(context, project_id, session=None)

获取项目的 (snapshot_count, gigabytes)。

share_server_create(context, values)

创建共享服务器数据库记录。

share_server_delete(context, id)

删除共享服务器数据库记录。

share_server_update(context, id, values)

更新共享服务器数据库记录。

share_server_get(context, id, session=None)

按 ID 获取共享服务器数据库记录。

share_server_get_by_host(context, host, share_net_id, session=None)

按主机获取共享服务器数据库记录。

share_server_get_by_host_and_share_net(context, host, share_net_id, session=None)

按主机和共享网络获取共享服务器数据库记录。

share_server_get_by_host_and_share_net_valid(context, host, share_net_id, session=None)

按主机和共享网络获取共享服务器数据库记录,不报错。

share_server_get_all(context)

获取所有共享服务器数据库记录。

share_server_backend_details_set(context, share_server_id, server_details)

创建带有后端详细信息的数据库记录。

share_server_backend_details_get(context, share_server_id)

获取共享服务器的所有后端详细信息记录。

Sqlalchemy 驱动程序

manila.db.sqlalchemy.api 模块

SQLAlchemy 后端的实现。manila.db.sqlalchemy.models 模块

Manila 数据 SQLAlchemy 模型

class ManilaBase

Bases: object
Manila 模型的基类。
ManilaBase.created_at = Column(None, DateTime(), table=None, default=ColumnDefault(<function <lambda> at 0x505faa0>))
ManilaBase.delete(session=None)
删除此对象。
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()
使模型对象表现得像一个字典。
包括来自连接的属性。
ManilaBase.metadata = None
ManilaBase.next()
ManilaBase.save(session=None)
保存此对象。
ManilaBase.update(values)
使模型对象表现得像一个字典。
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
表示主机上运行的 manila 服务。
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
表示正在运行的主机到主机迁移。
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
表示项目的单个配额覆盖。
如果对于给定的项目 ID 和资源没有行,则使用配额类的默认值。如果对于给定的配额类和资源没有行,则使用部署的默认值。如果该行存在但硬限制为 Null,则该资源是无限的。
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
表示配额类的单个配额覆盖。
如果对于给定的配额类和资源没有行,则使用部署的默认值。如果该行存在但硬限制为 Null,则该资源是无限的。
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
表示给定资源的使用情况。
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
表示配额的资源预留。
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
表示主机上运行的服务。
Service.availability_zone None
Service.binary None
Service.created_at None
Service.deleted None
Service.deleted_at None
Service.disabled None
Service.host None 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
表示 NFS 和 CIFS 共享。
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
表示对 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
表示一个共享的快照。
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()

注册模型并创建元数据。
从 manila.db.sqlalchemy.__init__ 中调用,作为加载驱动程序的一部分,除非连接丢失并需要重新建立,否则不需要在其他地方显式调用。

manila.db.sqlalchemy.session 模块

SQLAlchemy 后端的会话处理。

get_engine()

返回一个 SQLAlchemy 引擎。

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

使用给定的引擎返回一个 SQLAlchemy sessionmaker。

get_session(autocommit=True, expire_on_commit=False)

返回一个 SQLAlchemy 会话。

is_db_connection_error(args)

如果连接数据库时出错,则返回 True。

ping_listener(dbapi_conn, connection_rec, connection_proxy)

确保从连接池中检出的 MySQL 连接处于活动状态。
借用自:http://groups.google.com/group/sqlalchemy/msg/a4ce563d802c929f

synchronous_switch_listener(dbapi_conn, connection_rec)

将 sqlite 连接切换到非同步模式

测试

db api 层和 sqlalchemy 驱动程序缺乏测试。但是,驱动程序中的故障将在其他测试用例中被检测到。