From 1dde8fb5cfda07121ca7a702dc632553456eef15 Mon Sep 17 00:00:00 2001 From: Yulia Portnova <yportnova@mirantis.com> Date: Tue, 3 Sep 2013 11:14:00 +0300 Subject: [PATCH] DB cleaned --- manila/db/__init__.py | 2 +- manila/db/api.py | 138 --------- manila/db/sqlalchemy/api.py | 265 ------------------ manila/db/sqlalchemy/migrate_repo/migrate.cfg | 2 +- .../migrate_repo/versions/001_manila_init.py | 2 +- manila/db/sqlalchemy/models.py | 52 +--- 6 files changed, 16 insertions(+), 445 deletions(-) diff --git a/manila/db/__init__.py b/manila/db/__init__.py index 083a0a1fb2..dd681f9a52 100644 --- a/manila/db/__init__.py +++ b/manila/db/__init__.py @@ -17,7 +17,7 @@ # License for the specific language governing permissions and limitations # under the License. """ -DB abstraction for Cinder +DB abstraction for Manila """ from manila.db.api import * diff --git a/manila/db/api.py b/manila/db/api.py index ac59b27ab0..3ee86af038 100644 --- a/manila/db/api.py +++ b/manila/db/api.py @@ -56,9 +56,6 @@ db_opts = [ cfg.BoolOpt('enable_new_services', default=True, help='Services to be added to the available pool on create'), - cfg.StrOpt('volume_name_template', - default='volume-%s', - help='Template string to be used to generate volume names'), cfg.StrOpt('share_name_template', default='share-%s', help='Template string to be used to generate share names'), @@ -80,11 +77,6 @@ IMPL = utils.LazyPluggable('db_backend', sqlalchemy='manila.db.sqlalchemy.api') -class NoMoreTargets(exception.CinderException): - """No more available targets""" - pass - - ################### @@ -174,97 +166,9 @@ def migration_get_all_unconfirmed(context, confirm_window): return IMPL.migration_get_all_unconfirmed(context, confirm_window) -################### - - -def sm_backend_conf_create(context, values): - """Create a new SM Backend Config entry.""" - return IMPL.sm_backend_conf_create(context, values) - - -def sm_backend_conf_update(context, sm_backend_conf_id, values): - """Update a SM Backend Config entry.""" - return IMPL.sm_backend_conf_update(context, sm_backend_conf_id, values) - - -def sm_backend_conf_delete(context, sm_backend_conf_id): - """Delete a SM Backend Config.""" - return IMPL.sm_backend_conf_delete(context, sm_backend_conf_id) - - -def sm_backend_conf_get(context, sm_backend_conf_id): - """Get a specific SM Backend Config.""" - return IMPL.sm_backend_conf_get(context, sm_backend_conf_id) - - -def sm_backend_conf_get_by_sr(context, sr_uuid): - """Get a specific SM Backend Config.""" - return IMPL.sm_backend_conf_get_by_sr(context, sr_uuid) - - -def sm_backend_conf_get_all(context): - """Get all SM Backend Configs.""" - return IMPL.sm_backend_conf_get_all(context) - - #################### -def sm_flavor_create(context, values): - """Create a new SM Flavor entry.""" - return IMPL.sm_flavor_create(context, values) - - -def sm_flavor_update(context, sm_flavor_id, values): - """Update a SM Flavor entry.""" - return IMPL.sm_flavor_update(context, values) - - -def sm_flavor_delete(context, sm_flavor_id): - """Delete a SM Flavor.""" - return IMPL.sm_flavor_delete(context, sm_flavor_id) - - -def sm_flavor_get(context, sm_flavor): - """Get a specific SM Flavor.""" - return IMPL.sm_flavor_get(context, sm_flavor) - - -def sm_flavor_get_all(context): - """Get all SM Flavors.""" - return IMPL.sm_flavor_get_all(context) - - -#################### - - -def sm_volume_create(context, values): - """Create a new child Zone entry.""" - return IMPL.sm_volume_create(context, values) - - -def sm_volume_update(context, volume_id, values): - """Update a child Zone entry.""" - return IMPL.sm_volume_update(context, values) - - -def sm_volume_delete(context, volume_id): - """Delete a child Zone.""" - return IMPL.sm_volume_delete(context, volume_id) - - -def sm_volume_get(context, volume_id): - """Get a specific child Zone.""" - return IMPL.sm_volume_get(context, volume_id) - - -def sm_volume_get_all(context): - """Get all child Zones.""" - return IMPL.sm_volume_get_all(context) - -################### - - def quota_create(context, project_id, resource, limit): """Create a quota for the given project and resource.""" return IMPL.quota_create(context, project_id, resource, limit) @@ -403,48 +307,6 @@ def reservation_expire(context): ################### -def backup_get(context, backup_id): - """Get a backup or raise if it does not exist.""" - return IMPL.backup_get(context, backup_id) - - -def backup_get_all(context): - """Get all backups.""" - return IMPL.backup_get_all(context) - - -def backup_get_all_by_host(context, host): - """Get all backups belonging to a host.""" - return IMPL.backup_get_all_by_host(context, host) - - -def backup_create(context, values): - """Create a backup from the values dictionary.""" - return IMPL.backup_create(context, values) - - -def backup_get_all_by_project(context, project_id): - """Get all backups belonging to a project.""" - return IMPL.backup_get_all_by_project(context, project_id) - - -def backup_update(context, backup_id, values): - """ - Set the given properties on a backup and update it. - - Raises NotFound if backup does not exist. - """ - return IMPL.backup_update(context, backup_id, values) - - -def backup_destroy(context, backup_id): - """Destroy the backup or raise if it does not exist.""" - return IMPL.backup_destroy(context, backup_id) - - -#################### - - def share_create(context, values): """Create new share.""" return IMPL.share_create(context, values) diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py index 414cb352e2..9459bb70bf 100644 --- a/manila/db/sqlalchemy/api.py +++ b/manila/db/sqlalchemy/api.py @@ -328,39 +328,6 @@ def service_update(context, service_id, values): ################### -def _metadata_refs(metadata_dict, meta_class): - metadata_refs = [] - if metadata_dict: - for k, v in metadata_dict.iteritems(): - metadata_ref = meta_class() - metadata_ref['key'] = k - metadata_ref['value'] = v - metadata_refs.append(metadata_ref) - return metadata_refs - - -def _dict_with_extra_specs(inst_type_query): - """Takes an instance, volume, or instance type query returned - by sqlalchemy and returns it as a dictionary, converting the - extra_specs entry from a list of dicts: - - 'extra_specs' : [{'key': 'k1', 'value': 'v1', ...}, ...] - - to a single dict: - - 'extra_specs' : {'k1': 'v1'} - - """ - inst_type_dict = dict(inst_type_query) - extra_specs = dict([(x['key'], x['value']) - for x in inst_type_query['extra_specs']]) - inst_type_dict['extra_specs'] = extra_specs - return inst_type_dict - - -################### - - @require_context def quota_get(context, project_id, resource, session=None): result = model_query(context, models.Quota, session=session, @@ -838,238 +805,6 @@ def reservation_expire(context): reservation.delete(session=session) -################### - - -@require_admin_context -def sm_backend_conf_create(context, values): - backend_conf = models.SMBackendConf() - backend_conf.update(values) - backend_conf.save() - return backend_conf - - -@require_admin_context -def sm_backend_conf_update(context, sm_backend_id, values): - session = get_session() - with session.begin(): - backend_conf = model_query(context, models.SMBackendConf, - session=session, - read_deleted="yes").\ - filter_by(id=sm_backend_id).\ - first() - - if not backend_conf: - raise exception.NotFound( - _("No backend config with id %(sm_backend_id)s") % locals()) - - backend_conf.update(values) - backend_conf.save(session=session) - return backend_conf - - -@require_admin_context -def sm_backend_conf_delete(context, sm_backend_id): - # FIXME(sirp): for consistency, shouldn't this just mark as deleted with - # `purge` actually deleting the record? - session = get_session() - with session.begin(): - model_query(context, models.SMBackendConf, session=session, - read_deleted="yes").\ - filter_by(id=sm_backend_id).\ - delete() - - -@require_admin_context -def sm_backend_conf_get(context, sm_backend_id): - result = model_query(context, models.SMBackendConf, read_deleted="yes").\ - filter_by(id=sm_backend_id).\ - first() - - if not result: - raise exception.NotFound(_("No backend config with id " - "%(sm_backend_id)s") % locals()) - - return result - - -@require_admin_context -def sm_backend_conf_get_by_sr(context, sr_uuid): - return model_query(context, models.SMBackendConf, read_deleted="yes").\ - filter_by(sr_uuid=sr_uuid).\ - first() - - -@require_admin_context -def sm_backend_conf_get_all(context): - return model_query(context, models.SMBackendConf, read_deleted="yes").\ - all() - - -#################### - - -def _sm_flavor_get_query(context, sm_flavor_label, session=None): - return model_query(context, models.SMFlavors, session=session, - read_deleted="yes").\ - filter_by(label=sm_flavor_label) - - -@require_admin_context -def sm_flavor_create(context, values): - sm_flavor = models.SMFlavors() - sm_flavor.update(values) - sm_flavor.save() - return sm_flavor - - -@require_admin_context -def sm_flavor_update(context, sm_flavor_label, values): - sm_flavor = sm_flavor_get(context, sm_flavor_label) - sm_flavor.update(values) - sm_flavor.save() - return sm_flavor - - -@require_admin_context -def sm_flavor_delete(context, sm_flavor_label): - session = get_session() - with session.begin(): - _sm_flavor_get_query(context, sm_flavor_label).delete() - - -@require_admin_context -def sm_flavor_get(context, sm_flavor_label): - result = _sm_flavor_get_query(context, sm_flavor_label).first() - - if not result: - raise exception.NotFound( - _("No sm_flavor called %(sm_flavor)s") % locals()) - - return result - - -@require_admin_context -def sm_flavor_get_all(context): - return model_query(context, models.SMFlavors, read_deleted="yes").all() - - -############################### - - -def _sm_volume_get_query(context, volume_id, session=None): - return model_query(context, models.SMVolume, session=session, - read_deleted="yes").\ - filter_by(id=volume_id) - - -def sm_volume_create(context, values): - sm_volume = models.SMVolume() - sm_volume.update(values) - sm_volume.save() - return sm_volume - - -def sm_volume_update(context, volume_id, values): - sm_volume = sm_volume_get(context, volume_id) - sm_volume.update(values) - sm_volume.save() - return sm_volume - - -def sm_volume_delete(context, volume_id): - session = get_session() - with session.begin(): - _sm_volume_get_query(context, volume_id, session=session).delete() - - -def sm_volume_get(context, volume_id): - result = _sm_volume_get_query(context, volume_id).first() - - if not result: - raise exception.NotFound( - _("No sm_volume with id %(volume_id)s") % locals()) - - return result - - -def sm_volume_get_all(context): - return model_query(context, models.SMVolume, read_deleted="yes").all() - - -############################### - - -@require_context -def backup_get(context, backup_id, session=None): - result = model_query(context, models.Backup, - session=session, project_only=True).\ - filter_by(id=backup_id).\ - first() - - if not result: - raise exception.BackupNotFound(backup_id=backup_id) - - return result - - -@require_admin_context -def backup_get_all(context): - return model_query(context, models.Backup).all() - - -@require_admin_context -def backup_get_all_by_host(context, host): - return model_query(context, models.Backup).filter_by(host=host).all() - - -@require_context -def backup_get_all_by_project(context, project_id): - authorize_project_context(context, project_id) - - return model_query(context, models.Backup).\ - filter_by(project_id=project_id).all() - - -@require_context -def backup_create(context, values): - backup = models.Backup() - if not values.get('id'): - values['id'] = str(uuid.uuid4()) - backup.update(values) - backup.save() - return backup - - -@require_context -def backup_update(context, backup_id, values): - session = get_session() - with session.begin(): - backup = model_query(context, models.Backup, - session=session, read_deleted="yes").\ - filter_by(id=backup_id).first() - - if not backup: - raise exception.BackupNotFound( - _("No backup with id %(backup_id)s") % locals()) - - backup.update(values) - backup.save(session=session) - return backup - - -@require_admin_context -def backup_destroy(context, backup_id): - session = get_session() - with session.begin(): - session.query(models.Backup).\ - filter_by(id=backup_id).\ - update({'status': 'deleted', - 'deleted': True, - 'deleted_at': timeutils.utcnow(), - 'updated_at': literal_column('updated_at')}) - - ################ diff --git a/manila/db/sqlalchemy/migrate_repo/migrate.cfg b/manila/db/sqlalchemy/migrate_repo/migrate.cfg index 10c685c0e5..14b4e4f130 100644 --- a/manila/db/sqlalchemy/migrate_repo/migrate.cfg +++ b/manila/db/sqlalchemy/migrate_repo/migrate.cfg @@ -1,7 +1,7 @@ [db_settings] # Used to identify which repository this database is versioned under. # You can use the name of your project. -repository_id=cinder +repository_id=manila # The name of the database table used to track the schema version. # This name shouldn't already be used by your project. diff --git a/manila/db/sqlalchemy/migrate_repo/versions/001_manila_init.py b/manila/db/sqlalchemy/migrate_repo/versions/001_manila_init.py index 61efc8af67..613b324644 100644 --- a/manila/db/sqlalchemy/migrate_repo/versions/001_manila_init.py +++ b/manila/db/sqlalchemy/migrate_repo/versions/001_manila_init.py @@ -106,4 +106,4 @@ def upgrade(migrate_engine): def downgrade(migrate_engine): - LOG.exception(_('Downgrade from initial Cinder install is unsupported.')) + LOG.exception(_('Downgrade from initial Manila install is unsupported.')) diff --git a/manila/db/sqlalchemy/models.py b/manila/db/sqlalchemy/models.py index 8f997a8f48..cebc0ae0de 100644 --- a/manila/db/sqlalchemy/models.py +++ b/manila/db/sqlalchemy/models.py @@ -18,7 +18,7 @@ # License for the specific language governing permissions and limitations # under the License. """ -SQLAlchemy models for manila data. +SQLAlchemy models for Manila data. """ from sqlalchemy import Column, Integer, String, Text, schema @@ -38,8 +38,8 @@ FLAGS = flags.FLAGS BASE = declarative_base() -class CinderBase(object): - """Base class for Cinder Models.""" +class ManilaBase(object): + """Base class for Manila Models.""" __table_args__ = {'mysql_engine': 'InnoDB'} __table_initialized__ = False created_at = Column(DateTime, default=timeutils.utcnow) @@ -100,7 +100,7 @@ class CinderBase(object): return local.iteritems() -class Service(BASE, CinderBase): +class Service(BASE, ManilaBase): """Represents a running service on a host.""" __tablename__ = 'services' @@ -113,7 +113,7 @@ class Service(BASE, CinderBase): availability_zone = Column(String(255), default='manila') -class ManilaNode(BASE, CinderBase): +class ManilaNode(BASE, ManilaBase): """Represents a running manila service on a host.""" __tablename__ = 'manila_nodes' @@ -121,7 +121,7 @@ class ManilaNode(BASE, CinderBase): service_id = Column(Integer, ForeignKey('services.id'), nullable=True) -class Quota(BASE, CinderBase): +class Quota(BASE, ManilaBase): """Represents a single quota override for a project. If there is no row for a given project id and resource, then the @@ -140,7 +140,7 @@ class Quota(BASE, CinderBase): hard_limit = Column(Integer, nullable=True) -class QuotaClass(BASE, CinderBase): +class QuotaClass(BASE, ManilaBase): """Represents a single quota override for a quota class. If there is no row for a given quota class and resource, then the @@ -157,7 +157,7 @@ class QuotaClass(BASE, CinderBase): hard_limit = Column(Integer, nullable=True) -class QuotaUsage(BASE, CinderBase): +class QuotaUsage(BASE, ManilaBase): """Represents the current usage for a given resource.""" __tablename__ = 'quota_usages' @@ -176,7 +176,7 @@ class QuotaUsage(BASE, CinderBase): until_refresh = Column(Integer, nullable=True) -class Reservation(BASE, CinderBase): +class Reservation(BASE, ManilaBase): """Represents a resource reservation for quotas.""" __tablename__ = 'reservations' @@ -192,7 +192,7 @@ class Reservation(BASE, CinderBase): expire = Column(DateTime, nullable=False) -class Migration(BASE, CinderBase): +class Migration(BASE, ManilaBase): """Represents a running host-to-host migration.""" __tablename__ = 'migrations' id = Column(Integer, primary_key=True, nullable=False) @@ -210,33 +210,7 @@ class Migration(BASE, CinderBase): status = Column(String(255)) -class Backup(BASE, CinderBase): - """Represents a backup of a volume to Swift.""" - __tablename__ = 'backups' - id = Column(String(36), primary_key=True) - - @property - def name(self): - return FLAGS.backup_name_template % self.id - - user_id = Column(String(255), nullable=False) - project_id = Column(String(255), nullable=False) - - volume_id = Column(String(36), nullable=False) - host = Column(String(255)) - availability_zone = Column(String(255)) - display_name = Column(String(255)) - display_description = Column(String(255)) - container = Column(String(255)) - status = Column(String(255)) - fail_reason = Column(String(255)) - service_metadata = Column(String(255)) - service = Column(String(255)) - size = Column(Integer) - object_count = Column(Integer) - - -class Share(BASE, CinderBase): +class Share(BASE, ManilaBase): """Represents an NFS and CIFS shares.""" __tablename__ = 'shares' @@ -261,7 +235,7 @@ class Share(BASE, CinderBase): export_location = Column(String(255)) -class ShareAccessMapping(BASE, CinderBase): +class ShareAccessMapping(BASE, ManilaBase): """Represents access to NFS.""" STATE_NEW = 'new' STATE_ACTIVE = 'active' @@ -279,7 +253,7 @@ class ShareAccessMapping(BASE, CinderBase): default=STATE_NEW) -class ShareSnapshot(BASE, CinderBase): +class ShareSnapshot(BASE, ManilaBase): """Represents a snapshot of a share.""" __tablename__ = 'share_snapshots'