Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Iliya Manolov
slapos.toolbox
Commits
6582b9c0
Commit
6582b9c0
authored
Mar 22, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
43fc2f2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
slapos/networkbench/ping.py
slapos/networkbench/ping.py
+6
-6
slapos/promise/is_icmp_packet_lost/__init__.py
slapos/promise/is_icmp_packet_lost/__init__.py
+29
-0
No files found.
slapos/networkbench/ping.py
View file @
6582b9c0
...
...
@@ -13,7 +13,7 @@ ping_re = re.compile(
date_reg_exp
=
re
.
compile
(
'
\
d{
4
}[-/]
\
d{
2
}[-/]
\
d{
2
}'
)
def
ping
(
host
,
timeout
=
10
,
protocol
=
"4"
):
def
ping
(
host
,
timeout
=
10
,
protocol
=
"4"
,
count
=
10
):
if
protocol
==
'4'
:
ping_bin
=
'ping'
test_title
=
'PING'
...
...
@@ -21,7 +21,7 @@ def ping(host, timeout=10, protocol="4"):
ping_bin
=
'ping6'
test_title
=
'PING6'
proc
=
subprocess
.
Popen
((
ping_bin
,
'-c'
,
'10'
,
'-w'
,
str
(
timeout
),
host
),
proc
=
subprocess
.
Popen
((
ping_bin
,
'-c'
,
str
(
count
),
'-w'
,
str
(
timeout
),
host
),
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
proc
.
communicate
()
...
...
@@ -46,6 +46,6 @@ def ping(host, timeout=10, protocol="4"):
return
info_list
def
ping6
(
host
,
timeout
=
10
):
return
ping
(
host
,
timeout
=
10
,
protocol
=
'6'
)
def
ping6
(
host
,
timeout
=
10
,
count
=
10
):
return
ping
(
host
,
timeout
=
10
,
protocol
=
'6'
,
count
=
count
)
slapos/promise/is_icmp_packet_lost/__init__.py
View file @
6582b9c0
import
re
import
time
import
sys
import
gzip
from
slapos.networkcache.ping
import
ping
,
ping6
def
test
(
address
,
ipv4
,
count
):
if
ipv4
:
return
ping
(
address
,
count
=
count
)
return
ping6
(
address
,
count
=
count
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
# Address to ping to
parser
.
add_argument
(
"-a"
,
"--address"
,
metavar
=
"LOG_FILE"
)
# Force use ipv4 protocol
parser
.
add_argument
(
"-4"
,
"--ipv4"
,
action
=
"store_true"
)
parser
.
add_argument
(
"-c"
,
"--count"
,
metavar
=
"COUNT"
,
default
=
10
)
args
=
parser
.
parse_args
()
result
=
test
(
args
.
address
,
args
.
ipv4
,
args
.
count
)
print
"%s host=%s code=%s, result=%s, packet_lost_ratio=%s msg=%s"
%
result
if
result
[
4
]
!=
"0"
:
# Packet lost occurred
sys
.
exit
(
1
)
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