示例#1
0
    def create_audit(self, values):
        # ensure defaults are present for new audits
        if not values.get('uuid'):
            values['uuid'] = utils.generate_uuid()

        query = model_query(models.Audit)
        query = query.filter_by(name=values.get('name'), deleted_at=None)

        if len(query.all()) > 0:
            raise exception.AuditAlreadyExists(audit=values['name'])

        if values.get('state') is None:
            values['state'] = objects.audit.State.PENDING

        if not values.get('auto_trigger'):
            values['auto_trigger'] = False

        try:
            audit = self._create(models.Audit, values)
        except db_exc.DBDuplicateEntry:
            raise exception.AuditAlreadyExists(audit=values['uuid'])
        return audit
示例#2
0
文件: api.py 项目: icclab/watcher
    def create_audit(self, values):
        # ensure defaults are present for new audits
        if not values.get('uuid'):
            values['uuid'] = utils.generate_uuid()

        if values.get('state') is None:
            values['state'] = audit_objects.State.PENDING

        audit = models.Audit()
        audit.update(values)

        try:
            audit.save()
        except db_exc.DBDuplicateEntry:
            raise exception.AuditAlreadyExists(uuid=values['uuid'])
        return audit
示例#3
0
文件: api.py 项目: sue-fly/watcher
    def create_audit(self, values):
        # ensure defaults are present for new audits
        if not values.get('uuid'):
            values['uuid'] = utils.generate_uuid()

        if values.get('state') is None:
            values['state'] = objects.audit.State.PENDING

        if not values.get('auto_trigger'):
            values['auto_trigger'] = False

        try:
            audit = self._create(models.Audit, values)
        except db_exc.DBDuplicateEntry:
            raise exception.AuditAlreadyExists(uuid=values['uuid'])
        return audit