mirror of
https://github.com/rancher/plugins.git
synced 2025-09-13 10:58:29 +00:00
Add plugin code
This adds basic plugins. "main" types: veth, bridge, macvlan "ipam" type: host-local The code has been ported over from github.com/coreos/rkt project and adapted to fit the CNI spec.
This commit is contained in:
21
scripts/docker-run.sh
Executable file
21
scripts/docker-run.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Run a docker container with network namespace set up by the
|
||||
# CNI plugins.
|
||||
|
||||
# Example usage: ./docker-run.sh --rm busybox /sbin/ifconfig
|
||||
|
||||
contid=$(docker run -d --net=none busybox:latest /bin/sleep 10000000)
|
||||
pid=$(docker inspect -f '{{ .State.Pid }}' $contid)
|
||||
netnspath=/proc/$pid/ns/net
|
||||
|
||||
./exec-plugins.sh add $netnspath
|
||||
|
||||
function cleanup() {
|
||||
./exec-plugins.sh del $netnspath
|
||||
docker kill $contid >/dev/null
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
docker run --net=container:$contid $@
|
||||
|
29
scripts/exec-plugins.sh
Executable file
29
scripts/exec-plugins.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
NETCONFPATH=${NETCONFPATH-/etc/cni/net.d}
|
||||
|
||||
function exec_plugins() {
|
||||
i=0
|
||||
netns=$2
|
||||
export CNI_COMMAND=$(echo $1 | tr '[:lower:]' '[:upper:]')
|
||||
export PATH=$CNI_PATH:$PATH
|
||||
export CNI_NETNS=$netns
|
||||
|
||||
for netconf in $(echo $NETCONFPATH/*.conf | sort); do
|
||||
plugin=$(jq -r '.type' <$netconf)
|
||||
export CNI_IFNAME=$(printf eth%d $i)
|
||||
|
||||
$plugin <$netconf >/dev/null
|
||||
|
||||
let "i=i+1"
|
||||
done
|
||||
}
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 add|del NETNS-PATH"
|
||||
echo " Adds or deletes the container specified by NETNS-PATH to the networks"
|
||||
echo " specified in \$NETCONFPATH directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exec_plugins $1 $2
|
20
scripts/priv-net-run.sh
Executable file
20
scripts/priv-net-run.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
# Run a command in a private network namespace
|
||||
# set up by CNI plugins
|
||||
|
||||
netnsname=$(printf '%x%x' $RANDOM $RANDOM)
|
||||
netnspath=/var/run/netns/$netnsname
|
||||
|
||||
ip netns add $netnsname
|
||||
ip netns exec $netnsname ip link set lo up
|
||||
./exec-plugins.sh add $netnspath
|
||||
|
||||
|
||||
function cleanup() {
|
||||
./exec-plugins.sh del $netnspath
|
||||
ip netns delete $netnsname
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
ip netns exec $netnsname $@
|
Reference in New Issue
Block a user