Last active
August 29, 2015 14:10
-
-
Save qb0C80aE/56db8819f31abd3a2498 to your computer and use it in GitHub Desktop.
Docker container and network configuration for OpenVNet DEMO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
BRIDGE=br0 | |
ovs-vsctl show | grep "Port \"veth" | awk '{print $2}' | sed -e 's/"//g' | while read port; do | |
ovs-vsctl del-port ${BRIDGE} ${port} | |
done | |
docker ps | awk '{print $1}' | grep -v grep | grep -v CONTAINER | while read container_id; do | |
docker kill ${container_id} | |
done | |
rm -rf /var/run/netns/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
BRIDGE=br0 | |
DOCKER_PID=`ps -ef | grep docker | grep -v grep | awk '{print $2}'` | |
DOCKER_IMAGE="centos_sshd" | |
IP_ADDRESSES=("10.102.0.10/24" "10.102.0.10/24" "10.102.0.11/24" "10.102.0.11/24") | |
rm -f ./netconfig.env | |
mkdir -p /var/run/netns/ | |
for i in `seq 1 ${#IP_ADDRESSES[@]}`; do | |
let address_index=$i-1 | |
CONTAINER_ID=`docker run --hostname="container${i}" --net="none" -i -t -d ${DOCKER_IMAGE} /bin/bash` | |
BASH_PID=`docker inspect --format {{.State.Pid}} ${CONTAINER_ID}` | |
ln -s /proc/${BASH_PID}/ns/net /var/run/netns/${BASH_PID} | |
ip link add veth${i}-1 type veth peer name veth${i}-2 | |
ip link set veth${i}-1 up | |
ip link set veth${i}-2 netns ${BASH_PID} | |
ip netns exec ${BASH_PID} ip link set veth${i}-2 up | |
ip netns exec ${BASH_PID} ip addr add ${IP_ADDRESSES[${address_index}]} dev veth${i}-2 | |
#ovs-vsctl add-port ${BRIDGE} veth${i}-1 | |
hwaddr=`ip netns exec ${BASH_PID} ifconfig | grep veth | awk '{print $5}'` | |
ipaddr=`echo "${IP_ADDRESSES[${address_index}]}" | awk -F/ '{print $1}'` | |
netmask=`echo "${IP_ADDRESSES[${address_index}]}" | awk -F/ '{print $2}'` | |
echo "veth${i}-2 ${IP_ADDRESSES[${address_index}]} ${hwaddr}" | |
echo "export mac_veth${i}2=${hwaddr}" >> ./netconfig.env | |
echo "export ip_veth${i}2=${ipaddr}" >> ./netconfig.env | |
echo "export netmask_veth${i}2=${netmask}" >> ./netconfig.env | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment