Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testbed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Alan Marsh
testbed
Commits
975fae7a
Commit
975fae7a
authored
7 years ago
by
Michael Marsh
Browse files
Options
Downloads
Patches
Plain Diff
updating network emulation
parent
08efa405
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
netem
+0
-43
0 additions, 43 deletions
netem
netem.py
+47
-0
47 additions, 0 deletions
netem.py
with
47 additions
and
43 deletions
netem
deleted
100644 → 0
+
0
−
43
View file @
08efa405
#! /usr/bin/env python
import
json
import
subprocess
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
state
=
dict
(
required
=
True
),
name
=
dict
(
required
=
True
,
type
=
'
str
'
),
device
=
dict
(
required
=
True
,
type
=
'
str
'
),
))
j
=
json
.
loads
(
module
.
params
[
'
state
'
])
name
=
module
.
params
[
'
name
'
]
device
=
module
.
params
[
'
device
'
]
changed
=
False
args
=
[
"
/sbin/ip
"
,
"
netns
"
,
"
exec
"
,
name
,
"
tc
"
,
"
qdisc
"
,
"
change
"
,
"
dev
"
,
device
,
"
root
"
,
"
netem
"
]
if
'
delay
'
in
j
:
args
.
append
(
"
delay
"
)
args
.
append
(
j
[
'
delay
'
])
changed
=
True
if
'
rate
'
in
j
:
args
.
append
(
"
rate
"
)
args
.
append
(
j
[
'
rate
'
])
changed
=
True
if
'
loss
'
in
j
:
args
.
append
(
"
loss
"
)
args
.
append
(
j
[
'
loss
'
])
changed
=
True
if
changed
:
cmd
=
reduce
(
lambda
x
,
y
:
"
%s %s
"
%
(
x
,
y
),
args
)
sargs
=
map
(
lambda
x
:
str
(
x
),
args
)
try
:
subprocess
.
check_output
(
sargs
,
stderr
=
subprocess
.
STDOUT
)
except
subprocess
.
CalledProcessError
as
e
:
module
.
fail_json
(
msg
=
e
.
output
)
module
.
exit_json
(
changed
=
changed
,
cmd
=
cmd
)
from
ansible.module_utils.basic
import
*
main
()
This diff is collapsed.
Click to expand it.
netem.py
0 → 100755
+
47
−
0
View file @
975fae7a
#! /usr/bin/env python
import
json
import
subprocess
from
argparse
import
ArgumentParser
parser
=
ArgumentParser
()
parser
.
add_argument
(
'
-n
'
,
'
--namespace
'
,
dest
=
'
namespace
'
,
help
=
'
network namespace for the link to modify
'
)
parser
.
add_argument
(
'
-d
'
,
'
--device
'
,
dest
=
'
device
'
,
help
=
'
device to modify
'
)
parser
.
add_argument
(
'
-B,
'
--
bandwidth
'
,
dest=
'
bandwidth
'
,
help=
'
bandwidth
to
set
'
)
parser.add_argument(
'
-
D
,
'
--delay
'
,
dest
=
'
delay
'
,
help
=
'
link latency
'
)
parser
.
add_argument
(
'
-L,
'
--
loss
'
,
dest=
'
loss
'
,
help=
'
loss
rate
'
)
args = parser.parse_args()
# Enable network emulation on the device.
cmd = [
"
sudo
"
,
"
/sbin/ip
"
,
"
netns
"
,
"
exec
"
, args.namespace,
"
tc
"
,
"
qdisc
"
,
"
change
"
,
"
dev
"
, args.device,
"
root
"
,
"
netem
"
]
if args.delay is not None:
cmd.append(
"
delay
"
)
cmd.append(str(args.delay))
if args.bandwidth is not None:
cmd.append(
"
rate
"
)
cmd.append(str(args.bandwidth))
if args.loss is not None:
cmd.append(
"
loss
"
)
cmd.append(str(args.loss))
subprocess.check_output(cmd,stderr=subprocess.STDOUT)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment