Skip to content

Instantly share code, notes, and snippets.

@vps2fast
Created February 19, 2014 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vps2fast/9089212 to your computer and use it in GitHub Desktop.
Save vps2fast/9089212 to your computer and use it in GitHub Desktop.
Script for OpenvVSwhich support in OpenVZ
#!/bin/sh
#
# Add virtual network interfaces (veth's) in a container to a bridge on CT0
# Manual: http://openvz.org/Virtual_Ethernet_device#Automating_the_bridge
CONFIGFILE=/etc/vz/conf/$VEID.conf
. $CONFIGFILE
NETIFLIST=$(printf %s "$NETIF" |tr ';' '\n')
if [ -z "$NETIFLIST" ]; then
echo >&2 "According to $CONFIGFILE, CT$VEID has no veth interface configured."
exit 1
fi
for iface in $NETIFLIST; do
bridge=
host_ifname=
for str in $(printf %s "$iface" |tr ',' '\n'); do
case "$str" in
bridge=*|host_ifname=*)
eval "${str%%=*}=\${str#*=}" ;;
esac
done
[ "$host_ifname" = "$3" ] ||
continue
[ -n "$bridge" ] ||
bridge=vmbr0
echo "Adding interface $host_ifname to bridge $bridge on CT0 for CT$VEID"
ip link set dev "$host_ifname" up
#ip addr add 0.0.0.0/0 dev "$host_ifname"
#echo 1 >"/proc/sys/net/ipv4/conf/$host_ifname/proxy_arp"
#echo 1 >"/proc/sys/net/ipv4/conf/$host_ifname/forwarding"
/usr/bin/ovs-vsctl del-port "$bridge" "$host_ifname"
/usr/bin/ovs-vsctl add-port "$bridge" "$host_ifname"
break
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment