mirror of https://github.com/jumpserver/jumpserver
parent
a255bd21b4
commit
dca92a1e04
|
@ -23,6 +23,7 @@ class PushOrVerifyHostCallbackMixin:
|
||||||
execution: callable
|
execution: callable
|
||||||
host_account_mapper: dict
|
host_account_mapper: dict
|
||||||
ignore_account: bool
|
ignore_account: bool
|
||||||
|
need_privilege_account: bool
|
||||||
generate_public_key: callable
|
generate_public_key: callable
|
||||||
generate_private_key_path: callable
|
generate_private_key_path: callable
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class PushOrVerifyHostCallbackMixin:
|
||||||
return host
|
return host
|
||||||
|
|
||||||
accounts = asset.accounts.all()
|
accounts = asset.accounts.all()
|
||||||
if self.ignore_account and account:
|
if self.need_privilege_account and accounts.count() > 1 and account:
|
||||||
accounts = accounts.exclude(id=account.id)
|
accounts = accounts.exclude(id=account.id)
|
||||||
|
|
||||||
if '*' not in self.execution.snapshot['accounts']:
|
if '*' not in self.execution.snapshot['accounts']:
|
||||||
|
@ -198,6 +199,9 @@ class BasePlaybookManager:
|
||||||
result = cb.host_results.get(host)
|
result = cb.host_results.get(host)
|
||||||
if state == 'ok':
|
if state == 'ok':
|
||||||
self.on_host_success(host, result)
|
self.on_host_success(host, result)
|
||||||
|
elif state == 'skipped':
|
||||||
|
# TODO
|
||||||
|
print('skipped: ', hosts)
|
||||||
else:
|
else:
|
||||||
error = hosts.get(host)
|
error = hosts.get(host)
|
||||||
self.on_host_error(host, error, result)
|
self.on_host_error(host, error, result)
|
||||||
|
|
|
@ -6,7 +6,7 @@ logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PushAccountManager(PushOrVerifyHostCallbackMixin, BasePlaybookManager):
|
class PushAccountManager(PushOrVerifyHostCallbackMixin, BasePlaybookManager):
|
||||||
ignore_account = True
|
need_privilege_account = True
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
|
@ -6,7 +6,7 @@ logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class VerifyAccountManager(PushOrVerifyHostCallbackMixin, BasePlaybookManager):
|
class VerifyAccountManager(PushOrVerifyHostCallbackMixin, BasePlaybookManager):
|
||||||
ignore_account = False
|
need_privilege_account = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
|
@ -9,7 +9,7 @@ __all__ = ['PushAccountAutomation']
|
||||||
class PushAccountAutomation(BaseAutomation):
|
class PushAccountAutomation(BaseAutomation):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.type = AutomationTypes.verify_account
|
self.type = AutomationTypes.push_account
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -65,8 +65,8 @@ class AssetSerializer(OrgResourceSerializerMixin, WritableNestedModelSerializer)
|
||||||
platform = ObjectRelatedField(required=False, queryset=Platform.objects, label=_('Platform'))
|
platform = ObjectRelatedField(required=False, queryset=Platform.objects, label=_('Platform'))
|
||||||
nodes = ObjectRelatedField(many=True, required=False, queryset=Node.objects, label=_('Nodes'))
|
nodes = ObjectRelatedField(many=True, required=False, queryset=Node.objects, label=_('Nodes'))
|
||||||
labels = AssetLabelSerializer(many=True, required=False, label=_('Labels'))
|
labels = AssetLabelSerializer(many=True, required=False, label=_('Labels'))
|
||||||
accounts = AssetAccountSerializer(many=True, required=False, label=_('Accounts'))
|
|
||||||
protocols = AssetProtocolsSerializer(many=True, required=False, label=_('Protocols'))
|
protocols = AssetProtocolsSerializer(many=True, required=False, label=_('Protocols'))
|
||||||
|
accounts = AssetAccountSerializer(many=True, required=False, label=_('Accounts'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Asset
|
model = Asset
|
||||||
|
@ -74,7 +74,7 @@ class AssetSerializer(OrgResourceSerializerMixin, WritableNestedModelSerializer)
|
||||||
fields_small = fields_mini + ['is_active', 'comment']
|
fields_small = fields_mini + ['is_active', 'comment']
|
||||||
fields_fk = ['domain', 'platform', 'platform']
|
fields_fk = ['domain', 'platform', 'platform']
|
||||||
fields_m2m = [
|
fields_m2m = [
|
||||||
'nodes', 'labels', 'accounts', 'protocols', 'nodes_display',
|
'nodes', 'labels', 'protocols', 'accounts', 'nodes_display',
|
||||||
]
|
]
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
'category', 'type', 'specific',
|
'category', 'type', 'specific',
|
||||||
|
|
|
@ -31,7 +31,7 @@ def push_accounts_to_assets_util(accounts, assets):
|
||||||
def push_accounts_to_assets(account_ids, asset_ids):
|
def push_accounts_to_assets(account_ids, asset_ids):
|
||||||
from assets.models import Asset, Account
|
from assets.models import Asset, Account
|
||||||
with tmp_to_root_org():
|
with tmp_to_root_org():
|
||||||
assets = Asset.objects.get(id=asset_ids)
|
assets = Asset.objects.filter(id__in=asset_ids)
|
||||||
accounts = Account.objects.get(id=account_ids)
|
accounts = Account.objects.filter(id__in=account_ids)
|
||||||
|
|
||||||
return push_accounts_to_assets_util(accounts, assets)
|
return push_accounts_to_assets_util(accounts, assets)
|
||||||
|
|
|
@ -30,8 +30,8 @@ def verify_accounts_connectivity_util(accounts, assets, task_name):
|
||||||
def verify_accounts_connectivity(account_ids, asset_ids):
|
def verify_accounts_connectivity(account_ids, asset_ids):
|
||||||
from assets.models import Asset, Account
|
from assets.models import Asset, Account
|
||||||
with tmp_to_root_org():
|
with tmp_to_root_org():
|
||||||
assets = Asset.objects.get(id=asset_ids)
|
assets = Asset.objects.filter(id__in=asset_ids)
|
||||||
accounts = Account.objects.get(id=account_ids)
|
accounts = Account.objects.filter(id__in=account_ids)
|
||||||
|
|
||||||
task_name = gettext_noop("Verify accounts connectivity")
|
task_name = gettext_noop("Verify accounts connectivity")
|
||||||
return verify_accounts_connectivity_util(accounts, assets, task_name)
|
return verify_accounts_connectivity_util(accounts, assets, task_name)
|
||||||
|
|
Loading…
Reference in New Issue