Ejemplo n.º 1
0
 def get_audit_template_by_id(self, context, audit_template_id):
     query = model_query(models.AuditTemplate)
     query = query.filter_by(id=audit_template_id)
     try:
         audit_template = query.one()
         if not context.show_deleted:
             if audit_template.deleted_at is not None:
                 raise exception.AuditTemplateNotFound(
                     audit_template=audit_template_id)
         return audit_template
     except exc.NoResultFound:
         raise exception.AuditTemplateNotFound(
             audit_template=audit_template_id)
Ejemplo n.º 2
0
 def get_audit_template_by_name(self, context, audit_template_name):
     query = model_query(models.AuditTemplate)
     query = query.filter_by(name=audit_template_name)
     try:
         audit_template = query.one()
         if not context.show_deleted:
             if audit_template.deleted_at is not None:
                 raise exception.AuditTemplateNotFound(
                     audit_template=audit_template_name)
         return audit_template
     except exc.MultipleResultsFound:
         raise exception.Conflict(
             _('Multiple audit templates exist with the same name.'
               ' Please use the audit template uuid instead'))
     except exc.NoResultFound:
         raise exception.AuditTemplateNotFound(
             audit_template=audit_template_name)
Ejemplo n.º 3
0
 def _get_audit_template(self, context, fieldname, value):
     try:
         return self._get(context,
                          model=models.AuditTemplate,
                          fieldname=fieldname,
                          value=value)
     except exception.ResourceNotFound:
         raise exception.AuditTemplateNotFound(audit_template=value)
Ejemplo n.º 4
0
 def update_audit_template(self, audit_template_id, values):
     if 'uuid' in values:
         raise exception.Invalid(
             message=_("Cannot overwrite UUID for an existing "
                       "Audit Template."))
     try:
         return self._update(
             models.AuditTemplate, audit_template_id, values)
     except exception.ResourceNotFound:
         raise exception.AuditTemplateNotFound(
             audit_template=audit_template_id)
Ejemplo n.º 5
0
    def soft_delete_audit_template(self, audit_template_id):
        session = get_session()
        with session.begin():
            query = model_query(models.AuditTemplate, session=session)
            query = add_identity_filter(query, audit_template_id)

            try:
                query.one()
            except exc.NoResultFound:
                raise exception.AuditTemplateNotFound(node=audit_template_id)

            query.soft_delete()
Ejemplo n.º 6
0
    def _do_update_audit_template(self, audit_template_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.AuditTemplate, session=session)
            query = add_identity_filter(query, audit_template_id)
            try:
                ref = query.with_lockmode('update').one()
            except exc.NoResultFound:
                raise exception.AuditTemplateNotFound(
                    audit_template=audit_template_id)

            ref.update(values)
        return ref
Ejemplo n.º 7
0
    def get_audit_template_uuid(cls, uuid_or_name):
        if uuid_or_name is None:
            return

        query_func = None
        if not utils.is_uuid_like(uuid_or_name):
            query_func = objects.audit_template.AuditTemplate.get_by_name
        else:
            query_func = objects.audit_template.AuditTemplate.get_by_uuid

        try:
            audit_template = query_func(cls.ctx, uuid_or_name)
        except Exception as exc:
            LOG.exception(exc)
            raise exception.AuditTemplateNotFound(audit_template=uuid_or_name)

        if not audit_template.deleted_at:
            raise exception.NotSoftDeletedStateError(
                name=_('Audit Template'), id=uuid_or_name)

        return audit_template.uuid
Ejemplo n.º 8
0
 def soft_delete_audit_template(self, audit_template_id):
     try:
         return self._soft_delete(models.AuditTemplate, audit_template_id)
     except exception.ResourceNotFound:
         raise exception.AuditTemplateNotFound(
             audit_template=audit_template_id)