return wrapped
+def handle_db_data_error(f):
+ def wrapper(*args, **kwargs):
+ try:
+ return f(*args, **kwargs)
+ except db_exc.DBDataError:
+ msg = _('Error writing field to database')
+ LOG.exception(msg)
+ raise exception.Invalid(msg)
+
+ return wrapper
+
+
def model_query(context, *args, **kwargs):
"""Query helper that accounts for context's `read_deleted` field.
return volume_ref
+@handle_db_data_error
@require_context
def volume_create(context, values):
values['volume_metadata'] = _metadata_refs(values.get('metadata'),
volume_ref.update(values)
session = get_session()
- try:
- with session.begin():
- session.add(volume_ref)
- except db_exc.DBDataError:
- raise exception.Invalid()
+ with session.begin():
+ session.add(volume_ref)
return _volume_get(context, values['id'], session=session)
return result_keys, result_dirs
+@handle_db_data_error
@require_context
def volume_update(context, volume_id, values):
session = get_session()
###################
+@handle_db_data_error
@require_context
def snapshot_create(context, values):
values['snapshot_metadata'] = _metadata_refs(values.get('metadata'),
return query.all()
+@handle_db_data_error
@require_context
def snapshot_update(context, snapshot_id, values):
session = get_session()
###################
+@handle_db_data_error
@require_admin_context
def volume_type_create(context, values, projects=None):
"""Create a new volume type.
return query
+@handle_db_data_error
@require_admin_context
def volume_type_update(context, volume_type_id, values):
session = get_session()
return result
+@handle_db_data_error
@require_admin_context
def qos_specs_update(context, qos_specs_id, specs):
"""Make updates to an existing qos specs.
'updated_at': literal_column('updated_at')})
+@handle_db_data_error
@require_admin_context
def volume_type_encryption_create(context, volume_type_id, values):
session = get_session()
return encryption
+@handle_db_data_error
@require_admin_context
def volume_type_encryption_update(context, volume_type_id, values):
session = get_session()
return _backup_get_all(context, filters)
+@handle_db_data_error
@require_context
def backup_create(context, values):
backup = models.Backup()
return backup
+@handle_db_data_error
@require_context
def backup_update(context, backup_id, values):
session = get_session()
sort_keys, sort_dirs)
+@handle_db_data_error
@require_context
def consistencygroup_create(context, values):
consistencygroup = models.ConsistencyGroup()
return _consistencygroup_get(context, values['id'], session=session)
+@handle_db_data_error
@require_context
def consistencygroup_update(context, consistencygroup_id, values):
session = get_session()
return _cgsnapshot_get_all(context, project_id=project_id, filters=filters)
+@handle_db_data_error
@require_context
def cgsnapshot_create(context, values):
cgsnapshot = models.Cgsnapshot()
return _cgsnapshot_get(context, values['id'], session=session)
+@handle_db_data_error
@require_context
def cgsnapshot_update(context, cgsnapshot_id, values):
session = get_session()