From 033d9fc6ceece7951ec089bce1e5d636d205a1d2 Mon Sep 17 00:00:00 2001 From: vapao Date: Mon, 12 Jul 2021 23:30:09 +0800 Subject: [PATCH] fix issue --- spug_api/apps/host/utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/spug_api/apps/host/utils.py b/spug_api/apps/host/utils.py index 6e38a248..5bdd1d7d 100644 --- a/spug_api/apps/host/utils.py +++ b/spug_api/apps/host/utils.py @@ -211,7 +211,7 @@ def fetch_host_extend(ssh): return response -def batch_sync_host(token, hosts, password, ): +def batch_sync_host(token, hosts, password): private_key, public_key = AppSetting.get_ssh_key() threads, latest_exception, rds = [], None, get_redis_connection() max_workers = max(10, os.cpu_count() * 5) @@ -251,15 +251,12 @@ def _sync_host_extend(host, private_key=None, public_key=None, password=None, ss def _get_ssh(kwargs, pkey=None, private_key=None, public_key=None, password=None): try: - if pkey: - ssh = SSH(pkey=pkey, **kwargs) - ssh.ping() - return ssh - else: + ssh = SSH(pkey=pkey or private_key, **kwargs) + ssh.ping() + return ssh + except AuthenticationException as e: + if password: ssh = SSH(password=str(password), **kwargs) ssh.add_public_key(public_key) return _get_ssh(kwargs, private_key) - except AuthenticationException as e: - if password: - return _get_ssh(kwargs, None, public_key, public_key, password) raise e