Perf: 优化

pull/10104/head
jiangweidong 2023-04-03 09:57:40 +08:00
parent cfe0206179
commit 6aaa20ba17
2 changed files with 5 additions and 9 deletions

View File

@ -252,12 +252,8 @@ class BasePlaybookManager:
print('\033[31m %s \033[0m\n' % err_msg)
not_valid.append(k)
else:
if host['ansible_connection'] == 'winrm':
host['ansible_host'] = '127.0.0.1'
host['ansible_port'] = server.local_bind_port
else:
jms_asset['address'] = '127.0.0.1'
jms_asset['port'] = server.local_bind_port
host['ansible_host'] = jms_asset['address'] = '127.0.0.1'
host['ansible_port'] = jms_asset['port'] = server.local_bind_port
servers.append(server)
# 网域不可连接的,就不继续执行此资源的后续任务了

View File

@ -120,7 +120,7 @@ class JMSInventory:
def fill_ansible_config(ansible_config, protocol):
if protocol.name in ('ssh', 'winrm'):
ansible_config['ansible_connection'] = protocol.name
if protocol and protocol.name == 'winrm':
if protocol.name == 'winrm':
if protocol.setting.get('use_ssl', False):
ansible_config['ansible_winrm_scheme'] = 'https'
ansible_config['ansible_winrm_transport'] = 'ssl'
@ -211,7 +211,7 @@ class JMSInventory:
return None
@staticmethod
def _fill_attr_from_platform(asset, platform_protocols):
def set_platform_protocol_setting_to_asset(asset, platform_protocols):
asset_protocols = asset.protocols.all()
for p in asset_protocols:
setattr(p, 'setting', platform_protocols.get(p.name, {}))
@ -226,7 +226,7 @@ class JMSInventory:
p['name']: p['setting'] for p in platform.protocols.values('name', 'setting')
}
for asset in assets:
protocols = self._fill_attr_from_platform(asset, platform_protocols)
protocols = self.set_platform_protocol_setting_to_asset(asset, platform_protocols)
account = self.select_account(asset)
host = self.asset_to_host(asset, account, automation, protocols, platform)