Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Matteo Scandolo | aca8665 | 2017-08-08 13:05:27 -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 | |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [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] }} |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 27 | VSG=vsg-$STAG-$CTAG |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 28 | |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 29 | docker inspect $VSG > /dev/null 2>&1 |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 30 | if [ "$?" == 1 ] |
| 31 | then |
Scott Baker | 8e66d66 | 2016-10-13 13:22:49 -0700 | [diff] [blame] | 32 | docker pull {{ docker_remote_image_name }} |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 33 | docker run -d --name=$VSG --privileged=true --net=none \ |
| 34 | -v /var/container_volumes/$VSG/mount:/mount:ro \ |
| 35 | -v /var/container_volumes/$VSG/etc/dnsmasq.d:/etc/dnsmasq.d:ro \ |
| 36 | -v /var/container_volumes/$VSG/etc/service/message:/etc/service/message \ |
| 37 | -v /var/container_volumes/$VSG/usr/local/sbin:/usr/local/sbin:ro \ |
Scott Baker | 8e66d66 | 2016-10-13 13:22:49 -0700 | [diff] [blame] | 38 | {{ docker_local_image_name }} |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 39 | else |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 40 | docker start $VSG |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 41 | fi |
| 42 | |
| 43 | # Set up networking via pipework |
| 44 | WAN_IFACE=br-wan |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 45 | docker exec $VSG ifconfig eth0 >> /dev/null || pipework $WAN_IFACE -i eth0 $VSG {{ wan_container_ip }}/{{ wan_container_netbits }}@{{ wan_container_gateway_ip }} {{ wan_container_mac }} |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 46 | |
| 47 | LAN_IFACE=eth0 |
| 48 | ifconfig $LAN_IFACE >> /dev/null |
| 49 | if [ "$?" == 0 ] |
| 50 | then |
| 51 | ifconfig $LAN_IFACE.$STAG >> /dev/null || ip link add link $LAN_IFACE name $LAN_IFACE.$STAG type vlan id $STAG |
| 52 | ifconfig $LAN_IFACE.$STAG up |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 53 | docker exec $VSG ifconfig eth1 >> /dev/null || pipework $LAN_IFACE.$STAG -i eth1 $VSG 192.168.0.1/24 @$CTAG |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 54 | fi |
| 55 | |
| 56 | #HPC_IFACE=$( mac_to_iface {{ hpc_client_mac }} ) |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 57 | #docker exec $VSG ifconfig eth2 >> /dev/null || pipework $HPC_IFACE -i eth2 $VSG {{ hpc_client_ip }}/24 |
Scott Baker | 761e106 | 2016-06-20 17:18:17 -0700 | [diff] [blame] | 58 | |
| 59 | # Make sure VM's eth0 (hpc_client) has no IP address |
| 60 | #ifconfig $HPC_IFACE 0.0.0.0 |
| 61 | |
| 62 | # Attach to container |
Scott Baker | 645c0c5 | 2017-09-15 10:38:32 -0700 | [diff] [blame] | 63 | docker start -a $VSG |