Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [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 | VCPE=vcpe-$STAG-$CTAG |
| 14 | |
| 15 | docker inspect $VCPE > /dev/null 2>&1 |
| 16 | if [ "$?" == 1 ] |
| 17 | then |
| 18 | docker pull andybavier/docker-vcpe |
| 19 | docker run -d --name=$VCPE --privileged=true --net=none \ |
| 20 | -v /var/container_volumes/$VCPE/mount:/mount:ro \ |
| 21 | -v /var/container_volumes/$VCPE/etc/dnsmasq.d:/etc/dnsmasq.d:ro \ |
| 22 | -v /var/container_volumes/$VCPE/etc/service/message:/etc/service/message \ |
| 23 | -v /var/container_volumes/$VCPE/usr/local/sbin:/usr/local/sbin:ro \ |
| 24 | andybavier/docker-vcpe |
| 25 | else |
| 26 | docker start $VCPE |
| 27 | fi |
| 28 | |
| 29 | # Set up networking via pipework |
| 30 | WAN_IFACE=br-wan |
| 31 | docker exec $VCPE ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VCPE {{ wan_container_ip }}/{{ wan_container_netbits }}@{{ wan_container_gateway_ip }} {{ wan_container_mac }} |
| 32 | |
| 33 | LAN_IFACE=eth0 |
| 34 | ifconfig $LAN_IFACE >> /dev/null |
| 35 | if [ "$?" == 0 ] |
| 36 | then |
| 37 | ifconfig $LAN_IFACE.$STAG >> /dev/null || ip link add link $LAN_IFACE name $LAN_IFACE.$STAG type vlan id $STAG |
| 38 | ifconfig $LAN_IFACE.$STAG up |
| 39 | docker exec $VCPE ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VCPE 192.168.0.1/24 @$CTAG |
| 40 | fi |
| 41 | |
| 42 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 43 | #docker exec $VCPE ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VCPE {{ hpc_client_ip }}/24 |
| 44 | |
| 45 | # Make sure VM's eth0 (hpc_client) has no IP address |
| 46 | #ifconfig $HPC_IFACE 0.0.0.0 |
| 47 | |
| 48 | # Attach to container |
| 49 | docker start -a $VCPE |