Skip to content

Commit 4bd0a1a

Browse files
committed
Implemented msekania's suggestions.
1 parent 80aef76 commit 4bd0a1a

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

plugins/module_utils/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Discovery:
6565
def __init__(self, module, logger):
6666
self.module = module
6767
self.logger = logger
68-
self.timeout = module.params.get("wait_timeout", 15)
68+
self.timeout = module.params.get("wait_timeout", -1)
6969
self.wait_for_previous = module.params.get("wait_for_previous", True)
7070
self.wait_for_completion = module.params.get("wait_for_completion", True)
7171
self.single_mode = self._single_mode()

plugins/module_utils/discovery_230.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
"monitor_undecided_services",
3939
]
4040

41+
MONITOR_UNDECIDED_SERVICES = [
42+
"new",
43+
"fix_all",
44+
"monitor_undecided_services",
45+
]
46+
47+
REMOVE_VANISHED_SERVICES = ["remove", "fix_all"]
48+
49+
UPDATE_SERVICE_LABELS = [
50+
"only_service_labels",
51+
"fix_all",
52+
"new",
53+
]
54+
55+
UPDATE_HOST_LABELS = [
56+
"new",
57+
"fix_all",
58+
"only_host_labels",
59+
]
60+
4161
SUPPORTED_VERSIONS = {
4262
"min": "2.3.0",
4363
"max": "2.3.0p99",
@@ -97,17 +117,16 @@ def post(self):
97117
}
98118
else:
99119
# Use the new parameter "options"
100-
if self.params.get("state") in [
101-
"new",
102-
"fix_all",
103-
"monitor_undecided_services",
104-
]:
120+
if self.params.get("state") in MONITOR_UNDECIDED_SERVICES:
105121
options["monitor_undecided_services"] = True
106-
if self.params.get("state") in ["remove", "fix_all"]:
122+
123+
if self.params.get("state") in REMOVE_VANISHED_SERVICES:
107124
options["remove_vanished_services"] = True
108-
if self.params.get("state") in ["only_service_labels", "fix_all", "new"]:
125+
126+
if self.params.get("state") in UPDATE_SERVICE_LABELS:
109127
options["update_service_labels"] = True
110-
if self.params.get("state") in ["new", "fix_all", "only_host_labels"]:
128+
129+
if self.params.get("state") in UPDATE_HOST_LABELS:
111130
options["update_host_labels"] = True
112131

113132
data = {
@@ -182,10 +201,14 @@ def _service_completion_api(self):
182201

183202
def _wait_for_completion(self, what):
184203
now = time.time()
185-
deadline = now + self.timeout
204+
if self.timeout > 0:
205+
deadline = now + self.timeout
206+
else:
207+
deadline = 0 # In case of infinite timeout
208+
186209
while True:
187210
now = time.time()
188-
if now > deadline:
211+
if self.timeout > 0 and now > deadline:
189212
return generate_result(
190213
msg="Timeout reached while waiting for %s discovery" % what
191214
)

plugins/module_utils/discovery_240.py

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@
3838
"monitor_undecided_services",
3939
]
4040

41+
MONITOR_UNDECIDED_SERVICES = [
42+
"new",
43+
"fix_all",
44+
"refresh",
45+
"tabula_rasa",
46+
"monitor_undecided_services",
47+
]
48+
49+
REMOVE_VANISHED_SERVICES = ["remove", "fix_all", "refresh", "tabula_rasa"]
50+
51+
UPDATE_SERVICE_LABELS = [
52+
"only_service_labels",
53+
"fix_all",
54+
"refresh",
55+
"tabula_rasa",
56+
]
57+
58+
UPDATE_HOST_LABELS = [
59+
"new",
60+
"fix_all",
61+
"only_host_labels",
62+
"refresh",
63+
"tabula_rasa",
64+
]
65+
4166
SUPPORTED_VERSIONS = {
4267
"min": "2.4.0",
4368
"max": "2.4.0p99",
@@ -86,30 +111,16 @@ def post(self):
86111
"update_host_labels": False,
87112
}
88113

89-
if self.params.get("state") in [
90-
"new",
91-
"fix_all",
92-
"refresh",
93-
"tabula_rasa",
94-
"monitor_undecided_services",
95-
]:
114+
if self.params.get("state") in MONITOR_UNDECIDED_SERVICES:
96115
options["monitor_undecided_services"] = True
97-
if self.params.get("state") in ["remove", "fix_all", "refresh", "tabula_rasa"]:
116+
117+
if self.params.get("state") in REMOVE_VANISHED_SERVICES:
98118
options["remove_vanished_services"] = True
99-
if self.params.get("state") in [
100-
"only_service_labels",
101-
"fix_all",
102-
"refresh",
103-
"tabula_rasa",
104-
]:
119+
120+
if self.params.get("state") in UPDATE_SERVICE_LABELS:
105121
options["update_service_labels"] = True
106-
if self.params.get("state") in [
107-
"new",
108-
"fix_all",
109-
"only_host_labels",
110-
"refresh",
111-
"tabula_rasa",
112-
]:
122+
123+
if self.params.get("state") in UPDATE_HOST_LABELS:
113124
options["update_host_labels"] = True
114125

115126
data = {
@@ -184,7 +195,11 @@ def _service_completion_api(self):
184195

185196
def _wait_for_completion(self, what, job_id=None):
186197
now = time.time()
187-
deadline = now + self.timeout
198+
199+
if self.timeout > 0:
200+
deadline = now + self.timeout
201+
else:
202+
deadline = 0 # In case of infinite timeout
188203

189204
if self.bulk_mode and not job_id:
190205
return generate_result(
@@ -198,7 +213,7 @@ def _wait_for_completion(self, what, job_id=None):
198213

199214
while True:
200215
now = time.time()
201-
if now > deadline:
216+
if self.timeout > 0 and now > deadline:
202217
return generate_result(
203218
msg="Timeout reached while waiting for %s discovery" % what
204219
)

plugins/modules/discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
wait_timeout:
7474
description: The time in seconds to wait for (previous/current) completion.
7575
type: int
76-
default: 15
76+
default: -1 (infinite)
7777
7878
7979
author:
@@ -202,7 +202,7 @@ def run_module():
202202
ignore_errors=dict(type="bool", default=True),
203203
wait_for_completion=dict(type="bool", default=True),
204204
wait_for_previous=dict(type="bool", default=True),
205-
wait_timeout=dict(type="int", default=15),
205+
wait_timeout=dict(type="int", default=-1),
206206
)
207207
module = AnsibleModule(
208208
argument_spec=module_args,

0 commit comments

Comments
 (0)