Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Andy Bavier | 4c7e76d | 2015-09-09 18:06:30 -0400 | [diff] [blame] | 3 | function mac_to_iface { |
| 4 | MAC=$1 |
| 5 | ifconfig|grep $MAC| awk '{print $1}'|grep -v '\.' |
| 6 | } |
| 7 | |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 8 | iptables -L > /dev/null |
| 9 | ip6tables -L > /dev/null |
| 10 | |
Andy Bavier | 6d0a9be | 2015-07-02 15:00:58 -0400 | [diff] [blame] | 11 | VCPE=vcpe-{{ vlan_ids[0] }} |
| 12 | |
| 13 | docker inspect $VCPE > /dev/null 2>&1 |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 14 | if [ "$?" == 1 ] |
| 15 | then |
Andy Bavier | 7af6fa0 | 2015-06-08 15:10:57 -0400 | [diff] [blame] | 16 | docker pull andybavier/docker-vcpe |
Andy Bavier | 6d0a9be | 2015-07-02 15:00:58 -0400 | [diff] [blame] | 17 | docker run -d --name=$VCPE --privileged=true --net=none -v /etc/$VCPE/dnsmasq.d:/etc/dnsmasq.d andybavier/docker-vcpe |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 18 | else |
Andy Bavier | 6d0a9be | 2015-07-02 15:00:58 -0400 | [diff] [blame] | 19 | docker start $VCPE |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 20 | fi |
| 21 | |
| 22 | # Set up networking via pipework |
Andy Bavier | 4c7e76d | 2015-09-09 18:06:30 -0400 | [diff] [blame] | 23 | WAN_IFACE=$( mac_to_iface {{ wan_mac }} ) |
Andy Bavier | 733733d | 2015-10-29 14:01:47 -0400 | [diff] [blame] | 24 | docker exec $VCPE ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VCPE {{ wan_ip }}/24@{{ wan_next_hop }} {{ wan_container_mac }} |
Andy Bavier | 4c7e76d | 2015-09-09 18:06:30 -0400 | [diff] [blame] | 25 | |
| 26 | LAN_IFACE=$( mac_to_iface {{ lan_mac }} ) |
| 27 | docker exec $VCPE ifconfig eth1 >> /dev/null || pipework $LAN_IFACE -i eth1 $VCPE 192.168.0.1/24 @{{ vlan_ids[0] }} |
| 28 | |
| 29 | HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 30 | docker exec $VCPE ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VCPE {{ hpc_client_ip }}/24 |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 31 | |
Scott Baker | 6b73d1b | 2015-06-23 17:01:01 -0700 | [diff] [blame] | 32 | # Make sure VM's eth0 (hpc_client) has no IP address |
Andy Bavier | 4c7e76d | 2015-09-09 18:06:30 -0400 | [diff] [blame] | 33 | ifconfig $HPC_IFACE 0.0.0.0 |
Scott Baker | 6b73d1b | 2015-06-23 17:01:01 -0700 | [diff] [blame] | 34 | |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 35 | # Now can start up dnsmasq |
Andy Bavier | 6d0a9be | 2015-07-02 15:00:58 -0400 | [diff] [blame] | 36 | docker exec $VCPE service dnsmasq start |
Andy Bavier | aeaebe5 | 2015-05-18 15:15:06 -0400 | [diff] [blame] | 37 | |
| 38 | # Attach to container |
Andy Bavier | 6d0a9be | 2015-07-02 15:00:58 -0400 | [diff] [blame] | 39 | docker start -a $VCPE |