-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect-chain.sh
executable file
·35 lines (30 loc) · 1.02 KB
/
connect-chain.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
LIST=$(grep add-port create_chain_interfaces.sh | awk '{printf("%s,%s\n", $6, $5)}')
TMPA=$(tempfile)
TMPB=$(tempfile)
cat $1 > $TMPA
# Substitue switch port numbers
for i in $LIST; do
CONTAINER="$(echo $i | cut -d, -f1)"
INTERFACE=$(echo $i | cut -d, -f2)
cat $TMPA | sed -e "s/($i)/$(.\/container_interface_to_ovs_port_no.sh $CONTAINER $INTERFACE)/g" > $TMPB
cp $TMPB $TMPA
done
# Substribute IP addresses
for i in $LIST; do
CONTAINER="$(echo $i | cut -d, -f1)"
INTERFACE=$(echo $i | cut -d, -f2)
IP=$(docker exec -ti $CONTAINER ifconfig $INTERFACE | grep 'inet addr' | cut -d: -f2 | awk '{print $1}')
cat $TMPA | sed -e "s/\[$i\]/$IP/g" > $TMPB
cp $TMPB $TMPA
done
# Substitue MAC addresses
for i in $LIST; do
CONTAINER="$(echo $i | cut -d, -f1)"
INTERFACE=$(echo $i | cut -d, -f2)
MAC=$(docker exec -ti $CONTAINER ifconfig $INTERFACE | grep HWaddr | awk '{print tolower($5)}')
cat $TMPA | sed -e "s/{$i}/$MAC/g" > $TMPB
cp $TMPB $TMPA
done
cat $TMPA
rm -f $TMPA $TMPB