Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
1bd9ea64
Commit
1bd9ea64
authored
Sep 19, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1062 from dagwieers/wait_for-fix
Fix on older python versions, plus various improvements
parents
4cd3262f
89122580
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
8 deletions
+19
-8
library/wait_for
+19
-8
No files found.
library/wait_for
View file @
1bd9ea64
...
...
@@ -29,6 +29,7 @@ def main():
argument_spec
=
dict
(
host
=
dict
(
default
=
'127.0.0.1'
),
timeout
=
dict
(
default
=
300
),
connect_timeout
=
dict
(
default
=
5
),
delay
=
dict
(
default
=
0
),
port
=
dict
(
required
=
True
),
state
=
dict
(
default
=
'started'
,
choices
=
[
'started'
,
'stopped'
]),
...
...
@@ -39,6 +40,7 @@ def main():
host
=
params
[
'host'
]
timeout
=
int
(
params
[
'timeout'
])
connect_timeout
=
int
(
params
[
'connect_timeout'
])
delay
=
int
(
params
[
'delay'
])
port
=
int
(
params
[
'port'
])
state
=
params
[
'state'
]
...
...
@@ -46,38 +48,47 @@ def main():
if
delay
:
time
.
sleep
(
delay
)
if
state
is
'stopped'
:
start
=
datetime
.
datetime
.
now
()
if
state
==
'stopped'
:
### first wait for the host to go down
end
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
seconds
=
timeout
)
end
=
start
+
datetime
.
timedelta
(
seconds
=
timeout
)
while
datetime
.
datetime
.
now
()
<
end
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
settimeout
(
5
)
s
.
settimeout
(
connect_timeout
)
try
:
s
.
connect
(
(
host
,
port
)
)
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
time
.
sleep
(
1
)
except
:
break
else
:
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s to stop."
%
(
host
))
elapsed
=
datetime
.
datetime
.
now
()
-
start
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s:
%
s to stop."
%
(
host
,
port
),
elapsed
=
elapsed
.
seconds
)
if
state
is
'started'
:
elif
state
==
'started'
:
### wait for the host to come up
end
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
seconds
=
timeout
)
end
=
start
+
datetime
.
timedelta
(
seconds
=
timeout
)
while
datetime
.
datetime
.
now
()
<
end
:
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
settimeout
(
connect_timeout
)
try
:
s
.
connect
(
(
host
,
port
)
)
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
break
except
:
time
.
sleep
(
1
)
pass
else
:
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s"
%
(
host
))
elapsed
=
datetime
.
datetime
.
now
()
-
start
module
.
fail_json
(
msg
=
"Timeout when waiting for
%
s:
%
s"
%
(
host
,
port
),
elapsed
=
elapsed
.
seconds
)
module
.
exit_json
(
state
=
state
,
port
=
port
)
elapsed
=
datetime
.
datetime
.
now
()
-
start
module
.
exit_json
(
state
=
state
,
port
=
port
,
elapsed
=
elapsed
.
seconds
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment