Пример #1
0
def update(context, namespace_name, object_id, values, session):
    """Update an object, raise if ns not found/visible or duplicate result"""
    namespace_api.get(context, namespace_name, session)

    md_object = _get(context, object_id, session)
    metadef_utils.drop_protected_attrs(models.MetadefObject, values)
    # values['updated_at'] = timeutils.utcnow() - done by TS mixin
    try:
        md_object.update(values.copy())
        md_object.save(session=session)
    except db_exc.DBDuplicateEntry:
        msg = ("Invalid update. It would result in a duplicate"
               " metadata definition object with same name=%(name)s"
               " in namespace=%(namespace_name)s." % {
                   'name': md_object.name,
                   'namespace_name': namespace_name
               })
        LOG.debug(msg)
        emsg = (_("Invalid update. It would result in a duplicate"
                  " metadata definition object with the same name=%(name)s"
                  " in namespace=%(namespace_name)s.") % {
                      'name': md_object.name,
                      'namespace_name': namespace_name
                  })
        raise exc.MetadefDuplicateObject(emsg)

    return md_object.to_dict()
Пример #2
0
def create(context, namespace_name, values, session):
    namespace = namespace_api.get(context, namespace_name, session)
    values.update({'namespace_id': namespace['id']})

    md_object = models.MetadefObject()
    metadef_utils.drop_protected_attrs(models.MetadefObject, values)
    md_object.update(values.copy())
    try:
        md_object.save(session=session)
    except db_exc.DBDuplicateEntry:
        msg = ("A metadata definition object with name=%(name)s"
               " in namespace=%(namespace_name)s already exists."
               % {'name': md_object.name,
                  'namespace_name': namespace_name})
        LOG.debug(msg)
        raise exc.MetadefDuplicateObject(
            object_name=md_object.name, namespace_name=namespace_name)

    return md_object.to_dict()