Merge branch 'v3' of github.com:jumpserver/jumpserver into v3

pull/9029/head
ibuler 2 years ago
commit 2e784311d3

@ -82,10 +82,11 @@ class AssetsTaskMixin:
def perform_assets_task(self, serializer):
data = serializer.validated_data
assets = data.get('assets', [])
asset_ids = [asset.id for asset in assets]
if data['action'] == "refresh":
task = update_assets_hardware_info_manual.delay(assets)
task = update_assets_hardware_info_manual.delay(asset_ids)
else:
task = test_assets_connectivity_manual.delay(assets)
task = test_assets_connectivity_manual.delay(asset_ids)
return task
def perform_create(self, serializer):

@ -221,6 +221,7 @@ class BasePlaybookManager:
else:
print(">>> 开始执行任务\n")
self.execution.date_start = timezone.now()
for i, runner in enumerate(runners, start=1):
if len(runners) > 1:
print(">>> 开始执行第 {} 批任务".format(i))
@ -231,3 +232,5 @@ class BasePlaybookManager:
except Exception as e:
self.on_runner_failed(runner, e)
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 .push_account.manager import PushAccountManager
from .backup_account.manager import AccountBackupManager
from .ping.manager import PingManager
from ..const import AutomationTypes
class ExecutionManager:
manager_type_mapper = {
AutomationTypes.change_secret: ChangeSecretManager,
AutomationTypes.ping: PingManager,
AutomationTypes.push_account: PushAccountManager,
AutomationTypes.gather_facts: GatherFactsManager,
AutomationTypes.gather_accounts: GatherAccountsManager,
AutomationTypes.change_secret: ChangeSecretManager,
AutomationTypes.verify_account: VerifyAccountManager,
AutomationTypes.push_account: PushAccountManager,
AutomationTypes.gather_accounts: GatherAccountsManager,
# TODO 后期迁移到自动化策略中
'backup_account': AccountBackupManager,
}

@ -6,7 +6,6 @@ from common.db.fields import JsonDictTextField
from assets.const import Protocol
__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_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_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_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_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):
@ -61,10 +64,11 @@ class Platform(models.Model):
对资产提供 约束和默认值
对资产进行抽象
"""
CHARSET_CHOICES = (
('utf8', 'UTF-8'),
('gbk', 'GBK'),
)
class CharsetChoices(models.TextChoices):
utf8 = 'utf8', 'UTF-8'
gbk = 'gbk', 'GBK'
name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True)
category = models.CharField(default='host', max_length=32, verbose_name=_("Category"))
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"))
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"))
protocols_enabled = models.BooleanField(default=True, verbose_name=_("Protocols enabled"))
# 账号有关的
@ -103,4 +109,3 @@ class Platform(models.Model):
class Meta:
verbose_name = _("Platform")
# ordering = ('name',)

@ -20,7 +20,7 @@ class AccountBackupPlanSerializer(PeriodTaskSerializerMixin, BulkOrgResourceMode
fields = [
'id', 'name', 'is_periodic', 'interval', 'crontab', 'date_created',
'date_updated', 'created_by', 'periodic_display', 'comment',
'recipients', 'categories'
'recipients', 'types'
]
extra_kwargs = {
'name': {'required': True},

@ -77,7 +77,7 @@ class AssetSerializer(OrgResourceSerializerMixin, WritableNestedModelSerializer)
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
]
read_only_fields = [
'category', 'type', 'specific',
'category', 'type', 'specific', 'info',
'connectivity', 'date_verified',
'created_by', 'date_created',
]

@ -9,3 +9,4 @@ from .gather_facts import *
from .nodes_amount import *
from .push_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_MaxDisconnectionTime: 60000
RDS_RemoteAppLogoffTimeLimit: 0
TinkerInstaller: JumpServer-Remoteapp_v0.0.1.exe
TinkerInstaller: Tinker_Installer_v0.0.1.exe
tasks:
- name: Install RDS-Licensing (RDS)
@ -31,12 +31,12 @@
include_management_tools: yes
register: rds_install
- name: Download JumpServer Remoteapp installer (jumpserver)
- name: Download JumpServer Tinker installer (jumpserver)
ansible.windows.win_get_url:
url: "{{ DownloadHost }}/{{ TinkerInstaller }}"
dest: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
- name: Install JumpServer Remoteapp agent (jumpserver)
- name: Install JumpServer Tinker (jumpserver)
ansible.windows.win_package:
path: "{{ ansible_env.TEMP }}\\{{ TinkerInstaller }}"
arguments:
@ -48,7 +48,7 @@
- name: Set remote-server on the global system path (remote-server)
ansible.windows.win_path:
elements:
- '%USERPROFILE%\AppData\Local\Programs\JumpServer-Remoteapp\'
- '%USERPROFILE%\AppData\Local\Programs\Tinker\'
scope: user
- name: Download python-3.10.8
@ -153,18 +153,18 @@
arguments:
- /quiet
- name: Generate component config
- name: Generate tinkerd component config
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 }}"
- name: Install remoteapp-server service
- name: Install tinkerd service
ansible.windows.win_shell:
"remoteapp-server service install"
"tinkerd service install"
- name: Start remoteapp-server service
- name: Start tinkerd service
ansible.windows.win_shell:
"remoteapp-server service start"
"tinkerd service start"
- name: Wait Tinker api health
ansible.windows.win_uri:

Loading…
Cancel
Save