summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 13:54:28 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 13:54:28 +0000
commitc411e712f30b29febe08d2daaba1166d44671f7c (patch)
tree6ff0b5073bea99289ab3672d6e30ac0e7d299624
parent76c91b6029f02e8011b6e45251010975960947a6 (diff)
parentb42269992452ad4874d9963253592f92f3af5dcc (diff)
Merge "Use parenthesis instead of backslashes in db folder"
-rw-r--r--manila/db/migrations/alembic/versions/55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py17
-rw-r--r--manila/db/migrations/alembic/versions/56cdbe267881_add_share_export_locations_table.py4
-rw-r--r--manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py17
-rw-r--r--manila/db/sqlalchemy/api.py564
4 files changed, 303 insertions, 299 deletions
diff --git a/manila/db/migrations/alembic/versions/55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py b/manila/db/migrations/alembic/versions/55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py
index ce1ea0b..3293c16 100644
--- a/manila/db/migrations/alembic/versions/55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py
+++ b/manila/db/migrations/alembic/versions/55761e5f59c5_add_snapshot_support_extra_spec_to_share_types.py
@@ -55,17 +55,18 @@ def upgrade():
55 sa.Column('id', sa.Integer)) 55 sa.Column('id', sa.Integer))
56 56
57 # NOTE(vponomaryov): field 'deleted' is integer here. 57 # NOTE(vponomaryov): field 'deleted' is integer here.
58 existing_extra_specs = session.query(es_table).\ 58 existing_extra_specs = (session.query(es_table).
59 filter(es_table.c.spec_key == constants.ExtraSpecs.SNAPSHOT_SUPPORT).\ 59 filter(es_table.c.spec_key ==
60 filter(es_table.c.deleted == 0).\ 60 constants.ExtraSpecs.SNAPSHOT_SUPPORT).
61 all() 61 filter(es_table.c.deleted == 0).
62 all())
62 exclude_st_ids = [es.share_type_id for es in existing_extra_specs] 63 exclude_st_ids = [es.share_type_id for es in existing_extra_specs]
63 64
64 # NOTE(vponomaryov): field 'deleted' is string here. 65 # NOTE(vponomaryov): field 'deleted' is string here.
65 share_types = session.query(st_table).\ 66 share_types = (session.query(st_table).
66 filter(st_table.c.deleted.in_(('0', 'False', ))).\ 67 filter(st_table.c.deleted.in_(('0', 'False', ))).
67 filter(st_table.c.id.notin_(exclude_st_ids)).\ 68 filter(st_table.c.id.notin_(exclude_st_ids)).
68 all() 69 all())
69 session.close_all() 70 session.close_all()
70 71
71 extra_specs = [] 72 extra_specs = []
diff --git a/manila/db/migrations/alembic/versions/56cdbe267881_add_share_export_locations_table.py b/manila/db/migrations/alembic/versions/56cdbe267881_add_share_export_locations_table.py
index 7e137fd..65884c3 100644
--- a/manila/db/migrations/alembic/versions/56cdbe267881_add_share_export_locations_table.py
+++ b/manila/db/migrations/alembic/versions/56cdbe267881_add_share_export_locations_table.py
@@ -103,8 +103,8 @@ def downgrade():
103 autoload=True, autoload_with=connection) 103 autoload=True, autoload_with=connection)
104 104
105 for location in export_locations: 105 for location in export_locations:
106 update = shares.update().where(shares.c.id == location.share_id). \ 106 update = (shares.update().where(shares.c.id == location.share_id).
107 values(export_location=location.path) 107 values(export_location=location.path))
108 connection.execute(update) 108 connection.execute(update)
109 109
110 op.drop_table('share_export_locations') 110 op.drop_table('share_export_locations')
diff --git a/manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py b/manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py
index 9557b92..073f933 100644
--- a/manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py
+++ b/manila/db/migrations/alembic/versions/59eb64046740_add_required_extra_spec.py
@@ -47,17 +47,18 @@ def upgrade():
47 sa.Column('id', sa.Integer)) 47 sa.Column('id', sa.Integer))
48 48
49 # NOTE(vponomaryov): field 'deleted' is integer here. 49 # NOTE(vponomaryov): field 'deleted' is integer here.
50 existing_required_extra_specs = session.query(es_table).\ 50 existing_required_extra_specs = (session.query(es_table).
51 filter(es_table.c.spec_key == 'driver_handles_share_servers').\ 51 filter(es_table.c.spec_key ==
52 filter(es_table.c.deleted == 0).\ 52 'driver_handles_share_servers').
53 all() 53 filter(es_table.c.deleted == 0).
54 all())
54 exclude_st_ids = [es.share_type_id for es in existing_required_extra_specs] 55 exclude_st_ids = [es.share_type_id for es in existing_required_extra_specs]
55 56
56 # NOTE(vponomaryov): field 'deleted' is string here. 57 # NOTE(vponomaryov): field 'deleted' is string here.
57 share_types = session.query(st_table).\ 58 share_types = (session.query(st_table).
58 filter(st_table.c.deleted.in_(('0', 'False', ))).\ 59 filter(st_table.c.deleted.in_(('0', 'False', ))).
59 filter(st_table.c.id.notin_(exclude_st_ids)).\ 60 filter(st_table.c.id.notin_(exclude_st_ids)).
60 all() 61 all())
61 62
62 extra_specs = [] 63 extra_specs = []
63 for st in share_types: 64 for st in share_types:
diff --git a/manila/db/sqlalchemy/api.py b/manila/db/sqlalchemy/api.py
index 8f533d8..35a0e0c 100644
--- a/manila/db/sqlalchemy/api.py
+++ b/manila/db/sqlalchemy/api.py
@@ -337,12 +337,12 @@ def service_destroy(context, service_id):
337 337
338@require_admin_context 338@require_admin_context
339def service_get(context, service_id, session=None): 339def service_get(context, service_id, session=None):
340 result = model_query( 340 result = (model_query(
341 context, 341 context,
342 models.Service, 342 models.Service,
343 session=session).\ 343 session=session).
344 filter_by(id=service_id).\ 344 filter_by(id=service_id).
345 first() 345 first())
346 if not result: 346 if not result:
347 raise exception.ServiceNotFound(service_id=service_id) 347 raise exception.ServiceNotFound(service_id=service_id)
348 348
@@ -361,21 +361,21 @@ def service_get_all(context, disabled=None):
361 361
362@require_admin_context 362@require_admin_context
363def service_get_all_by_topic(context, topic): 363def service_get_all_by_topic(context, topic):
364 return model_query( 364 return (model_query(
365 context, models.Service, read_deleted="no").\ 365 context, models.Service, read_deleted="no").
366 filter_by(disabled=False).\ 366 filter_by(disabled=False).
367 filter_by(topic=topic).\ 367 filter_by(topic=topic).
368 all() 368 all())
369 369
370 370
371@require_admin_context 371@require_admin_context
372def service_get_by_host_and_topic(context, host, topic): 372def service_get_by_host_and_topic(context, host, topic):
373 result = model_query( 373 result = (model_query(
374 context, models.Service, read_deleted="no").\ 374 context, models.Service, read_deleted="no").
375 filter_by(disabled=False).\ 375 filter_by(disabled=False).
376 filter_by(host=host).\ 376 filter_by(host=host).
377 filter_by(topic=topic).\ 377 filter_by(topic=topic).
378 first() 378 first())
379 if not result: 379 if not result:
380 raise exception.ServiceNotFound(service_id=host) 380 raise exception.ServiceNotFound(service_id=host)
381 return result 381 return result
@@ -384,14 +384,14 @@ def service_get_by_host_and_topic(context, host, topic):
384@require_admin_context 384@require_admin_context
385def _service_get_all_topic_subquery(context, session, topic, subq, label): 385def _service_get_all_topic_subquery(context, session, topic, subq, label):
386 sort_value = getattr(subq.c, label) 386 sort_value = getattr(subq.c, label)
387 return model_query(context, models.Service, 387 return (model_query(context, models.Service,
388 func.coalesce(sort_value, 0), 388 func.coalesce(sort_value, 0),
389 session=session, read_deleted="no").\ 389 session=session, read_deleted="no").
390 filter_by(topic=topic).\ 390 filter_by(topic=topic).
391 filter_by(disabled=False).\ 391 filter_by(disabled=False).
392 outerjoin((subq, models.Service.host == subq.c.host)).\ 392 outerjoin((subq, models.Service.host == subq.c.host)).
393 order_by(sort_value).\ 393 order_by(sort_value).
394 all() 394 all())
395 395
396 396
397@require_admin_context 397@require_admin_context
@@ -400,13 +400,13 @@ def service_get_all_share_sorted(context):
400 with session.begin(): 400 with session.begin():
401 topic = CONF.share_topic 401 topic = CONF.share_topic
402 label = 'share_gigabytes' 402 label = 'share_gigabytes'
403 subq = model_query(context, models.Share, 403 subq = (model_query(context, models.Share,
404 func.sum(models.Share.size).label(label), 404 func.sum(models.Share.size).label(label),
405 session=session, read_deleted="no").\ 405 session=session, read_deleted="no").
406 join(models.ShareInstance, 406 join(models.ShareInstance,
407 models.ShareInstance.share_id == models.Share.id).\ 407 models.ShareInstance.share_id == models.Share.id).
408 group_by(models.ShareInstance.host).\ 408 group_by(models.ShareInstance.host).
409 subquery() 409 subquery())
410 return _service_get_all_topic_subquery(context, 410 return _service_get_all_topic_subquery(context,
411 session, 411 session,
412 topic, 412 topic,
@@ -416,10 +416,10 @@ def service_get_all_share_sorted(context):
416 416
417@require_admin_context 417@require_admin_context
418def service_get_by_args(context, host, binary): 418def service_get_by_args(context, host, binary):
419 result = model_query(context, models.Service).\ 419 result = (model_query(context, models.Service).
420 filter_by(host=host).\ 420 filter_by(host=host).
421 filter_by(binary=binary).\ 421 filter_by(binary=binary).
422 first() 422 first())
423 423
424 if not result: 424 if not result:
425 raise exception.HostBinaryNotFound(host=host, binary=binary) 425 raise exception.HostBinaryNotFound(host=host, binary=binary)
@@ -461,11 +461,11 @@ def service_update(context, service_id, values):
461 461
462@require_context 462@require_context
463def quota_get(context, project_id, resource, session=None): 463def quota_get(context, project_id, resource, session=None):
464 result = model_query(context, models.Quota, session=session, 464 result = (model_query(context, models.Quota, session=session,
465 read_deleted="no").\ 465 read_deleted="no").
466 filter_by(project_id=project_id).\ 466 filter_by(project_id=project_id).
467 filter_by(resource=resource).\ 467 filter_by(resource=resource).
468 first() 468 first())
469 469
470 if not result: 470 if not result:
471 raise exception.ProjectQuotaNotFound(project_id=project_id) 471 raise exception.ProjectQuotaNotFound(project_id=project_id)
@@ -477,12 +477,12 @@ def quota_get(context, project_id, resource, session=None):
477def quota_get_all_by_project_and_user(context, project_id, user_id): 477def quota_get_all_by_project_and_user(context, project_id, user_id):
478 authorize_project_context(context, project_id) 478 authorize_project_context(context, project_id)
479 479
480 user_quotas = model_query(context, models.ProjectUserQuota, 480 user_quotas = (model_query(context, models.ProjectUserQuota,
481 models.ProjectUserQuota.resource, 481 models.ProjectUserQuota.resource,
482 models.ProjectUserQuota.hard_limit).\ 482 models.ProjectUserQuota.hard_limit).
483 filter_by(project_id=project_id).\ 483 filter_by(project_id=project_id).
484 filter_by(user_id=user_id).\ 484 filter_by(user_id=user_id).
485 all() 485 all())
486 486
487 result = {'project_id': project_id, 'user_id': user_id} 487 result = {'project_id': project_id, 'user_id': user_id}
488 for quota in user_quotas: 488 for quota in user_quotas:
@@ -495,9 +495,9 @@ def quota_get_all_by_project_and_user(context, project_id, user_id):
495def quota_get_all_by_project(context, project_id): 495def quota_get_all_by_project(context, project_id):
496 authorize_project_context(context, project_id) 496 authorize_project_context(context, project_id)
497 497
498 rows = model_query(context, models.Quota, read_deleted="no").\ 498 rows = (model_query(context, models.Quota, read_deleted="no").
499 filter_by(project_id=project_id).\ 499 filter_by(project_id=project_id).
500 all() 500 all())
501 501
502 result = {'project_id': project_id} 502 result = {'project_id': project_id}
503 for row in rows: 503 for row in rows:
@@ -510,9 +510,9 @@ def quota_get_all_by_project(context, project_id):
510def quota_get_all(context, project_id): 510def quota_get_all(context, project_id):
511 authorize_project_context(context, project_id) 511 authorize_project_context(context, project_id)
512 512
513 result = model_query(context, models.ProjectUserQuota).\ 513 result = (model_query(context, models.ProjectUserQuota).
514 filter_by(project_id=project_id).\ 514 filter_by(project_id=project_id).
515 all() 515 all())
516 516
517 return result 517 return result
518 518
@@ -522,16 +522,16 @@ def quota_create(context, project_id, resource, limit, user_id=None):
522 per_user = user_id and resource not in PER_PROJECT_QUOTAS 522 per_user = user_id and resource not in PER_PROJECT_QUOTAS
523 523
524 if per_user: 524 if per_user:
525 check = model_query(context, models.ProjectUserQuota).\ 525 check = (model_query(context, models.ProjectUserQuota).
526 filter_by(project_id=project_id).\ 526 filter_by(project_id=project_id).
527 filter_by(user_id=user_id).\ 527 filter_by(user_id=user_id).
528 filter_by(resource=resource).\ 528 filter_by(resource=resource).
529 all() 529 all())
530 else: 530 else:
531 check = model_query(context, models.Quota).\ 531 check = (model_query(context, models.Quota).
532 filter_by(project_id=project_id).\ 532 filter_by(project_id=project_id).
533 filter_by(resource=resource).\ 533 filter_by(resource=resource).
534 all() 534 all())
535 if check: 535 if check:
536 raise exception.QuotaExists(project_id=project_id, resource=resource) 536 raise exception.QuotaExists(project_id=project_id, resource=resource)
537 537
@@ -552,9 +552,9 @@ def quota_create(context, project_id, resource, limit, user_id=None):
552def quota_update(context, project_id, resource, limit, user_id=None): 552def quota_update(context, project_id, resource, limit, user_id=None):
553 per_user = user_id and resource not in PER_PROJECT_QUOTAS 553 per_user = user_id and resource not in PER_PROJECT_QUOTAS
554 model = models.ProjectUserQuota if per_user else models.Quota 554 model = models.ProjectUserQuota if per_user else models.Quota
555 query = model_query(context, model).\ 555 query = (model_query(context, model).
556 filter_by(project_id=project_id).\ 556 filter_by(project_id=project_id).
557 filter_by(resource=resource) 557 filter_by(resource=resource))
558 if per_user: 558 if per_user:
559 query = query.filter_by(user_id=user_id) 559 query = query.filter_by(user_id=user_id)
560 560
@@ -572,11 +572,11 @@ def quota_update(context, project_id, resource, limit, user_id=None):
572 572
573@require_context 573@require_context
574def quota_class_get(context, class_name, resource, session=None): 574def quota_class_get(context, class_name, resource, session=None):
575 result = model_query(context, models.QuotaClass, session=session, 575 result = (model_query(context, models.QuotaClass, session=session,
576 read_deleted="no").\ 576 read_deleted="no").
577 filter_by(class_name=class_name).\ 577 filter_by(class_name=class_name).
578 filter_by(resource=resource).\ 578 filter_by(resource=resource).
579 first() 579 first())
580 580
581 if not result: 581 if not result:
582 raise exception.QuotaClassNotFound(class_name=class_name) 582 raise exception.QuotaClassNotFound(class_name=class_name)
@@ -586,9 +586,9 @@ def quota_class_get(context, class_name, resource, session=None):
586 586
587@require_context 587@require_context
588def quota_class_get_default(context): 588def quota_class_get_default(context):
589 rows = model_query(context, models.QuotaClass, read_deleted="no").\ 589 rows = (model_query(context, models.QuotaClass, read_deleted="no").
590 filter_by(class_name=_DEFAULT_QUOTA_NAME).\ 590 filter_by(class_name=_DEFAULT_QUOTA_NAME).
591 all() 591 all())
592 592
593 result = {'class_name': _DEFAULT_QUOTA_NAME} 593 result = {'class_name': _DEFAULT_QUOTA_NAME}
594 for row in rows: 594 for row in rows:
@@ -601,9 +601,9 @@ def quota_class_get_default(context):
601def quota_class_get_all_by_name(context, class_name): 601def quota_class_get_all_by_name(context, class_name):
602 authorize_quota_class_context(context, class_name) 602 authorize_quota_class_context(context, class_name)
603 603
604 rows = model_query(context, models.QuotaClass, read_deleted="no").\ 604 rows = (model_query(context, models.QuotaClass, read_deleted="no").
605 filter_by(class_name=class_name).\ 605 filter_by(class_name=class_name).
606 all() 606 all())
607 607
608 result = {'class_name': class_name} 608 result = {'class_name': class_name}
609 for row in rows: 609 for row in rows:
@@ -627,10 +627,10 @@ def quota_class_create(context, class_name, resource, limit):
627@require_admin_context 627@require_admin_context
628@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True) 628@oslo_db_api.wrap_db_retry(max_retries=5, retry_on_deadlock=True)
629def quota_class_update(context, class_name, resource, limit): 629def quota_class_update(context, class_name, resource, limit):
630 result = model_query(context, models.QuotaClass, read_deleted="no").\ 630 result = (model_query(context, models.QuotaClass, read_deleted="no").
631 filter_by(class_name=class_name).\ 631 filter_by(class_name=class_name).
632 filter_by(resource=resource).\ 632 filter_by(resource=resource).
633 update({'hard_limit': limit}) 633 update({'hard_limit': limit}))
634 634
635 if not result: 635 if not result:
636 raise exception.QuotaClassNotFound(class_name=class_name) 636 raise exception.QuotaClassNotFound(class_name=class_name)
@@ -641,9 +641,9 @@ def quota_class_update(context, class_name, resource, limit):
641 641
642@require_context 642@require_context
643def quota_usage_get(context, project_id, resource, user_id=None): 643def quota_usage_get(context, project_id, resource, user_id=None):
644 query = model_query(context, models.QuotaUsage, read_deleted="no").\ 644 query = (model_query(context, models.QuotaUsage, read_deleted="no").
645 filter_by(project_id=project_id).\ 645 filter_by(project_id=project_id).
646 filter_by(resource=resource) 646 filter_by(resource=resource))
647 if user_id: 647 if user_id:
648 if resource not in PER_PROJECT_QUOTAS: 648 if resource not in PER_PROJECT_QUOTAS:
649 result = query.filter_by(user_id=user_id).first() 649 result = query.filter_by(user_id=user_id).first()
@@ -660,8 +660,8 @@ def quota_usage_get(context, project_id, resource, user_id=None):
660 660
661def _quota_usage_get_all(context, project_id, user_id=None): 661def _quota_usage_get_all(context, project_id, user_id=None):
662 authorize_project_context(context, project_id) 662 authorize_project_context(context, project_id)
663 query = model_query(context, models.QuotaUsage, read_deleted="no").\ 663 query = (model_query(context, models.QuotaUsage, read_deleted="no").
664 filter_by(project_id=project_id) 664 filter_by(project_id=project_id))
665 result = {'project_id': project_id} 665 result = {'project_id': project_id}
666 if user_id: 666 if user_id:
667 query = query.filter(or_(models.QuotaUsage.user_id == user_id, 667 query = query.filter(or_(models.QuotaUsage.user_id == user_id,
@@ -724,12 +724,12 @@ def quota_usage_update(context, project_id, user_id, resource, **kwargs):
724 if key in kwargs: 724 if key in kwargs:
725 updates[key] = kwargs[key] 725 updates[key] = kwargs[key]
726 726
727 result = model_query(context, models.QuotaUsage, read_deleted="no").\ 727 result = (model_query(context, models.QuotaUsage, read_deleted="no").
728 filter_by(project_id=project_id).\ 728 filter_by(project_id=project_id).
729 filter_by(resource=resource).\ 729 filter_by(resource=resource).
730 filter(or_(models.QuotaUsage.user_id == user_id, 730 filter(or_(models.QuotaUsage.user_id == user_id,
731 models.QuotaUsage.user_id is None)).\ 731 models.QuotaUsage.user_id is None)).
732 update(updates) 732 update(updates))
733 733
734 if not result: 734 if not result:
735 raise exception.QuotaUsageNotFound(project_id=project_id) 735 raise exception.QuotaUsageNotFound(project_id=project_id)
@@ -762,24 +762,24 @@ def _reservation_create(context, uuid, usage, project_id, user_id, resource,
762 762
763def _get_user_quota_usages(context, session, project_id, user_id): 763def _get_user_quota_usages(context, session, project_id, user_id):
764 # Broken out for testability 764 # Broken out for testability
765 rows = model_query(context, models.QuotaUsage, 765 rows = (model_query(context, models.QuotaUsage,
766 read_deleted="no", 766 read_deleted="no",
767 session=session).\ 767 session=session).
768 filter_by(project_id=project_id).\ 768 filter_by(project_id=project_id).
769 filter(or_(models.QuotaUsage.user_id == user_id, 769 filter(or_(models.QuotaUsage.user_id == user_id,
770 models.QuotaUsage.user_id is None)).\ 770 models.QuotaUsage.user_id is None)).
771 with_lockmode('update').\ 771 with_lockmode('update').
772 all() 772 all())
773 return {row.resource: row for row in rows} 773 return {row.resource: row for row in rows}
774 774
775 775
776def _get_project_quota_usages(context, session, project_id): 776def _get_project_quota_usages(context, session, project_id):
777 rows = model_query(context, models.QuotaUsage, 777 rows = (model_query(context, models.QuotaUsage,
778 read_deleted="no", 778 read_deleted="no",
779 session=session).\ 779 session=session).
780 filter_by(project_id=project_id).\ 780 filter_by(project_id=project_id).
781 with_lockmode('update').\ 781 with_lockmode('update').
782 all() 782 all())
783 result = dict() 783 result = dict()
784 # Get the total count of in_use,reserved 784 # Get the total count of in_use,reserved
785 for row in rows: 785 for row in rows:
@@ -992,11 +992,11 @@ def _quota_reservations_query(session, context, reservations):
992 """Return the relevant reservations.""" 992 """Return the relevant reservations."""
993 993
994 # Get the listed reservations 994 # Get the listed reservations
995 return model_query(context, models.Reservation, 995 return (model_query(context, models.Reservation,
996 read_deleted="no", 996 read_deleted="no",
997 session=session).\ 997 session=session).
998 filter(models.Reservation.uuid.in_(reservations)).\ 998 filter(models.Reservation.uuid.in_(reservations)).
999 with_lockmode('update') 999 with_lockmode('update'))
1000 1000
1001 1001
1002@require_context 1002@require_context
@@ -1034,45 +1034,45 @@ def reservation_rollback(context, reservations, project_id=None, user_id=None):
1034def quota_destroy_all_by_project_and_user(context, project_id, user_id): 1034def quota_destroy_all_by_project_and_user(context, project_id, user_id):
1035 session = get_session() 1035 session = get_session()
1036 with session.begin(): 1036 with session.begin():
1037 model_query(context, models.ProjectUserQuota, session=session, 1037 (model_query(context, models.ProjectUserQuota, session=session,
1038 read_deleted="no").\ 1038 read_deleted="no").
1039 filter_by(project_id=project_id).\ 1039 filter_by(project_id=project_id).
1040 filter_by(user_id=user_id).soft_delete(synchronize_session=False) 1040 filter_by(user_id=user_id).soft_delete(synchronize_session=False))
1041 1041
1042 model_query(context, models.QuotaUsage, 1042 (model_query(context, models.QuotaUsage,
1043 session=session, read_deleted="no").\ 1043 session=session, read_deleted="no").
1044 filter_by(project_id=project_id).\ 1044 filter_by(project_id=project_id).
1045 filter_by(user_id=user_id).soft_delete(synchronize_session=False) 1045 filter_by(user_id=user_id).soft_delete(synchronize_session=False))
1046 1046
1047 model_query(context, models.Reservation, 1047 (model_query(context, models.Reservation,
1048 session=session, read_deleted="no").\ 1048 session=session, read_deleted="no").
1049 filter_by(project_id=project_id).\ 1049 filter_by(project_id=project_id).
1050 filter_by(user_id=user_id).soft_delete(synchronize_session=False) 1050 filter_by(user_id=user_id).soft_delete(synchronize_session=False))
1051 1051
1052 1052
1053@require_admin_context 1053@require_admin_context
1054def quota_destroy_all_by_project(context, project_id): 1054def quota_destroy_all_by_project(context, project_id):
1055 session = get_session() 1055 session = get_session()
1056 with session.begin(): 1056 with session.begin():
1057 model_query(context, models.Quota, session=session, 1057 (model_query(context, models.Quota, session=session,
1058 read_deleted="no").\ 1058 read_deleted="no").
1059 filter_by(project_id=project_id).\ 1059 filter_by(project_id=project_id).
1060 soft_delete(synchronize_session=False) 1060 soft_delete(synchronize_session=False))
1061 1061
1062 model_query(context, models.ProjectUserQuota, session=session, 1062 (model_query(context, models.ProjectUserQuota, session=session,
1063 read_deleted="no").\ 1063 read_deleted="no").
1064 filter_by(project_id=project_id).\ 1064 filter_by(project_id=project_id).
1065 soft_delete(synchronize_session=False) 1065 soft_delete(synchronize_session=False))
1066 1066
1067 model_query(context, models.QuotaUsage, 1067 (model_query(context, models.QuotaUsage,
1068 session=session, read_deleted="no").\ 1068 session=session, read_deleted="no").
1069 filter_by(project_id=project_id).\ 1069 filter_by(project_id=project_id).
1070 soft_delete(synchronize_session=False) 1070 soft_delete(synchronize_session=False))
1071 1071
1072 model_query(context, models.Reservation, 1072 (model_query(context, models.Reservation,
1073 session=session, read_deleted="no").\ 1073 session=session, read_deleted="no").
1074 filter_by(project_id=project_id).\ 1074 filter_by(project_id=project_id).
1075 soft_delete(synchronize_session=False) 1075 soft_delete(synchronize_session=False))
1076 1076
1077 1077
1078@require_admin_context 1078@require_admin_context
@@ -1081,9 +1081,10 @@ def reservation_expire(context):
1081 session = get_session() 1081 session = get_session()
1082 with session.begin(): 1082 with session.begin():
1083 current_time = timeutils.utcnow() 1083 current_time = timeutils.utcnow()
1084 reservation_query = model_query(context, models.Reservation, 1084 reservation_query = (model_query(
1085 session=session, read_deleted="no").\ 1085 context, models.Reservation,
1086 filter(models.Reservation.expire < current_time) 1086 session=session, read_deleted="no").
1087 filter(models.Reservation.expire < current_time))
1087 1088
1088 for reservation in reservation_query.all(): 1089 for reservation in reservation_query.all():
1089 if reservation.delta >= 0: 1090 if reservation.delta >= 0:
@@ -1458,8 +1459,8 @@ def share_replica_delete(context, share_replica_id, session=None):
1458def _share_get_query(context, session=None): 1459def _share_get_query(context, session=None):
1459 if session is None: 1460 if session is None:
1460 session = get_session() 1461 session = get_session()
1461 return model_query(context, models.Share, session=session).\ 1462 return (model_query(context, models.Share, session=session).
1462 options(joinedload('share_metadata')) 1463 options(joinedload('share_metadata')))
1463 1464
1464 1465
1465def _metadata_refs(metadata_dict, meta_class): 1466def _metadata_refs(metadata_dict, meta_class):
@@ -1502,12 +1503,12 @@ def share_create(context, share_values, create_share_instance=True):
1502 1503
1503@require_admin_context 1504@require_admin_context
1504def share_data_get_for_project(context, project_id, user_id, session=None): 1505def share_data_get_for_project(context, project_id, user_id, session=None):
1505 query = model_query(context, models.Share, 1506 query = (model_query(context, models.Share,
1506 func.count(models.Share.id), 1507 func.count(models.Share.id),
1507 func.sum(models.Share.size), 1508 func.sum(models.Share.size),
1508 read_deleted="no", 1509 read_deleted="no",
1509 session=session).\ 1510 session=session).
1510 filter_by(project_id=project_id) 1511 filter_by(project_id=project_id))
1511 if user_id: 1512 if user_id:
1512 result = query.filter_by(user_id=user_id).first() 1513 result = query.filter_by(user_id=user_id).first()
1513 else: 1514 else:
@@ -1677,8 +1678,8 @@ def share_delete(context, share_id):
1677 1678
1678 share_ref.soft_delete(session=session) 1679 share_ref.soft_delete(session=session)
1679 1680
1680 session.query(models.ShareMetadata).\ 1681 (session.query(models.ShareMetadata).
1681 filter_by(share_id=share_id).soft_delete() 1682 filter_by(share_id=share_id).soft_delete())
1682 1683
1683 1684
1684################### 1685###################
@@ -1880,8 +1881,8 @@ def share_access_get_all_by_type_and_access(context, share_id, access_type,
1880def share_access_delete_all_by_share(context, share_id): 1881def share_access_delete_all_by_share(context, share_id):
1881 session = get_session() 1882 session = get_session()
1882 with session.begin(): 1883 with session.begin():
1883 session.query(models.ShareAccessMapping). \ 1884 (session.query(models.ShareAccessMapping).
1884 filter_by(share_id=share_id).soft_delete() 1885 filter_by(share_id=share_id).soft_delete())
1885 1886
1886 1887
1887@require_context 1888@require_context
@@ -1889,8 +1890,8 @@ def share_instance_access_delete(context, mapping_id):
1889 session = get_session() 1890 session = get_session()
1890 with session.begin(): 1891 with session.begin():
1891 1892
1892 mapping = session.query(models.ShareInstanceAccessMapping).\ 1893 mapping = (session.query(models.ShareInstanceAccessMapping).
1893 filter_by(id=mapping_id).first() 1894 filter_by(id=mapping_id).first())
1894 1895
1895 if not mapping: 1896 if not mapping:
1896 exception.NotFound() 1897 exception.NotFound()
@@ -2122,12 +2123,12 @@ def share_snapshot_create(context, create_values,
2122 2123
2123@require_admin_context 2124@require_admin_context
2124def snapshot_data_get_for_project(context, project_id, user_id, session=None): 2125def snapshot_data_get_for_project(context, project_id, user_id, session=None):
2125 query = model_query(context, models.ShareSnapshot, 2126 query = (model_query(context, models.ShareSnapshot,
2126 func.count(models.ShareSnapshot.id), 2127 func.count(models.ShareSnapshot.id),
2127 func.sum(models.ShareSnapshot.size), 2128 func.sum(models.ShareSnapshot.size),
2128 read_deleted="no", 2129 read_deleted="no",
2129 session=session).\ 2130 session=session).
2130 filter_by(project_id=project_id) 2131 filter_by(project_id=project_id))
2131 2132
2132 if user_id: 2133 if user_id:
2133 result = query.filter_by(user_id=user_id).first() 2134 result = query.filter_by(user_id=user_id).first()
@@ -2139,12 +2140,12 @@ def snapshot_data_get_for_project(context, project_id, user_id, session=None):
2139 2140
2140@require_context 2141@require_context
2141def share_snapshot_get(context, snapshot_id, session=None): 2142def share_snapshot_get(context, snapshot_id, session=None):
2142 result = model_query(context, models.ShareSnapshot, session=session, 2143 result = (model_query(context, models.ShareSnapshot, session=session,
2143 project_only=True).\ 2144 project_only=True).
2144 filter_by(id=snapshot_id).\ 2145 filter_by(id=snapshot_id).
2145 options(joinedload('share')).\ 2146 options(joinedload('share')).
2146 options(joinedload('instances')).\ 2147 options(joinedload('instances')).
2147 first() 2148 first())
2148 2149
2149 if not result: 2150 if not result:
2150 raise exception.ShareSnapshotNotFound(snapshot_id=snapshot_id) 2151 raise exception.ShareSnapshotNotFound(snapshot_id=snapshot_id)
@@ -2539,8 +2540,8 @@ def share_metadata_get(context, share_id):
2539@require_context 2540@require_context
2540@require_share_exists 2541@require_share_exists
2541def share_metadata_delete(context, share_id, key): 2542def share_metadata_delete(context, share_id, key):
2542 _share_metadata_get_query(context, share_id).\ 2543 (_share_metadata_get_query(context, share_id).
2543 filter_by(key=key).soft_delete() 2544 filter_by(key=key).soft_delete())
2544 2545
2545 2546
2546@require_context 2547@require_context
@@ -2550,10 +2551,10 @@ def share_metadata_update(context, share_id, metadata, delete):
2550 2551
2551 2552
2552def _share_metadata_get_query(context, share_id, session=None): 2553def _share_metadata_get_query(context, share_id, session=None):
2553 return model_query(context, models.ShareMetadata, session=session, 2554 return (model_query(context, models.ShareMetadata, session=session,
2554 read_deleted="no").\ 2555 read_deleted="no").
2555 filter_by(share_id=share_id).\ 2556 filter_by(share_id=share_id).
2556 options(joinedload('share')) 2557 options(joinedload('share')))
2557 2558
2558 2559
2559def _share_metadata_get(context, share_id, session=None): 2560def _share_metadata_get(context, share_id, session=None):
@@ -2607,9 +2608,9 @@ def _share_metadata_update(context, share_id, metadata, delete, session=None):
2607 2608
2608 2609
2609def _share_metadata_get_item(context, share_id, key, session=None): 2610def _share_metadata_get_item(context, share_id, key, session=None):
2610 result = _share_metadata_get_query(context, share_id, session=session).\ 2611 result = (_share_metadata_get_query(context, share_id, session=session).
2611 filter_by(key=key).\ 2612 filter_by(key=key).
2612 first() 2613 first())
2613 2614
2614 if not result: 2615 if not result:
2615 raise exception.ShareMetadataNotFound(metadata_key=key, 2616 raise exception.ShareMetadataNotFound(metadata_key=key,
@@ -2925,8 +2926,8 @@ def security_service_update(context, id, values):
2925 2926
2926@require_context 2927@require_context
2927def security_service_get(context, id, session=None): 2928def security_service_get(context, id, session=None):
2928 result = _security_service_get_query(context, session=session).\ 2929 result = (_security_service_get_query(context, session=session).
2929 filter_by(id=id).first() 2930 filter_by(id=id).first())
2930 2931
2931 if result is None: 2932 if result is None:
2932 raise exception.SecurityServiceNotFound(security_service_id=id) 2933 raise exception.SecurityServiceNotFound(security_service_id=id)
@@ -2940,8 +2941,8 @@ def security_service_get_all(context):
2940 2941
2941@require_context 2942@require_context
2942def security_service_get_all_by_project(context, project_id): 2943def security_service_get_all_by_project(context, project_id):
2943 return _security_service_get_query(context).\ 2944 return (_security_service_get_query(context).
2944 filter_by(project_id=project_id).all() 2945 filter_by(project_id=project_id).all())
2945 2946
2946 2947
2947def _security_service_get_query(context, session=None): 2948def _security_service_get_query(context, session=None):
@@ -2956,10 +2957,10 @@ def _security_service_get_query(context, session=None):
2956def _network_get_query(context, session=None): 2957def _network_get_query(context, session=None):
2957 if session is None: 2958 if session is None:
2958 session = get_session() 2959 session = get_session()
2959 return model_query(context, models.ShareNetwork, session=session).\ 2960 return (model_query(context, models.ShareNetwork, session=session).
2960 options(joinedload('share_instances'), 2961 options(joinedload('share_instances'),
2961 joinedload('security_services'), 2962 joinedload('security_services'),
2962 joinedload('share_servers')) 2963 joinedload('share_servers')))
2963 2964
2964 2965
2965@require_context 2966@require_context
@@ -3018,12 +3019,12 @@ def share_network_get_all_by_project(context, project_id, user_id=None,
3018@require_context 3019@require_context
3019def share_network_get_all_by_security_service(context, security_service_id): 3020def share_network_get_all_by_security_service(context, security_service_id):
3020 session = get_session() 3021 session = get_session()
3021 return model_query(context, models.ShareNetwork, session=session).\ 3022 return (model_query(context, models.ShareNetwork, session=session).
3022 join(models.ShareNetworkSecurityServiceAssociation, 3023 join(models.ShareNetworkSecurityServiceAssociation,
3023 models.ShareNetwork.id == 3024 models.ShareNetwork.id ==
3024 models.ShareNetworkSecurityServiceAssociation.share_network_id).\ 3025 models.ShareNetworkSecurityServiceAssociation.share_network_id).
3025 filter_by(security_service_id=security_service_id, deleted=0).\ 3026 filter_by(security_service_id=security_service_id, deleted=0).
3026 options(joinedload('share_servers')).all() 3027 options(joinedload('share_servers')).all())
3027 3028
3028 3029
3029@require_context 3030@require_context
@@ -3031,12 +3032,13 @@ def share_network_add_security_service(context, id, security_service_id):
3031 session = get_session() 3032 session = get_session()
3032 3033
3033 with session.begin(): 3034 with session.begin():
3034 assoc_ref = model_query( 3035 assoc_ref = (model_query(
3035 context, 3036 context,
3036 models.ShareNetworkSecurityServiceAssociation, 3037 models.ShareNetworkSecurityServiceAssociation,
3037 session=session).\ 3038 session=session).
3038 filter_by(share_network_id=id).\ 3039 filter_by(share_network_id=id).
3039 filter_by(security_service_id=security_service_id).first() 3040 filter_by(
3041 security_service_id=security_service_id).first())
3040 3042
3041 if assoc_ref: 3043 if assoc_ref:
3042 msg = "Already associated" 3044 msg = "Already associated"
@@ -3063,12 +3065,12 @@ def share_network_remove_security_service(context, id, security_service_id):
3063 share_nw_ref = share_network_get(context, id, session=session) 3065 share_nw_ref = share_network_get(context, id, session=session)
3064 security_service_get(context, security_service_id, session=session) 3066 security_service_get(context, security_service_id, session=session)
3065 3067
3066 assoc_ref = model_query( 3068 assoc_ref = (model_query(
3067 context, 3069 context,
3068 models.ShareNetworkSecurityServiceAssociation, 3070 models.ShareNetworkSecurityServiceAssociation,
3069 session=session).\ 3071 session=session).
3070 filter_by(share_network_id=id).\ 3072 filter_by(share_network_id=id).
3071 filter_by(security_service_id=security_service_id).first() 3073 filter_by(security_service_id=security_service_id).first())
3072 3074
3073 if assoc_ref: 3075 if assoc_ref:
3074 assoc_ref.soft_delete(session) 3076 assoc_ref.soft_delete(session)
@@ -3088,10 +3090,10 @@ def share_network_remove_security_service(context, id, security_service_id):
3088def _server_get_query(context, session=None): 3090def _server_get_query(context, session=None):
3089 if session is None: 3091 if session is None:
3090 session = get_session() 3092 session = get_session()
3091 return model_query(context, models.ShareServer, session=session).\ 3093 return (model_query(context, models.ShareServer, session=session).
3092 options(joinedload('share_instances'), 3094 options(joinedload('share_instances'),
3093 joinedload('network_allocations'), 3095 joinedload('network_allocations'),
3094 joinedload('share_network')) 3096 joinedload('share_network')))
3095 3097
3096 3098
3097@require_context 3099@require_context
@@ -3128,8 +3130,8 @@ def share_server_update(context, id, values):
3128 3130
3129@require_context 3131@require_context
3130def share_server_get(context, server_id, session=None): 3132def share_server_get(context, server_id, session=None):
3131 result = _server_get_query(context, session).filter_by(id=server_id)\ 3133 result = (_server_get_query(context, session).filter_by(id=server_id)
3132 .first() 3134 .first())
3133 if result is None: 3135 if result is None:
3134 raise exception.ShareServerNotFound(share_server_id=server_id) 3136 raise exception.ShareServerNotFound(share_server_id=server_id)
3135 return result 3137 return result
@@ -3139,10 +3141,11 @@ def share_server_get(context, server_id, session=None):
3139def share_server_get_all_by_host_and_share_net_valid(context, host, 3141def share_server_get_all_by_host_and_share_net_valid(context, host,
3140 share_net_id, 3142 share_net_id,
3141 session=None): 3143 session=None):
3142 result = _server_get_query(context, session).filter_by(host=host)\ 3144 result = (_server_get_query(context, session).filter_by(host=host)
3143 .filter_by(share_network_id=share_net_id)\ 3145 .filter_by(share_network_id=share_net_id)
3144 .filter(models.ShareServer.status.in_( 3146 .filter(models.ShareServer.status.in_(
3145 (constants.STATUS_CREATING, constants.STATUS_ACTIVE))).all() 3147 (constants.STATUS_CREATING,
3148 constants.STATUS_ACTIVE))).all())
3146 if not result: 3149 if not result:
3147 filters_description = ('share_network_id is "%(share_net_id)s",' 3150 filters_description = ('share_network_id is "%(share_net_id)s",'
3148 ' host is "%(host)s" and status in' 3151 ' host is "%(host)s" and status in'
@@ -3174,12 +3177,12 @@ def share_server_get_all_unused_deletable(context, host, updated_before):
3174 constants.STATUS_ACTIVE, 3177 constants.STATUS_ACTIVE,
3175 constants.STATUS_ERROR, 3178 constants.STATUS_ERROR,
3176 ) 3179 )
3177 result = _server_get_query(context)\ 3180 result = (_server_get_query(context)
3178 .filter_by(host=host)\ 3181 .filter_by(host=host)
3179 .filter(~models.ShareServer.share_groups.any())\ 3182 .filter(~models.ShareServer.share_groups.any())
3180 .filter(~models.ShareServer.share_instances.any())\ 3183 .filter(~models.ShareServer.share_instances.any())
3181 .filter(models.ShareServer.status.in_(valid_server_status))\ 3184 .filter(models.ShareServer.status.in_(valid_server_status))
3182 .filter(models.ShareServer.updated_at < updated_before).all() 3185 .filter(models.ShareServer.updated_at < updated_before).all())
3183 return result 3186 return result
3184 3187
3185 3188
@@ -3205,10 +3208,10 @@ def share_server_backend_details_delete(context, share_server_id,
3205 session=None): 3208 session=None):
3206 if not session: 3209 if not session:
3207 session = get_session() 3210 session = get_session()
3208 share_server_details = model_query(context, 3211 share_server_details = (model_query(context,
3209 models.ShareServerBackendDetails, 3212 models.ShareServerBackendDetails,
3210 session=session)\ 3213 session=session)
3211 .filter_by(share_server_id=share_server_id).all() 3214 .filter_by(share_server_id=share_server_id).all())
3212 for item in share_server_details: 3215 for item in share_server_details:
3213 item.soft_delete(session) 3216 item.soft_delete(session)
3214 3217
@@ -3331,8 +3334,8 @@ def network_allocation_delete(context, id):
3331def network_allocation_get(context, id, session=None): 3334def network_allocation_get(context, id, session=None):
3332 if session is None: 3335 if session is None:
3333 session = get_session() 3336 session = get_session()
3334 result = model_query(context, models.NetworkAllocation, session=session).\ 3337 result = (model_query(context, models.NetworkAllocation, session=session).
3335 filter_by(id=id).first() 3338 filter_by(id=id).first())
3336 if result is None: 3339 if result is None:
3337 raise exception.NotFound() 3340 raise exception.NotFound()
3338 return result 3341 return result
@@ -3341,8 +3344,8 @@ def network_allocation_get(context, id, session=None):
3341@require_context 3344@require_context
3342def network_allocations_get_by_ip_address(context, ip_address): 3345def network_allocations_get_by_ip_address(context, ip_address):
3343 session = get_session() 3346 session = get_session()
3344 result = model_query(context, models.NetworkAllocation, session=session).\ 3347 result = (model_query(context, models.NetworkAllocation, session=session).
3345 filter_by(ip_address=ip_address).all() 3348 filter_by(ip_address=ip_address).all())
3346 return result or [] 3349 return result or []
3347 3350
3348 3351
@@ -3440,11 +3443,11 @@ def share_type_create(context, values, projects=None):
3440def _share_type_get_query(context, session=None, read_deleted=None, 3443def _share_type_get_query(context, session=None, read_deleted=None,
3441 expected_fields=None): 3444 expected_fields=None):
3442 expected_fields = expected_fields or [] 3445 expected_fields = expected_fields or []
3443 query = model_query(context, 3446 query = (model_query(context,
3444 models.ShareTypes, 3447 models.ShareTypes,
3445 session=session, 3448 session=session,
3446 read_deleted=read_deleted). \ 3449 read_deleted=read_deleted).
3447 options(joinedload('extra_specs')) 3450 options(joinedload('extra_specs')))
3448 3451
3449 if 'projects' in expected_fields: 3452 if 'projects' in expected_fields:
3450 query = query.options(joinedload('projects')) 3453 query = query.options(joinedload('projects'))
@@ -3492,9 +3495,9 @@ def share_type_get_all(context, inactive=False, filters=None):
3492 3495
3493 3496
3494def _share_type_get_id_from_share_type_query(context, id, session=None): 3497def _share_type_get_id_from_share_type_query(context, id, session=None):
3495 return model_query( 3498 return (model_query(
3496 context, models.ShareTypes, read_deleted="no", session=session).\ 3499 context, models.ShareTypes, read_deleted="no", session=session).
3497 filter_by(id=id) 3500 filter_by(id=id))
3498 3501
3499 3502
3500def _share_type_get_id_from_share_type(context, id, session=None): 3503def _share_type_get_id_from_share_type(context, id, session=None):
@@ -3509,10 +3512,10 @@ def _share_type_get(context, id, session=None, inactive=False,
3509 expected_fields=None): 3512 expected_fields=None):
3510 expected_fields = expected_fields or [] 3513 expected_fields = expected_fields or []
3511 read_deleted = "yes" if inactive else "no" 3514 read_deleted = "yes" if inactive else "no"
3512 result = _share_type_get_query( 3515 result = (_share_type_get_query(
3513 context, session, read_deleted, expected_fields). \ 3516 context, session, read_deleted, expected_fields).
3514 filter_by(id=id). \ 3517 filter_by(id=id).
3515 first() 3518 first())
3516 3519
3517 if not result: 3520 if not result:
3518 raise exception.ShareTypeNotFound(share_type_id=id) 3521 raise exception.ShareTypeNotFound(share_type_id=id)
@@ -3535,10 +3538,10 @@ def share_type_get(context, id, inactive=False, expected_fields=None):
3535 3538
3536 3539
3537def _share_type_get_by_name(context, name, session=None): 3540def _share_type_get_by_name(context, name, session=None):
3538 result = model_query(context, models.ShareTypes, session=session).\ 3541 result = (model_query(context, models.ShareTypes, session=session).
3539 options(joinedload('extra_specs')).\ 3542 options(joinedload('extra_specs')).
3540 filter_by(name=name).\ 3543 filter_by(name=name).
3541 first() 3544 first())
3542 3545
3543 if not result: 3546 if not result:
3544 raise exception.ShareTypeNotFoundByName(share_type_name=name) 3547 raise exception.ShareTypeNotFoundByName(share_type_name=name)
@@ -3572,9 +3575,9 @@ def share_type_destroy(context, id):
3572 session = get_session() 3575 session = get_session()
3573 with session.begin(): 3576 with session.begin():
3574 _share_type_get(context, id, session) 3577 _share_type_get(context, id, session)
3575 results = model_query(context, models.ShareInstance, session=session, 3578 results = (model_query(context, models.ShareInstance, session=session,
3576 read_deleted="no").\ 3579 read_deleted="no").
3577 filter_by(share_type_id=id).count() 3580 filter_by(share_type_id=id).count())
3578 share_group_count = model_query( 3581 share_group_count = model_query(
3579 context, 3582 context,
3580 models.ShareGroupShareTypeMapping, 3583 models.ShareGroupShareTypeMapping,
@@ -3585,10 +3588,10 @@ def share_type_destroy(context, id):
3585 LOG.error('ShareType %s deletion failed, ShareType in use.', 3588 LOG.error('ShareType %s deletion failed, ShareType in use.',
3586 id) 3589 id)
3587 raise exception.ShareTypeInUse(share_type_id=id) 3590 raise exception.ShareTypeInUse(share_type_id=id)
3588 model_query(context, models.ShareTypeExtraSpecs, session=session).\ 3591 (model_query(context, models.ShareTypeExtraSpecs, session=session).
3589 filter_by(share_type_id=id).soft_delete() 3592 filter_by(share_type_id=id).soft_delete())
3590 model_query(context, models.ShareTypes, session=session).\ 3593 (model_query(context, models.ShareTypes, session=session).
3591 filter_by(id=id).soft_delete() 3594 filter_by(id=id).soft_delete())
3592 3595
3593 3596
3594def _share_type_access_query(context, session=None): 3597def _share_type_access_query(context, session=None):
@@ -3599,8 +3602,8 @@ def _share_type_access_query(context, session=None):
3599@require_admin_context 3602@require_admin_context
3600def share_type_access_get_all(context, type_id): 3603def share_type_access_get_all(context, type_id):
3601 share_type_id = _share_type_get_id_from_share_type(context, type_id) 3604 share_type_id = _share_type_get_id_from_share_type(context, type_id)
3602 return _share_type_access_query(context).\ 3605 return (_share_type_access_query(context).
3603 filter_by(share_type_id=share_type_id).all() 3606 filter_by(share_type_id=share_type_id).all())
3604 3607
3605 3608
3606@require_admin_context 3609@require_admin_context
@@ -3627,10 +3630,10 @@ def share_type_access_remove(context, type_id, project_id):
3627 """Remove given tenant from the share type access list.""" 3630 """Remove given tenant from the share type access list."""
3628 share_type_id = _share_type_get_id_from_share_type(context, type_id) 3631 share_type_id = _share_type_get_id_from_share_type(context, type_id)
3629 3632
3630 count = _share_type_access_query(context).\ 3633 count = (_share_type_access_query(context).
3631 filter_by(share_type_id=share_type_id).\ 3634 filter_by(share_type_id=share_type_id).
3632 filter_by(project_id=project_id).\ 3635 filter_by(project_id=project_id).
3633 soft_delete(synchronize_session=False) 3636 soft_delete(synchronize_session=False))
3634 if count == 0: 3637 if count == 0:
3635 raise exception.ShareTypeAccessNotFound( 3638 raise exception.ShareTypeAccessNotFound(
3636 share_type_id=type_id, project_id=project_id) 3639 share_type_id=type_id, project_id=project_id)
@@ -3639,16 +3642,16 @@ def share_type_access_remove(context, type_id, project_id):
3639 3642
3640 3643
3641def _share_type_extra_specs_query(context, share_type_id, session=None): 3644def _share_type_extra_specs_query(context, share_type_id, session=None):
3642 return model_query(context, models.ShareTypeExtraSpecs, session=session, 3645 return (model_query(context, models.ShareTypeExtraSpecs, session=session,
3643 read_deleted="no").\ 3646 read_deleted="no").
3644 filter_by(share_type_id=share_type_id).\ 3647 filter_by(share_type_id=share_type_id).
3645 options(joinedload('share_type')) 3648 options(joinedload('share_type')))
3646 3649
3647 3650
3648@require_context 3651@require_context
3649def share_type_extra_specs_get(context, share_type_id): 3652def share_type_extra_specs_get(context, share_type_id):
3650 rows = _share_type_extra_specs_query(context, share_type_id).\ 3653 rows = (_share_type_extra_specs_query(context, share_type_id).
3651 all() 3654 all())
3652 3655
3653 result = {} 3656 result = {}
3654 for row in rows: 3657 for row in rows:
@@ -3662,8 +3665,8 @@ def share_type_extra_specs_delete(context, share_type_id, key):
3662 session = get_session() 3665 session = get_session()
3663 with session.begin(): 3666 with session.begin():
3664 _share_type_extra_specs_get_item(context, share_type_id, key, session) 3667 _share_type_extra_specs_get_item(context, share_type_id, key, session)
3665 _share_type_extra_specs_query(context, share_type_id, session).\ 3668 (_share_type_extra_specs_query(context, share_type_id, session).
3666 filter_by(key=key).soft_delete() 3669 filter_by(key=key).soft_delete())
3667 3670
3668 3671
3669def _share_type_extra_specs_get_item(context, share_type_id, key, 3672def _share_type_extra_specs_get_item(context, share_type_id, key,
@@ -3827,13 +3830,13 @@ def purge_deleted_records(context, age_in_days):
3827 3830
3828def _share_group_get(context, share_group_id, session=None): 3831def _share_group_get(context, share_group_id, session=None):
3829 session = session or get_session() 3832 session = session or get_session()
3830 result = model_query(context, models.ShareGroup, 3833 result = (model_query(context, models.ShareGroup,
3831 session=session, 3834 session=session,
3832 project_only=True, 3835 project_only=True,
3833 read_deleted='no').\ 3836 read_deleted='no').
3834 filter_by(id=share_group_id).\ 3837 filter_by(id=share_group_id).
3835 options(joinedload('share_types')).\ 3838 options(joinedload('share_types')).
3836 first() 3839 first())
3837 3840
3838 if not result: 3841 if not result:
3839 raise exception.ShareGroupNotFound(share_group_id=share_group_id) 3842 raise exception.ShareGroupNotFound(share_group_id=share_group_id)
@@ -3973,21 +3976,20 @@ def share_group_destroy(context, share_group_id):
3973@require_context 3976@require_context
3974def count_shares_in_share_group(context, share_group_id, session=None): 3977def count_shares_in_share_group(context, share_group_id, session=None):
3975 session = session or get_session() 3978 session = session or get_session()
3976 return model_query( 3979 return (model_query(context, models.Share, session=session,
3977 context, models.Share, session=session, 3980 project_only=True, read_deleted="no").
3978 project_only=True, read_deleted="no").\ 3981 filter_by(share_group_id=share_group_id).
3979 filter_by(share_group_id=share_group_id).\ 3982 count())
3980 count()
3981 3983
3982 3984
3983@require_context 3985@require_context
3984def get_all_shares_by_share_group(context, share_group_id, session=None): 3986def get_all_shares_by_share_group(context, share_group_id, session=None):
3985 session = session or get_session() 3987 session = session or get_session()
3986 return model_query( 3988 return (model_query(
3987 context, models.Share, session=session, 3989 context, models.Share, session=session,
3988 project_only=True, read_deleted="no").\ 3990 project_only=True, read_deleted="no").
3989 filter_by(share_group_id=share_group_id).\ 3991 filter_by(share_group_id=share_group_id).
3990 all() 3992 all())
3991 3993
3992 3994
3993@require_context 3995@require_context
@@ -4006,11 +4008,11 @@ def count_share_group_snapshots_in_share_group(context, share_group_id,
4006def count_share_groups_in_share_network(context, share_network_id, 4008def count_share_groups_in_share_network(context, share_network_id,
4007 session=None): 4009 session=None):
4008 session = session or get_session() 4010 session = session or get_session()
4009 return model_query( 4011 return (model_query(
4010 context, models.ShareGroup, session=session, 4012 context, models.ShareGroup, session=session,
4011 project_only=True, read_deleted="no").\ 4013 project_only=True, read_deleted="no").
4012 filter_by(share_network_id=share_network_id).\ 4014 filter_by(share_network_id=share_network_id).
4013 count() 4015 count())
4014 4016
4015 4017
4016@require_context 4018@require_context