mirror of https://github.com/jumpserver/jumpserver
Merge branch 'v3' of github.com:jumpserver/jumpserver into v3
commit
2e784311d3
|
@ -82,10 +82,11 @@ class AssetsTaskMixin:
|
||||||
def perform_assets_task(self, serializer):
|
def perform_assets_task(self, serializer):
|
||||||
data = serializer.validated_data
|
data = serializer.validated_data
|
||||||
assets = data.get('assets', [])
|
assets = data.get('assets', [])
|
||||||
|
asset_ids = [asset.id for asset in assets]
|
||||||
if data['action'] == "refresh":
|
if data['action'] == "refresh":
|
||||||
task = update_assets_hardware_info_manual.delay(assets)
|
task = update_assets_hardware_info_manual.delay(asset_ids)
|
||||||
else:
|
else:
|
||||||
task = test_assets_connectivity_manual.delay(assets)
|
task = test_assets_connectivity_manual.delay(asset_ids)
|
||||||
return task
|
return task
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
|
|
|
@ -221,6 +221,7 @@ class BasePlaybookManager:
|
||||||
else:
|
else:
|
||||||
print(">>> 开始执行任务\n")
|
print(">>> 开始执行任务\n")
|
||||||
|
|
||||||
|
self.execution.date_start = timezone.now()
|
||||||
for i, runner in enumerate(runners, start=1):
|
for i, runner in enumerate(runners, start=1):
|
||||||
if len(runners) > 1:
|
if len(runners) > 1:
|
||||||
print(">>> 开始执行第 {} 批任务".format(i))
|
print(">>> 开始执行第 {} 批任务".format(i))
|
||||||
|
@ -231,3 +232,5 @@ class BasePlaybookManager:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.on_runner_failed(runner, e)
|
self.on_runner_failed(runner, e)
|
||||||
print('\n')
|
print('\n')
|
||||||
|
self.execution.date_finished = timezone.now()
|
||||||
|
self.execution.save()
|
||||||
|
|
|
@ -4,16 +4,18 @@ from .gather_accounts.manager import GatherAccountsManager
|
||||||
from .verify_account.manager import VerifyAccountManager
|
from .verify_account.manager import VerifyAccountManager
|
||||||
from .push_account.manager import PushAccountManager
|
from .push_account.manager import PushAccountManager
|
||||||
from .backup_account.manager import AccountBackupManager
|
from .backup_account.manager import AccountBackupManager
|
||||||
|
from .ping.manager import PingManager
|
||||||
from ..const import AutomationTypes
|
from ..const import AutomationTypes
|
||||||
|
|
||||||
|
|
||||||
class ExecutionManager:
|
class ExecutionManager:
|
||||||
manager_type_mapper = {
|
manager_type_mapper = {
|
||||||
AutomationTypes.change_secret: ChangeSecretManager,
|
AutomationTypes.ping: PingManager,
|
||||||
AutomationTypes.gather_facts: GatherFactsManager,
|
|
||||||
AutomationTypes.gather_accounts: GatherAccountsManager,
|
|
||||||
AutomationTypes.verify_account: VerifyAccountManager,
|
|
||||||
AutomationTypes.push_account: PushAccountManager,
|
AutomationTypes.push_account: PushAccountManager,
|
||||||
|
AutomationTypes.gather_facts: GatherFactsManager,
|
||||||
|
AutomationTypes.change_secret: ChangeSecretManager,
|
||||||
|
AutomationTypes.verify_account: VerifyAccountManager,
|
||||||
|
AutomationTypes.gather_accounts: GatherAccountsManager,
|
||||||
# TODO 后期迁移到自动化策略中
|
# TODO 后期迁移到自动化策略中
|
||||||
'backup_account': AccountBackupManager,
|
'backup_account': AccountBackupManager,
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ from common.db.fields import JsonDictTextField
|
||||||
|
|
||||||
from assets.const import Protocol
|
from assets.const import Protocol
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Platform', 'PlatformProtocol', 'PlatformAutomation']
|
__all__ = ['Platform', 'PlatformProtocol', 'PlatformAutomation']
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,11 +48,15 @@ class PlatformAutomation(models.Model):
|
||||||
push_account_enabled = models.BooleanField(default=False, verbose_name=_("Push account enabled"))
|
push_account_enabled = models.BooleanField(default=False, verbose_name=_("Push account enabled"))
|
||||||
push_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Push account method"))
|
push_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Push account method"))
|
||||||
change_secret_enabled = models.BooleanField(default=False, verbose_name=_("Change password enabled"))
|
change_secret_enabled = models.BooleanField(default=False, verbose_name=_("Change password enabled"))
|
||||||
change_secret_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Change password method"))
|
change_secret_method = models.TextField(
|
||||||
|
max_length=32, blank=True, null=True, verbose_name=_("Change password method"))
|
||||||
verify_account_enabled = models.BooleanField(default=False, verbose_name=_("Verify account enabled"))
|
verify_account_enabled = models.BooleanField(default=False, verbose_name=_("Verify account enabled"))
|
||||||
verify_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Verify account method"))
|
verify_account_method = models.TextField(
|
||||||
|
max_length=32, blank=True, null=True, verbose_name=_("Verify account method"))
|
||||||
gather_accounts_enabled = models.BooleanField(default=False, verbose_name=_("Gather facts enabled"))
|
gather_accounts_enabled = models.BooleanField(default=False, verbose_name=_("Gather facts enabled"))
|
||||||
gather_accounts_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Gather facts method"))
|
gather_accounts_method = models.TextField(
|
||||||
|
max_length=32, blank=True, null=True, verbose_name=_("Gather facts method")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Platform(models.Model):
|
class Platform(models.Model):
|
||||||
|
@ -61,10 +64,11 @@ class Platform(models.Model):
|
||||||
对资产提供 约束和默认值
|
对资产提供 约束和默认值
|
||||||
对资产进行抽象
|
对资产进行抽象
|
||||||
"""
|
"""
|
||||||
CHARSET_CHOICES = (
|
|
||||||
('utf8', 'UTF-8'),
|
class CharsetChoices(models.TextChoices):
|
||||||
('gbk', 'GBK'),
|
utf8 = 'utf8', 'UTF-8'
|
||||||
)
|
gbk = 'gbk', 'GBK'
|
||||||
|
|
||||||
name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True)
|
name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True)
|
||||||
category = models.CharField(default='host', max_length=32, verbose_name=_("Category"))
|
category = models.CharField(default='host', max_length=32, verbose_name=_("Category"))
|
||||||
type = models.CharField(max_length=32, default='linux', verbose_name=_("Type"))
|
type = models.CharField(max_length=32, default='linux', verbose_name=_("Type"))
|
||||||
|
@ -72,7 +76,9 @@ class Platform(models.Model):
|
||||||
internal = models.BooleanField(default=False, verbose_name=_("Internal"))
|
internal = models.BooleanField(default=False, verbose_name=_("Internal"))
|
||||||
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
|
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
|
||||||
# 资产有关的
|
# 资产有关的
|
||||||
charset = models.CharField(default='utf8', choices=CHARSET_CHOICES, max_length=8, verbose_name=_("Charset"))
|
charset = models.CharField(
|
||||||
|
default=CharsetChoices.utf8, choices=CharsetChoices.choices, max_length=8, verbose_name=_("Charset")
|
||||||
|
)
|
||||||
domain_enabled = models.BooleanField(default=True, verbose_name=_("Domain enabled"))
|
domain_enabled = models.BooleanField(default=True, verbose_name=_("Domain enabled"))
|
||||||
protocols_enabled = models.BooleanField(default=True, verbose_name=_("Protocols enabled"))
|
protocols_enabled = models.BooleanField(default=True, verbose_name=_("Protocols enabled"))
|
||||||
# 账号有关的
|
# 账号有关的
|
||||||
|
@ -103,4 +109,3 @@ class Platform(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Platform")
|
verbose_name = _("Platform")
|
||||||
# ordering = ('name',)
|
# ordering = ('name',)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AccountBackupPlanSerializer(PeriodTaskSerializerMixin, BulkOrgResourceMode
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'name', 'is_periodic', 'interval', 'crontab', 'date_created',
|
'id', 'name', 'is_periodic', 'interval', 'crontab', 'date_created',
|
||||||
'date_updated', 'created_by', 'periodic_display', 'comment',
|
'date_updated', 'created_by', 'periodic_display', 'comment',
|
||||||
'recipients', 'categories'
|
'recipients', 'types'
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'name': {'required': True},
|
'name': {'required': True},
|
||||||
|
|
|
@ -77,7 +77,7 @@ class AssetSerializer(OrgResourceSerializerMixin, WritableNestedModelSerializer)
|
||||||
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
|
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
|
||||||
]
|
]
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
'category', 'type', 'specific',
|
'category', 'type', 'specific', 'info',
|
||||||
'connectivity', 'date_verified',
|
'connectivity', 'date_verified',
|
||||||
'created_by', 'date_created',
|
'created_by', 'date_created',
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,3 +9,4 @@ from .gather_facts import *
|
||||||
from .nodes_amount import *
|
from .nodes_amount import *
|
||||||
from .push_account import *
|
from .push_account import *
|
||||||
from .verify_account import *
|
from .verify_account import *
|
||||||
|
from .gather_accounts import *
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# ~*~ coding: utf-8 ~*~
|
||||||
|
from celery import shared_task
|
||||||
|
from django.utils.translation import gettext_noop
|
||||||
|
|
||||||
|
from orgs.utils import tmp_to_root_org, org_aware_func
|
||||||
|
from common.utils import get_logger
|
||||||
|
from assets.models import Node
|
||||||
|
|
||||||
|
__all__ = ['gather_asset_accounts']
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@org_aware_func("nodes")
|
||||||
|
def gather_asset_accounts_util(nodes, task_name):
|
||||||
|
from assets.models import GatherAccountsAutomation
|
||||||
|
task_name = GatherAccountsAutomation.generate_unique_name(task_name)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'name': task_name,
|
||||||
|
'comment': ', '.join([str(i) for i in nodes])
|
||||||
|
}
|
||||||
|
instance = GatherAccountsAutomation.objects.create(**data)
|
||||||
|
instance.nodes.add(*nodes)
|
||||||
|
instance.execute()
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task(queue="ansible")
|
||||||
|
def gather_asset_accounts(node_ids, task_name=None):
|
||||||
|
if task_name is None:
|
||||||
|
task_name = gettext_noop("Gather assets accounts")
|
||||||
|
|
||||||
|
with tmp_to_root_org():
|
||||||
|
nodes = Node.objects.filter(id__in=node_ids)
|
||||||
|
gather_asset_accounts_util(nodes=nodes, task_name=task_name)
|
|
@ -14,7 +14,7 @@
|
||||||
RDS_fSingleSessionPerUser: 1
|
RDS_fSingleSessionPerUser: 1
|
||||||
RDS_MaxDisconnectionTime: 60000
|
RDS_MaxDisconnectionTime: 60000
|
||||||
RDS_RemoteAppLogoffTimeLimit: 0
|
RDS_RemoteAppLogoffTimeLimit: 0
|
||||||
TinkerInstaller: JumpServer-Remoteapp_v0.0.1.exe
|
TinkerInstaller: Tinker_Installer_v0.0.1.exe
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Install RDS-Licensing (RDS)
|
- name: Install RDS-Licensing (RDS)
|
||||||
|
@ -31,12 +31,12 @@
|
||||||
include_management_tools: yes
|
include_management_tools: yes
|
||||||
register: rds_install
|
register: rds_install
|
||||||
|
|
||||||
- name: Download JumpServer Remoteapp installer (jumpserver)
|
- name: Download JumpServer Tinker installer (jumpserver)
|
||||||
ansible.windows.win_get_url:
|
ansible.windows.win_get_url:
|
||||||
url: "{{ DownloadHost }}/{{ TinkerInstaller }}"
|
url: "{{ DownloadHost }}/{{ TinkerInstaller }}"
|
||||||
dest: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
|
dest: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
|
||||||
|
|
||||||
- name: Install JumpServer Remoteapp agent (jumpserver)
|
- name: Install JumpServer Tinker (jumpserver)
|
||||||
ansible.windows.win_package:
|
ansible.windows.win_package:
|
||||||
path: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
|
path: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
|
||||||
arguments:
|
arguments:
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
- name: Set remote-server on the global system path (remote-server)
|
- name: Set remote-server on the global system path (remote-server)
|
||||||
ansible.windows.win_path:
|
ansible.windows.win_path:
|
||||||
elements:
|
elements:
|
||||||
- '%USERPROFILE%\AppData\Local\Programs\JumpServer-Remoteapp\'
|
- '%USERPROFILE%\AppData\Local\Programs\Tinker\'
|
||||||
scope: user
|
scope: user
|
||||||
|
|
||||||
- name: Download python-3.10.8
|
- name: Download python-3.10.8
|
||||||
|
@ -153,18 +153,18 @@
|
||||||
arguments:
|
arguments:
|
||||||
- /quiet
|
- /quiet
|
||||||
|
|
||||||
- name: Generate component config
|
- name: Generate tinkerd component config
|
||||||
ansible.windows.win_shell:
|
ansible.windows.win_shell:
|
||||||
"remoteapp-server config --hostname {{ HOST_NAME }} --core_host {{ CORE_HOST }}
|
"tinkerd config --hostname {{ HOST_NAME }} --core_host {{ CORE_HOST }}
|
||||||
--token {{ BOOTSTRAP_TOKEN }} --host_id {{ HOST_ID }}"
|
--token {{ BOOTSTRAP_TOKEN }} --host_id {{ HOST_ID }}"
|
||||||
|
|
||||||
- name: Install remoteapp-server service
|
- name: Install tinkerd service
|
||||||
ansible.windows.win_shell:
|
ansible.windows.win_shell:
|
||||||
"remoteapp-server service install"
|
"tinkerd service install"
|
||||||
|
|
||||||
- name: Start remoteapp-server service
|
- name: Start tinkerd service
|
||||||
ansible.windows.win_shell:
|
ansible.windows.win_shell:
|
||||||
"remoteapp-server service start"
|
"tinkerd service start"
|
||||||
|
|
||||||
- name: Wait Tinker api health
|
- name: Wait Tinker api health
|
||||||
ansible.windows.win_uri:
|
ansible.windows.win_uri:
|
||||||
|
|
Loading…
Reference in New Issue