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 {{ docker_remote_image_name }} |
| 19 | docker run -d --name=$VEG --privileged=true --net=none \ |
| 20 | -v /var/container_volumes/$VEG/mount:/mount:ro \ |
| 21 | -v /var/container_volumes/$VEG/etc/dnsmasq.d:/etc/dnsmasq.d:ro \ |
| 22 | -v /var/container_volumes/$VEG/etc/service/message:/etc/service/message \ |
| 23 | -v /var/container_volumes/$VEG/usr/local/sbin:/usr/local/sbin:ro \ |
| 24 | {{ docker_local_image_name }} |
| 25 | else |
| 26 | docker start $VEG |
| 27 | fi |
| 28 | |
| 29 | # Set up networking via pipework |
| 30 | WAN_IFACE=br-wan |
| 31 | docker exec $VEG ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VEG {{ 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 $VEG ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VEG 192.168.0.1/24 @$CTAG |
| 40 | fi |
| 41 | |
| 42 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 43 | #docker exec $VEG ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VEG {{ 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 $VEG |