mirror of https://github.com/jumpserver/jumpserver
perf: 支持发布机仅初始化配置
parent
d71c41e384
commit
d8a891a7d7
|
@ -59,15 +59,18 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
|||
)
|
||||
|
||||
@staticmethod
|
||||
def start_deploy(instance):
|
||||
task = run_applet_host_deployment.apply_async((instance.id,), task_id=str(instance.id))
|
||||
def start_deploy(instance, install_applets):
|
||||
task = run_applet_host_deployment.apply_async((instance.id, install_applets,),
|
||||
task_id=str(instance.id))
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
validated_data = serializer.validated_data
|
||||
install_applets = validated_data.pop('install_applets', True)
|
||||
instance = serializer.save()
|
||||
instance.save_task(instance.id)
|
||||
transaction.on_commit(lambda: self.start_deploy(instance))
|
||||
transaction.on_commit(lambda: self.start_deploy(instance, install_applets))
|
||||
return Response({'task': str(instance.id)}, status=201)
|
||||
|
||||
@action(methods=['post'], detail=False)
|
||||
|
|
|
@ -17,10 +17,12 @@ CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||
|
||||
|
||||
class DeployAppletHostManager:
|
||||
def __init__(self, deployment: AppletHostDeployment, applet: Applet = None):
|
||||
def __init__(self, deployment: AppletHostDeployment, applet: Applet = None,
|
||||
install_applets: bool = True, **kwargs):
|
||||
self.deployment = deployment
|
||||
self.applet = applet
|
||||
self.run_dir = self.get_run_dir()
|
||||
self.install_applets = bool(install_applets)
|
||||
|
||||
@staticmethod
|
||||
def get_run_dir():
|
||||
|
@ -70,6 +72,7 @@ class DeployAppletHostManager:
|
|||
play["vars"]["BOOTSTRAP_TOKEN"] = bootstrap_token
|
||||
play["vars"]["HOST_ID"] = host_id
|
||||
play["vars"]["HOST_NAME"] = hostname
|
||||
play["vars"]["INSTALL_APPLETS"] = self.install_applets
|
||||
return plays
|
||||
|
||||
return self._generate_playbook("playbook.yml", handler)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
RDS_MaxDisconnectionTime: 60000
|
||||
RDS_RemoteAppLogoffTimeLimit: 0
|
||||
TinkerInstaller: Tinker_Installer.exe
|
||||
INSTALL_APPLETS: true
|
||||
|
||||
tasks:
|
||||
- name: Install RDS-RD-Server (RDS)
|
||||
|
@ -273,3 +274,4 @@
|
|||
ansible.windows.win_powershell:
|
||||
script: |
|
||||
tinkerd install all
|
||||
when: INSTALL_APPLETS
|
||||
|
|
|
@ -155,8 +155,8 @@ class AppletHostDeployment(JMSBaseModel):
|
|||
self.host.save()
|
||||
terminal.delete()
|
||||
from ...automations.deploy_applet_host import DeployAppletHostManager
|
||||
manager = DeployAppletHostManager(self)
|
||||
manager.run(**kwargs)
|
||||
manager = DeployAppletHostManager(self, **kwargs)
|
||||
manager.run()
|
||||
|
||||
def install_applet(self, applet_id, **kwargs):
|
||||
from ...automations.deploy_applet_host import DeployAppletHostManager
|
||||
|
|
|
@ -134,6 +134,7 @@ class HostAppletSerializer(AppletSerializer):
|
|||
|
||||
class AppletHostDeploymentSerializer(serializers.ModelSerializer):
|
||||
status = LabeledChoiceField(choices=Status.choices, label=_('Status'), default=Status.pending)
|
||||
install_applets = serializers.BooleanField(default=True, label=_('Install applets'), write_only=True)
|
||||
|
||||
class Meta:
|
||||
model = AppletHostDeployment
|
||||
|
@ -142,7 +143,8 @@ class AppletHostDeploymentSerializer(serializers.ModelSerializer):
|
|||
'status', 'date_created', 'date_updated',
|
||||
'date_start', 'date_finished'
|
||||
]
|
||||
fields = fields_mini + ['comment'] + read_only_fields
|
||||
write_only_fields = ['install_applets',]
|
||||
fields = fields_mini + ['comment'] + read_only_fields + write_only_fields
|
||||
|
||||
|
||||
class AppletHostAccountSerializer(serializers.ModelSerializer):
|
||||
|
|
|
@ -91,10 +91,10 @@ def upload_session_replay_to_external_storage(session_id):
|
|||
verbose_name=_('Run applet host deployment'),
|
||||
activity_callback=lambda self, did, *args, **kwargs: ([did],)
|
||||
)
|
||||
def run_applet_host_deployment(did):
|
||||
def run_applet_host_deployment(did, install_applets):
|
||||
with tmp_to_builtin_org(system=1):
|
||||
deployment = AppletHostDeployment.objects.get(id=did)
|
||||
deployment.start()
|
||||
deployment.start(install_applets=install_applets)
|
||||
|
||||
|
||||
@shared_task(
|
||||
|
|
Loading…
Reference in New Issue