2016-01-29 10:17:40 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2016-02-23 18:22:13 +00:00
|
|
|
if [[ ${DEBUG} -gt 0 ]]; then set -x; fi
|
2015-04-15 22:35:02 +00:00
|
|
|
|
|
|
|
# Run a command in a private network namespace
|
|
|
|
# set up by CNI plugins
|
2015-05-05 20:35:20 +00:00
|
|
|
contid=$(printf '%x%x%x%x' $RANDOM $RANDOM $RANDOM $RANDOM)
|
|
|
|
netnspath=/var/run/netns/$contid
|
2015-04-15 22:35:02 +00:00
|
|
|
|
2015-05-05 20:35:20 +00:00
|
|
|
ip netns add $contid
|
|
|
|
./exec-plugins.sh add $contid $netnspath
|
2015-04-15 22:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
function cleanup() {
|
2015-05-05 20:35:20 +00:00
|
|
|
./exec-plugins.sh del $contid $netnspath
|
|
|
|
ip netns delete $contid
|
2015-04-15 22:35:02 +00:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2015-05-19 19:02:41 +00:00
|
|
|
ip netns exec $contid "$@"
|