def attribute_create(self, context, values): if not values.get('uuid'): values['uuid'] = uuidutils.generate_uuid() if values.get('id'): values.pop('id', None) attribute = models.Attribute() attribute.update(values) with _session_for_write() as session: try: session.add(attribute) session.flush() except db_exc.DBDuplicateEntry: raise exception.AttributeAlreadyExists(uuid=values['uuid']) return attribute
def attribute_create(self, context, key, value): update_fields = {'key': key, 'value': value} update_fields['uuid'] = uuidutils.generate_uuid() attribute = models.Attribute() attribute.update(update_fields) with _session_for_write() as session: try: session.add(attribute) session.flush() except db_exc.DBDuplicateEntry: raise exception.AttributeAlreadyExists( uuid=update_fields['uuid']) return attribute