Andrea Campanella | edfdbca | 2017-02-01 17:33:47 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Scott Baker | 3b8ceca | 2017-10-12 11:38:50 -0700 | [diff] [blame] | 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Andrea Campanella | edfdbca | 2017-02-01 17:33:47 -0800 | [diff] [blame] | 17 | function mac_to_iface { |
| 18 | MAC=$1 |
| 19 | ifconfig|grep $MAC| awk '{print $1}'|grep -v '\.' |
| 20 | } |
| 21 | |
| 22 | iptables -L > /dev/null |
| 23 | ip6tables -L > /dev/null |
| 24 | |
| 25 | STAG={{ s_tags[0] }} |
| 26 | CTAG={{ c_tags[0] }} |
| 27 | VEG=veg-$STAG-$CTAG |
| 28 | |
| 29 | docker inspect $VEG > /dev/null 2>&1 |
| 30 | if [ "$?" == 1 ] |
| 31 | then |
| 32 | docker pull andybavier/docker-veg |
| 33 | docker run -d --name=$VEG --privileged=true --net=none -v /etc/$VEG/dnsmasq.d:/etc/dnsmasq.d andybavier/docker-veg |
| 34 | else |
| 35 | docker start $VEG |
| 36 | fi |
| 37 | |
| 38 | # Set up networking via pipework |
| 39 | WAN_IFACE=$( mac_to_iface {{ wan_mac }} ) |
| 40 | docker exec $VEG ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VEG {{ wan_ip }}/24@{{ wan_next_hop }} {{ wan_container_mac }} |
| 41 | |
| 42 | # LAN_IFACE=$( mac_to_iface {{ lan_mac }} ) |
| 43 | # Need to encapsulate VLAN traffic so that Neutron doesn't eat it |
| 44 | # Assumes that br-lan has been set up appropriately by a previous step |
| 45 | LAN_IFACE=br-lan |
| 46 | ifconfig $LAN_IFACE >> /dev/null |
| 47 | if [ "$?" == 0 ] |
| 48 | then |
| 49 | ifconfig $LAN_IFACE.$STAG >> /dev/null || ip link add link $LAN_IFACE name $LAN_IFACE.$STAG type vlan id $STAG |
| 50 | ifconfig $LAN_IFACE.$STAG up |
| 51 | docker exec $VEG ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VEG 192.168.0.1/24 @$CTAG |
| 52 | fi |
| 53 | |
| 54 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
| 55 | #docker exec $VEG ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VEG {{ hpc_client_ip }}/24 |
| 56 | |
| 57 | # Make sure VM's eth0 (hpc_client) has no IP address |
| 58 | #ifconfig $HPC_IFACE 0.0.0.0 |
| 59 | |
| 60 | # Now can start up dnsmasq |
| 61 | docker exec $VEG service dnsmasq start |
| 62 | |
| 63 | # Attach to container |
| 64 | docker start -a $VEG |