From: Brian Waldon Date: Mon, 22 Oct 2012 21:17:40 +0000 (-0700) Subject: Drop duplicate sqlalchemy db api methods X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=921e13f644db987295d22530434f16319f2643aa;p=openstack-build%2Fcinder-build.git Drop duplicate sqlalchemy db api methods Several methods were redefined at the bottom of cinder/db/sqlalchemy/api.py. They have been removed: - quota_get - quota_get_all_by_project - quota_create - quota_update - quota_destroy - quota_destroy_all_by_project - quota_class_get - quota_class_get_all_by_name - quota_class_create - quota_class_update - quota_class_destroy - quota_class_destroy_all_by_name - quota_usage_get - quota_usage_get_all_by_project - quota_usage_create - quota_usage_update - quota_usage_destroy Fix bug 1070033 Change-Id: I64b0b0045af7251853da97a8a8c4b2cb09b1dd53 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index be29b30bd..1e75b2978 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1616,225 +1616,3 @@ def sm_volume_get(context, volume_id): def sm_volume_get_all(context): return model_query(context, models.SMVolume, read_deleted="yes").all() - - -############################### - - -@require_context -def quota_get(context, project_id, resource, session=None): - result = model_query(context, models.Quota, session=session, - read_deleted="no").\ - filter_by(project_id=project_id).\ - filter_by(resource=resource).\ - first() - - if not result: - raise exception.ProjectQuotaNotFound(project_id=project_id) - - return result - - -@require_context -def quota_get_all_by_project(context, project_id): - authorize_project_context(context, project_id) - - rows = model_query(context, models.Quota, read_deleted="no").\ - filter_by(project_id=project_id).\ - all() - - result = {'project_id': project_id} - for row in rows: - result[row.resource] = row.hard_limit - - return result - - -@require_admin_context -def quota_create(context, project_id, resource, limit): - quota_ref = models.Quota() - quota_ref.project_id = project_id - quota_ref.resource = resource - quota_ref.hard_limit = limit - quota_ref.save() - return quota_ref - - -@require_admin_context -def quota_update(context, project_id, resource, limit): - session = get_session() - with session.begin(): - quota_ref = quota_get(context, project_id, resource, session=session) - quota_ref.hard_limit = limit - quota_ref.save(session=session) - - -@require_admin_context -def quota_destroy(context, project_id, resource): - session = get_session() - with session.begin(): - quota_ref = quota_get(context, project_id, resource, session=session) - quota_ref.delete(session=session) - - -@require_admin_context -def quota_destroy_all_by_project(context, project_id): - session = get_session() - with session.begin(): - quotas = model_query(context, models.Quota, session=session, - read_deleted="no").\ - filter_by(project_id=project_id).\ - all() - - for quota_ref in quotas: - quota_ref.delete(session=session) - - -################### - - -@require_context -def quota_class_get(context, class_name, resource, session=None): - result = model_query(context, models.QuotaClass, session=session, - read_deleted="no").\ - filter_by(class_name=class_name).\ - filter_by(resource=resource).\ - first() - - if not result: - raise exception.QuotaClassNotFound(class_name=class_name) - - return result - - -@require_context -def quota_class_get_all_by_name(context, class_name): - authorize_quota_class_context(context, class_name) - - rows = model_query(context, models.QuotaClass, read_deleted="no").\ - filter_by(class_name=class_name).\ - all() - - result = {'class_name': class_name} - for row in rows: - result[row.resource] = row.hard_limit - - return result - - -@require_admin_context -def quota_class_create(context, class_name, resource, limit): - quota_class_ref = models.QuotaClass() - quota_class_ref.class_name = class_name - quota_class_ref.resource = resource - quota_class_ref.hard_limit = limit - quota_class_ref.save() - return quota_class_ref - - -@require_admin_context -def quota_class_update(context, class_name, resource, limit): - session = get_session() - with session.begin(): - quota_class_ref = quota_class_get(context, class_name, resource, - session=session) - quota_class_ref.hard_limit = limit - quota_class_ref.save(session=session) - - -@require_admin_context -def quota_class_destroy(context, class_name, resource): - session = get_session() - with session.begin(): - quota_class_ref = quota_class_get(context, class_name, resource, - session=session) - quota_class_ref.delete(session=session) - - -@require_admin_context -def quota_class_destroy_all_by_name(context, class_name): - session = get_session() - with session.begin(): - quota_classes = model_query(context, models.QuotaClass, - session=session, read_deleted="no").\ - filter_by(class_name=class_name).\ - all() - - for quota_class_ref in quota_classes: - quota_class_ref.delete(session=session) - - -@require_context -def quota_usage_get(context, project_id, resource, session=None): - result = model_query(context, models.QuotaUsage, session=session, - read_deleted="no").\ - filter_by(project_id=project_id).\ - filter_by(resource=resource).\ - first() - - if not result: - raise exception.QuotaUsageNotFound(project_id=project_id) - - return result - - -@require_context -def quota_usage_get_all_by_project(context, project_id): - authorize_project_context(context, project_id) - - rows = model_query(context, models.QuotaUsage, read_deleted="no").\ - filter_by(project_id=project_id).\ - all() - - result = {'project_id': project_id} - for row in rows: - result[row.resource] = dict(in_use=row.in_use, reserved=row.reserved) - - return result - - -@require_admin_context -def quota_usage_create(context, project_id, resource, in_use, reserved, - until_refresh, session=None, save=True): - quota_usage_ref = models.QuotaUsage() - quota_usage_ref.project_id = project_id - quota_usage_ref.resource = resource - quota_usage_ref.in_use = in_use - quota_usage_ref.reserved = reserved - quota_usage_ref.until_refresh = until_refresh - - # Allow us to hold the save operation until later; keeps the - # transaction in quota_reserve() from breaking too early - if save: - quota_usage_ref.save(session=session) - - return quota_usage_ref - - -@require_admin_context -def quota_usage_update(context, project_id, resource, in_use, reserved, - until_refresh, session=None): - def do_update(session): - quota_usage_ref = quota_usage_get(context, project_id, resource, - session=session) - quota_usage_ref.in_use = in_use - quota_usage_ref.reserved = reserved - quota_usage_ref.until_refresh = until_refresh - quota_usage_ref.save(session=session) - - if session: - # Assume caller started a transaction - do_update(session) - else: - session = get_session() - with session.begin(): - do_update(session) - - -@require_admin_context -def quota_usage_destroy(context, project_id, resource): - session = get_session() - with session.begin(): - quota_usage_ref = quota_usage_get(context, project_id, resource, - session=session) - quota_usage_ref.delete(session=session)