Andrea Campanella | edfdbca | 2017-02-01 17:33:47 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | function mac_to_iface { |
| 4 | MAC=$1 |
| 5 | ifconfig|grep $MAC| awk '{print $1}'|grep -v '\.' |
| 6 | } |
| 7 | |
| 8 | iptables -L > /dev/null |
| 9 | ip6tables -L > /dev/null |
| 10 | |
| 11 | STAG={{ s_tags[0] }} |
| 12 | CTAG={{ c_tags[0] }} |
| 13 | VEG=veg-$STAG-$CTAG |
| 14 | |
| 15 | docker inspect $VEG > /dev/null 2>&1 |
| 16 | if [ "$?" == 1 ] |
| 17 | then |
| 18 | docker pull andybavier/docker-veg |
| 19 | docker run -d --name=$VEG --privileged=true --net=none -v /etc/$VEG/dnsmasq.d:/etc/dnsmasq.d andybavier/docker-veg |
| 20 | else |
| 21 | docker start $VEG |
| 22 | fi |
| 23 | |
| 24 | # Set up networking via pipework |
| 25 | WAN_IFACE=$( mac_to_iface {{ wan_mac }} ) |
| 26 | docker exec $VEG ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VEG {{ wan_ip }}/24@{{ wan_next_hop }} {{ wan_container_mac }} |
| 27 | |
| 28 | # LAN_IFACE=$( mac_to_iface {{ lan_mac }} ) |
| 29 | # Need to encapsulate VLAN traffic so that Neutron doesn't eat it |
| 30 | # Assumes that br-lan has been set up appropriately by a previous step |
| 31 | LAN_IFACE=br-lan |
| 32 | ifconfig $LAN_IFACE >> /dev/null |
| 33 | if [ "$?" == 0 ] |
| 34 | then |
| 35 | ifconfig $LAN_IFACE.$STAG >> /dev/null || ip link add link $LAN_IFACE name $LAN_IFACE.$STAG type vlan id $STAG |
| 36 | ifconfig $LAN_IFACE.$STAG up |
| 37 | docker exec $VEG ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VEG 192.168.0.1/24 @$CTAG |
| 38 | fi |
| 39 | |
| 40 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 41 | #docker exec $VEG ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VEG {{ hpc_client_ip }}/24 |
| 42 | |
| 43 | # Make sure VM's eth0 (hpc_client) has no IP address |
| 44 | #ifconfig $HPC_IFACE 0.0.0.0 |
| 45 | |
| 46 | # Now can start up dnsmasq |
| 47 | docker exec $VEG service dnsmasq start |
| 48 | |
| 49 | # Attach to container |
| 50 | docker start -a $VEG |