Skip to content

Commit 389bbd7

Browse files
author
gitlab
committed
Merge branch 'master' into 'master'
<fix>[ansible]: Optimize kvm host reconnection See merge request zstackio/zstack-utility!3284
2 parents 2c28272 + fecb3df commit 389bbd7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

kvmagent/ansible/kvm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def check_nested_kvm(host_post_info):
149149
modprobe_arg.state = 'present'
150150
modprobe(modprobe_arg, host_post_info)
151151

152+
152153
def load_zstacklib():
153154
"""include zstacklib.py"""
154155
zstacklib_args = ZstackLibArgs()
@@ -161,6 +162,7 @@ def load_zstacklib():
161162
zstacklib_args.pip_url = pip_url
162163
zstacklib_args.zstack_releasever = releasever
163164
zstacklib_args.trusted_host = trusted_host
165+
zstacklib_args.host_info = host_info
164166
if host_info.distro in DEB_BASED_OS:
165167
zstacklib_args.apt_server = yum_server
166168
zstacklib_args.zstack_apt_source = zstack_repo

zstacklib/ansible/zstacklib.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def __init__(self):
231231
self.host_post_info = None
232232
self.pip_url = None
233233
self.require_python_env = "true"
234+
self.host_info = None
234235

235236

236237
class Msg(object):
@@ -1026,7 +1027,11 @@ def apt_update_packages(name_list, host_post_info):
10261027
host_post_info.host))
10271028

10281029

1030+
IS_REMOTE_PIP_READY = {}
1031+
1032+
10291033
def pip_install_package(pip_install_arg, host_post_info):
1034+
global IS_REMOTE_PIP_READY
10301035
start_time = datetime.datetime.now()
10311036
host_post_info.start_time = start_time
10321037
name = pip_install_arg.name
@@ -1047,8 +1052,10 @@ def pip_install_package(pip_install_arg, host_post_info):
10471052
host_post_info.post_label_param = name
10481053
handle_ansible_info("INFO: pip installing package %s ..." %
10491054
name, host_post_info, "INFO")
1050-
command = "which pip || ln -s /usr/bin/pip2 /usr/bin/pip"
1051-
run_remote_command(command, host_post_info)
1055+
if host not in IS_REMOTE_PIP_READY.keys() or not IS_REMOTE_PIP_READY[host]:
1056+
command = "which pip || ln -s /usr/bin/pip2 /usr/bin/pip"
1057+
run_remote_command(command, host_post_info)
1058+
IS_REMOTE_PIP_READY[host] = True
10521059
param_dict = {}
10531060
param_dict_raw = dict(version=version,
10541061
extra_args=extra_args,
@@ -1546,7 +1553,9 @@ def get_remote_host_info_obj(host_post_info):
15461553
runner_args = ZstackRunnerArg()
15471554
runner_args.host_post_info = host_post_info
15481555
runner_args.module_name = 'setup'
1549-
runner_args.module_args = 'filter=ansible*'
1556+
runner_args.module_args = ('gather_subset=machine,processor '
1557+
'filter=ansible_dist*,ansible_machine,'
1558+
'ansible_processor,ansible_kernel')
15501559
zstack_runner = ZstackRunner(runner_args)
15511560
result = zstack_runner.run()
15521561
logger.debug(result)
@@ -2211,7 +2220,9 @@ def __init__(self, args):
22112220
check_umask(self.host_post_info)
22122221
configure_hosts(self.host_post_info)
22132222

2214-
host_info = get_remote_host_info_obj(self.host_post_info)
2223+
host_info = args.host_info
2224+
if not host_info:
2225+
host_info = get_remote_host_info_obj(self.host_post_info)
22152226

22162227
if self.distro in RPM_BASED_OS:
22172228
install_release_on_host(True, host_info, self.host_post_info)

0 commit comments

Comments
 (0)