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
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
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