jumpserver/apps/ops/serializers/job.py

44 lines
1.8 KiB
Python
Raw Normal View History

2022-12-02 04:21:56 +00:00
from django.utils.translation import ugettext as _
2022-11-11 11:20:17 +00:00
from rest_framework import serializers
from common.drf.fields import ReadableHiddenField
2022-11-18 10:46:48 +00:00
from ops.mixin import PeriodTaskSerializerMixin
2022-11-11 11:20:17 +00:00
from ops.models import Job, JobExecution
2022-12-16 07:52:02 +00:00
from ops.models.job import JobAuditLog
2022-12-15 09:25:21 +00:00
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
2022-11-11 11:20:17 +00:00
2022-12-15 09:25:21 +00:00
class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
2022-12-02 09:18:11 +00:00
run_after_save = serializers.BooleanField(label=_("Run after save"), read_only=True, default=False, required=False)
2022-11-11 11:20:17 +00:00
class Meta:
model = Job
2022-12-02 09:18:11 +00:00
read_only_fields = ["id", "date_last_run", "date_created", "date_updated", "average_time_cost",
"run_after_save"]
2022-11-18 10:46:48 +00:00
fields = read_only_fields + [
"name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "creator",
"use_parameter_define",
2022-11-17 12:10:13 +00:00
"parameters_define",
"timeout",
"chdir",
"comment",
2022-11-18 10:46:48 +00:00
"summary",
2022-12-02 09:18:11 +00:00
"is_periodic", "interval", "crontab"
2022-11-11 11:20:17 +00:00
]
2022-12-15 09:25:21 +00:00
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
job_type = serializers.ReadOnlyField(label=_("Job type"))
count = serializers.ReadOnlyField(label=_("Count"))
2022-11-11 11:20:17 +00:00
class Meta:
model = JobExecution
read_only_fields = ["id", "task_id", "timedelta", "count", "time_cost", 'is_finished', 'date_start',
'date_finished',
'date_created',
2022-12-16 10:39:59 +00:00
'is_success', 'task_id', 'short_id', 'job_type']
2022-11-11 11:20:17 +00:00
fields = read_only_fields + [
2022-12-16 10:39:59 +00:00
"job", "parameters", "creator"
2022-11-11 11:20:17 +00:00
]