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