mirror of https://github.com/jumpserver/jumpserver
Merge branch 'v3' of github.com:jumpserver/jumpserver into v3
commit
3abf2592d1
|
@ -5,7 +5,6 @@ from rest_framework import status, mixins, viewsets
|
||||||
|
|
||||||
from orgs.mixins import generics
|
from orgs.mixins import generics
|
||||||
from assets import serializers
|
from assets import serializers
|
||||||
from assets.const import AutomationTypes
|
|
||||||
from assets.tasks import execute_automation
|
from assets.tasks import execute_automation
|
||||||
from assets.models import BaseAutomation, AutomationExecution
|
from assets.models import BaseAutomation, AutomationExecution
|
||||||
from common.const.choices import Trigger
|
from common.const.choices import Trigger
|
||||||
|
@ -111,8 +110,7 @@ class AutomationExecutionViewSet(
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
automation = serializer.validated_data.get('automation')
|
automation = serializer.validated_data.get('automation')
|
||||||
tp = serializer.validated_data.get('type')
|
tp = serializer.validated_data.get('type')
|
||||||
model = AutomationTypes.get_type_model(tp)
|
|
||||||
task = execute_automation.delay(
|
task = execute_automation.delay(
|
||||||
pid=automation.pk, trigger=Trigger.manual, model=model
|
pid=automation.pk, trigger=Trigger.manual, tp=tp
|
||||||
)
|
)
|
||||||
return Response({'task': task.id}, status=status.HTTP_201_CREATED)
|
return Response({'task': task.id}, status=status.HTTP_201_CREATED)
|
||||||
|
|
|
@ -47,7 +47,7 @@ class BaseAutomation(CommonModelMixin, PeriodTaskModelMixin, OrgModelMixin):
|
||||||
def get_register_task(self):
|
def get_register_task(self):
|
||||||
name = f"automation_{self.type}_strategy_period_{str(self.id)[:8]}"
|
name = f"automation_{self.type}_strategy_period_{str(self.id)[:8]}"
|
||||||
task = execute_automation.name
|
task = execute_automation.name
|
||||||
args = (str(self.id), Trigger.timing, self._meta.model)
|
args = (str(self.id), Trigger.timing, self.type)
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
return name, task, args, kwargs
|
return name, task, args, kwargs
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@ from celery import shared_task
|
||||||
|
|
||||||
from orgs.utils import tmp_to_root_org, tmp_to_org
|
from orgs.utils import tmp_to_root_org, tmp_to_org
|
||||||
from common.utils import get_logger, get_object_or_none
|
from common.utils import get_logger, get_object_or_none
|
||||||
|
from assets.const import AutomationTypes
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
|
|
||||||
@shared_task(queue='ansible')
|
@shared_task(queue='ansible')
|
||||||
def execute_automation(pid, trigger, model):
|
def execute_automation(pid, trigger, tp):
|
||||||
|
model = AutomationTypes.get_model(tp)
|
||||||
with tmp_to_root_org():
|
with tmp_to_root_org():
|
||||||
instance = get_object_or_none(model, pk=pid)
|
instance = get_object_or_none(model, pk=pid)
|
||||||
if not instance:
|
if not instance:
|
||||||
|
|
Loading…
Reference in New Issue