mirror of https://github.com/jumpserver/jumpserver
feat: 支持超时时间设置
parent
ddca4dce41
commit
1cfe8d9cc8
|
@ -8,6 +8,7 @@ class DefaultCallback:
|
||||||
'failed': 'failed',
|
'failed': 'failed',
|
||||||
'running': 'running',
|
'running': 'running',
|
||||||
'pending': 'pending',
|
'pending': 'pending',
|
||||||
|
'timeout': 'timeout',
|
||||||
'unknown': 'unknown'
|
'unknown': 'unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class AdHocRunner:
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/', extra_vars={},
|
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/', extra_vars={},
|
||||||
dry_run=False):
|
dry_run=False, timeout=-1):
|
||||||
self.id = uuid.uuid4()
|
self.id = uuid.uuid4()
|
||||||
self.inventory = inventory
|
self.inventory = inventory
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
|
@ -25,6 +25,7 @@ class AdHocRunner:
|
||||||
self.runner = None
|
self.runner = None
|
||||||
self.extra_vars = extra_vars
|
self.extra_vars = extra_vars
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
def check_module(self):
|
def check_module(self):
|
||||||
if self.module not in self.cmd_modules_choices:
|
if self.module not in self.cmd_modules_choices:
|
||||||
|
@ -41,6 +42,7 @@ class AdHocRunner:
|
||||||
os.mkdir(self.project_dir, 0o755)
|
os.mkdir(self.project_dir, 0o755)
|
||||||
|
|
||||||
ansible_runner.run(
|
ansible_runner.run(
|
||||||
|
timeout=self.timeout if self.timeout > 0 else None,
|
||||||
extravars=self.extra_vars,
|
extravars=self.extra_vars,
|
||||||
host_pattern=self.pattern,
|
host_pattern=self.pattern,
|
||||||
private_data_dir=self.project_dir,
|
private_data_dir=self.project_dir,
|
||||||
|
|
|
@ -7,7 +7,7 @@ from ops.models import Job, JobExecution
|
||||||
from ops.serializers.job import JobSerializer, JobExecutionSerializer
|
from ops.serializers.job import JobSerializer, JobExecutionSerializer
|
||||||
|
|
||||||
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView',
|
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView',
|
||||||
'JobAssetDetail', 'JobExecutionTaskDetail','FrequentUsernames']
|
'JobAssetDetail', 'JobExecutionTaskDetail', 'FrequentUsernames']
|
||||||
|
|
||||||
from ops.tasks import run_ops_job_execution
|
from ops.tasks import run_ops_job_execution
|
||||||
from ops.variables import JMS_JOB_VARIABLE_HELP
|
from ops.variables import JMS_JOB_VARIABLE_HELP
|
||||||
|
@ -110,6 +110,7 @@ class JobExecutionTaskDetail(APIView):
|
||||||
with tmp_to_org(org):
|
with tmp_to_org(org):
|
||||||
execution = get_object_or_404(JobExecution, task_id=task_id)
|
execution = get_object_or_404(JobExecution, task_id=task_id)
|
||||||
return Response(data={
|
return Response(data={
|
||||||
|
'status': execution.status,
|
||||||
'is_finished': execution.is_finished,
|
'is_finished': execution.is_finished,
|
||||||
'is_success': execution.is_success,
|
'is_success': execution.is_success,
|
||||||
'time_cost': execution.time_cost,
|
'time_cost': execution.time_cost,
|
||||||
|
|
|
@ -43,9 +43,11 @@ class RunasPolicies(models.TextChoices):
|
||||||
class Modules(models.TextChoices):
|
class Modules(models.TextChoices):
|
||||||
shell = 'shell', _('Shell')
|
shell = 'shell', _('Shell')
|
||||||
winshell = 'win_shell', _('Powershell')
|
winshell = 'win_shell', _('Powershell')
|
||||||
|
python = 'python', _('Python')
|
||||||
|
|
||||||
|
|
||||||
class JobStatus(models.TextChoices):
|
class JobStatus(models.TextChoices):
|
||||||
running = 'running', _('Running')
|
running = 'running', _('Running')
|
||||||
success = 'success', _('Success')
|
success = 'success', _('Success')
|
||||||
|
timeout = 'timeout', _('Timeout')
|
||||||
failed = 'failed', _('Failed')
|
failed = 'failed', _('Failed')
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Generated by Django 3.2.14 on 2022-12-27 07:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ops', '0034_alter_celerytask_options'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='historicaljob',
|
||||||
|
name='module',
|
||||||
|
field=models.CharField(choices=[('shell', 'Shell'), ('win_shell', 'Powershell'), ('python', 'Python')], default='shell', max_length=128, null=True, verbose_name='Module'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='historicaljob',
|
||||||
|
name='timeout',
|
||||||
|
field=models.IntegerField(default=-1, verbose_name='Timeout (Seconds)'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='job',
|
||||||
|
name='module',
|
||||||
|
field=models.CharField(choices=[('shell', 'Shell'), ('win_shell', 'Powershell'), ('python', 'Python')], default='shell', max_length=128, null=True, verbose_name='Module'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='job',
|
||||||
|
name='timeout',
|
||||||
|
field=models.IntegerField(default=-1, verbose_name='Timeout (Seconds)'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -27,7 +27,7 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin):
|
||||||
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell,
|
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell,
|
||||||
verbose_name=_('Module'), null=True)
|
verbose_name=_('Module'), null=True)
|
||||||
chdir = models.CharField(default="", max_length=1024, verbose_name=_('Chdir'), null=True, blank=True)
|
chdir = models.CharField(default="", max_length=1024, verbose_name=_('Chdir'), null=True, blank=True)
|
||||||
timeout = models.IntegerField(default=60, verbose_name=_('Timeout (Seconds)'))
|
timeout = models.IntegerField(default=-1, verbose_name=_('Timeout (Seconds)'))
|
||||||
playbook = models.ForeignKey('ops.Playbook', verbose_name=_("Playbook"), null=True, on_delete=models.SET_NULL)
|
playbook = models.ForeignKey('ops.Playbook', verbose_name=_("Playbook"), null=True, on_delete=models.SET_NULL)
|
||||||
type = models.CharField(max_length=128, choices=Types.choices, default=Types.adhoc, verbose_name=_("Type"))
|
type = models.CharField(max_length=128, choices=Types.choices, default=Types.adhoc, verbose_name=_("Type"))
|
||||||
creator = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)
|
creator = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)
|
||||||
|
@ -197,6 +197,7 @@ class JobExecution(JMSOrgBaseModel):
|
||||||
runner = AdHocRunner(
|
runner = AdHocRunner(
|
||||||
self.inventory_path,
|
self.inventory_path,
|
||||||
module,
|
module,
|
||||||
|
timeout=self.current_job.timeout,
|
||||||
module_args=args,
|
module_args=args,
|
||||||
pattern="all",
|
pattern="all",
|
||||||
project_dir=self.private_dir,
|
project_dir=self.private_dir,
|
||||||
|
|
Loading…
Reference in New Issue