"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "manila/db/sqlalchemy/api.py" between
manila-11.0.0.tar.gz and manila-11.0.1.tar.gz

About: OpenStack Manila provides “Shared Filesystems as a service”.
The "Victoria" series (latest release).

api.py  (manila-11.0.0):api.py  (manila-11.0.1)
skipping to change at line 196 skipping to change at line 196
wrapper.__name__ = f.__name__ wrapper.__name__ = f.__name__
return wrapper return wrapper
def apply_sorting(model, query, sort_key, sort_dir): def apply_sorting(model, query, sort_key, sort_dir):
if sort_dir.lower() not in ('desc', 'asc'): if sort_dir.lower() not in ('desc', 'asc'):
msg = _("Wrong sorting data provided: sort key is '%(sort_key)s' " msg = _("Wrong sorting data provided: sort key is '%(sort_key)s' "
"and sort direction is '%(sort_dir)s'.") % { "and sort direction is '%(sort_dir)s'.") % {
"sort_key": sort_key, "sort_dir": sort_dir} "sort_key": sort_key, "sort_dir": sort_dir}
raise exception.InvalidInput(reason=msg) raise exception.InvalidInput(reason=msg)
sort_attr = getattr(model, sort_key) # NOTE(maaoyu): We add the additional sort by ID in this case to
sort_method = getattr(sort_attr, sort_dir.lower()) # get deterministic results. Without the ordering by ID this could
return query.order_by(sort_method()) # lead to flapping return lists.
sort_keys = [sort_key]
if sort_key != 'id':
sort_keys.append('id')
for sort_key in sort_keys:
sort_attr = getattr(model, sort_key)
sort_method = getattr(sort_attr, sort_dir.lower())
query = query.order_by(sort_method())
return query
def handle_db_data_error(f): def handle_db_data_error(f):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
try: try:
return f(*args, **kwargs) return f(*args, **kwargs)
except db_exc.DBDataError: except db_exc.DBDataError:
msg = _('Error writing field to database.') msg = _('Error writing field to database.')
LOG.exception(msg) LOG.exception(msg)
raise exception.Invalid(msg) raise exception.Invalid(msg)
skipping to change at line 1494 skipping to change at line 1504
export_location_path) export_location_path)
if export_location_id: if export_location_id:
query = query.filter( query = query.filter(
models.ShareInstanceExportLocations.uuid == models.ShareInstanceExportLocations.uuid ==
export_location_id) export_location_id)
instance_ids = filters.get('instance_ids') instance_ids = filters.get('instance_ids')
if instance_ids: if instance_ids:
query = query.filter(models.ShareInstance.id.in_(instance_ids)) query = query.filter(models.ShareInstance.id.in_(instance_ids))
# TODO(gouthamr): This DB API method needs to be generalized for all
# share instance fields.
host = filters.get('host')
if host:
query = query.filter(
or_(models.ShareInstance.host == host,
models.ShareInstance.host.like("{0}#%".format(host)))
)
share_server_id = filters.get('share_server_id')
if share_server_id:
query = query.filter(
models.ShareInstance.share_server_id == share_server_id)
# Returns list of share instances that satisfy filters. # Returns list of share instances that satisfy filters.
query = query.all() query = query.all()
return query return query
@require_context @require_context
def _update_share_instance_usages(context, share, instance_ref, def _update_share_instance_usages(context, share, instance_ref,
is_replica=False): is_replica=False):
deltas = {} deltas = {}
no_instances_remain = len(share.instances) == 0 no_instances_remain = len(share.instances) == 0
share_usages_to_release = {"shares": -1, "gigabytes": -share['size']} share_usages_to_release = {"shares": -1, "gigabytes": -share['size']}
skipping to change at line 1793 skipping to change at line 1816
def share_replica_delete(context, share_replica_id, session=None, def share_replica_delete(context, share_replica_id, session=None,
need_to_update_usages=True): need_to_update_usages=True):
"""Deletes a share replica.""" """Deletes a share replica."""
session = session or get_session() session = session or get_session()
share_instance_delete(context, share_replica_id, session=session, share_instance_delete(context, share_replica_id, session=session,
need_to_update_usages=need_to_update_usages) need_to_update_usages=need_to_update_usages)
################ ################
@require_context
def _share_get_query(context, session=None): def _share_get_query(context, session=None):
if session is None: if session is None:
session = get_session() session = get_session()
return (model_query(context, models.Share, session=session). return (model_query(context, models.Share, session=session).
options(joinedload('share_metadata'))) options(joinedload('share_metadata')))
def _process_share_filters(query, filters, project_id=None, is_public=False):
if filters is None:
filters = {}
share_filter_keys = ['share_group_id', 'snapshot_id']
instance_filter_keys = ['share_server_id', 'status', 'share_type_id',
'host', 'share_network_id']
share_filters = {}
instance_filters = {}
for k, v in filters.items():
share_filters.update({k: v}) if k in share_filter_keys else None
instance_filters.update({k: v}) if k in instance_filter_keys else None
no_key = 'key_is_absent'
def _filter_data(query, model, desired_filters):
for key, value in desired_filters.items():
filter_attr = getattr(model, key, no_key)
if filter_attr == no_key:
pass
query = query.filter(filter_attr == value)
return query
if share_filters:
query = _filter_data(query, models.Share, share_filters)
if instance_filters:
query = _filter_data(query, models.ShareInstance, instance_filters)
if project_id:
if is_public:
query = query.filter(or_(models.Share.project_id == project_id,
models.Share.is_public))
else:
query = query.filter(models.Share.project_id == project_id)
display_name = filters.get('display_name')
if display_name:
query = query.filter(
models.Share.display_name == display_name)
else:
display_name = filters.get('display_name~')
if display_name:
query = query.filter(models.Share.display_name.op('LIKE')(
u'%' + display_name + u'%'))
display_description = filters.get('display_description')
if display_description:
query = query.filter(
models.Share.display_description == display_description)
else:
display_description = filters.get('display_description~')
if display_description:
query = query.filter(models.Share.display_description.op('LIKE')(
u'%' + display_description + u'%'))
export_location_id = filters.pop('export_location_id', None)
export_location_path = filters.pop('export_location_path', None)
if export_location_id or export_location_path:
query = query.join(
models.ShareInstanceExportLocations,
models.ShareInstanceExportLocations.share_instance_id ==
models.ShareInstance.id)
if export_location_path:
query = query.filter(
models.ShareInstanceExportLocations.path ==
export_location_path)
if export_location_id:
query = query.filter(
models.ShareInstanceExportLocations.uuid ==
export_location_id)
if 'metadata' in filters:
for k, v in filters['metadata'].items():
# pylint: disable=no-member
query = query.filter(
or_(models.Share.share_metadata.any(
key=k, value=v)))
if 'extra_specs' in filters:
query = query.join(
models.ShareTypeExtraSpecs,
models.ShareTypeExtraSpecs.share_type_id ==
models.ShareInstance.share_type_id)
for k, v in filters['extra_specs'].items():
query = query.filter(or_(models.ShareTypeExtraSpecs.key == k,
models.ShareTypeExtraSpecs.value == v))
return query
def _metadata_refs(metadata_dict, meta_class): def _metadata_refs(metadata_dict, meta_class):
metadata_refs = [] metadata_refs = []
if metadata_dict: if metadata_dict:
for k, v in metadata_dict.items(): for k, v in metadata_dict.items():
value = six.text_type(v) if isinstance(v, bool) else v value = six.text_type(v) if isinstance(v, bool) else v
metadata_ref = meta_class() metadata_ref = meta_class()
metadata_ref['key'] = k metadata_ref['key'] = k
metadata_ref['value'] = value metadata_ref['value'] = value
metadata_refs.append(metadata_ref) metadata_refs.append(metadata_ref)
skipping to change at line 1898 skipping to change at line 2011
:param project_id: project id that owns shares :param project_id: project id that owns shares
:param share_server_id: share server that hosts shares :param share_server_id: share server that hosts shares
:param filters: dict of filters to specify share selection :param filters: dict of filters to specify share selection
:param is_public: public shares from other projects will be added :param is_public: public shares from other projects will be added
to result if True to result if True
:param sort_key: key of models.Share to be used for sorting :param sort_key: key of models.Share to be used for sorting
:param sort_dir: desired direction of sorting, can be 'asc' and 'desc' :param sort_dir: desired direction of sorting, can be 'asc' and 'desc'
:returns: list -- models.Share :returns: list -- models.Share
:raises: exception.InvalidInput :raises: exception.InvalidInput
""" """
if filters is None:
filters = {}
if not sort_key: if not sort_key:
sort_key = 'created_at' sort_key = 'created_at'
if not sort_dir: if not sort_dir:
sort_dir = 'desc' sort_dir = 'desc'
query = ( query = (
_share_get_query(context).join( _share_get_query(context).join(
models.ShareInstance, models.ShareInstance,
models.ShareInstance.share_id == models.Share.id models.ShareInstance.share_id == models.Share.id
) )
) )
if project_id:
if is_public:
query = query.filter(or_(models.Share.project_id == project_id,
models.Share.is_public))
else:
query = query.filter(models.Share.project_id == project_id)
if share_server_id:
query = query.filter(
models.ShareInstance.share_server_id == share_server_id)
if share_group_id: if share_group_id:
query = query.filter( filters['share_group_id'] = share_group_id
models.Share.share_group_id == share_group_id) if share_server_id:
filters['share_server_id'] = share_server_id
# Apply filters
if not filters:
filters = {}
export_location_id = filters.get('export_location_id')
export_location_path = filters.get('export_location_path')
if export_location_id or export_location_path:
query = query.join(
models.ShareInstanceExportLocations,
models.ShareInstanceExportLocations.share_instance_id ==
models.ShareInstance.id)
if export_location_path:
query = query.filter(
models.ShareInstanceExportLocations.path ==
export_location_path)
if export_location_id:
query = query.filter(
models.ShareInstanceExportLocations.uuid ==
export_location_id)
if 'metadata' in filters: query = _process_share_filters(
for k, v in filters['metadata'].items(): query, filters, project_id, is_public=is_public)
# pylint: disable=no-member
query = query.filter(
or_(models.Share.share_metadata.any(
key=k, value=v)))
if 'extra_specs' in filters:
query = query.join(
models.ShareTypeExtraSpecs,
models.ShareTypeExtraSpecs.share_type_id ==
models.ShareInstance.share_type_id)
for k, v in filters['extra_specs'].items():
query = query.filter(or_(models.ShareTypeExtraSpecs.key == k,
models.ShareTypeExtraSpecs.value == v))
try: try:
query = apply_sorting(models.Share, query, sort_key, sort_dir) query = apply_sorting(models.Share, query, sort_key, sort_dir)
except AttributeError: except AttributeError:
try: try:
query = apply_sorting( query = apply_sorting(
models.ShareInstance, query, sort_key, sort_dir) models.ShareInstance, query, sort_key, sort_dir)
except AttributeError: except AttributeError:
msg = _("Wrong sorting key provided - '%s'.") % sort_key msg = _("Wrong sorting key provided - '%s'.") % sort_key
raise exception.InvalidInput(reason=msg) raise exception.InvalidInput(reason=msg)
skipping to change at line 1978 skipping to change at line 2053
if 'limit' in filters: if 'limit' in filters:
offset = filters.get('offset', 0) offset = filters.get('offset', 0)
query = query.limit(filters['limit']).offset(offset) query = query.limit(filters['limit']).offset(offset)
# Returns list of shares that satisfy filters. # Returns list of shares that satisfy filters.
query = query.all() query = query.all()
return query return query
@require_admin_context @require_admin_context
def share_get_all(context, filters=None, sort_key=None, sort_dir=None): def share_get_all(context, filters=None, sort_key=None, sort_dir=None):
project_id = filters.pop('project_id', None) if filters else None
query = _share_get_all_with_filters( query = _share_get_all_with_filters(
context, filters=filters, sort_key=sort_key, sort_dir=sort_dir) context,
project_id=project_id,
filters=filters, sort_key=sort_key, sort_dir=sort_dir)
return query return query
@require_context @require_context
def share_get_all_by_project(context, project_id, filters=None, def share_get_all_by_project(context, project_id, filters=None,
is_public=False, sort_key=None, sort_dir=None): is_public=False, sort_key=None, sort_dir=None):
"""Returns list of shares with given project ID.""" """Returns list of shares with given project ID."""
query = _share_get_all_with_filters( query = _share_get_all_with_filters(
context, project_id=project_id, filters=filters, is_public=is_public, context, project_id=project_id, filters=filters, is_public=is_public,
sort_key=sort_key, sort_dir=sort_dir, sort_key=sort_key, sort_dir=sort_dir,
) )
 End of changes. 10 change blocks. 
50 lines changed or deleted 129 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)