Commit 66ecde5e authored by Maria Matejka's avatar Maria Matejka

better link setting

parent f66e4310
......@@ -16,7 +16,7 @@ except pypureomapi.OmapiError, err:
sys.exit(1)
if sys.argv[1] == "add":
oma.add_host(sys.argv[3], sys.argv[2])
oma.add_host(sys.argv[4], sys.argv[3], sys.argv[2])
elif sys.argv[1] == "del":
oma.del_host(sys.argv[2])
else:
......
......@@ -42,10 +42,14 @@ SCRIPT=`mktemp`
cat >$SCRIPT <<EOF
if [ ! -x /bin/bash ]; then
ln -s \$(command -v bash) /bin/bash
fi
rm -f /etc/udev/rules.d/70-persistent-net.rules
if egrep -q '/mnt/nfs\s+nfs\s+' /etc/fstab; then
( egrep -v '/mnt/nfs\s+nfs\s+' /etc/fstab ; echo "$FSTAB") > /etc/fstab.new
if egrep -q '/mnt/nfs[[:space:]]+nfs[[:space:]]+' /etc/fstab; then
( egrep -v '/mnt/nfs[[:space:]]+nfs[[:space:]]+' /etc/fstab ; echo "$FSTAB") > /etc/fstab.new
cp /etc/fstab.new /etc/fstab
mkdir -p /mnt/nfs
mount -o remount /mnt/nfs
......@@ -57,9 +61,11 @@ fi
cat >/etc/rc.local <<EOC
#!/bin/bash
if [ -x /mnt/nfs/rc.local ]; then
/mnt/nfs/rc.local
fi
until [ -x /mnt/nfs/rc.local ]; do
sleep 1
done
/mnt/nfs/rc.local
EOC
chmod +x /etc/rc.local
EOF
......
......@@ -27,24 +27,28 @@ if [ "$?" != 0 ]; then
exit 2
fi
$ROOT/bin/omapi add $HOSTMAC $HOSTIP4
if [ "$1" = "--install" ]; then
INSTALL="-cdrom $2 -boot d"
shift 2
fi
declare -a HOSTNICVLAN
if [ -n "$HOSTNICMAC" ]; then
for M in $(tr ',' ' ' <<<"$HOSTNICMAC"); do
TAPID=vl-$(tr -d ':' <<<"$M")
HOSTNICDEV="$HOSTNICDEV -netdev tap,id=$TAPID,ifname=$TAPID,script=no -device e1000,netdev=$TAPID,mac=$M"
echo "IP4 ${HOSTNICIP4%%,*}" > $ROOT/nfs/net/$TAPID
HOSTNICVLAN+=( $TAPID )
HOSTNICIP4=${HOSTNICIP4#*,}
if [ -n "$HOSTNIC" ]; then
declare -a HOSTNICVLAN
declare -a HOSTNIC=( $HOSTNIC )
for N in ${HOSTNIC[@]}; do
IFS=';' read NETNAME MAC TAG IP4 IP4PEER <<<"$N"
TAPID=$(mactotap $MAC)
HOSTNICDEV="$HOSTNICDEV -netdev tap,id=$TAPID,ifname=$TAPID,script=no -device e1000,netdev=$TAPID,mac=$MAC"
TAPFILE=$ROOT/nfs/net/$TAPID
echo "NAME $NETNAME" > $TAPFILE
echo "IP4 $IP4" >> $TAPFILE
if [ -n "$IP4PEER" ]; then echo "IP4PEER $IP4PEER" >> $TAPFILE; fi
HOSTNICVLAN+=( $TAPID,$TAG )
done
fi
$ROOT/bin/omapi add $NAME $HOSTMAC $HOSTIP4
qemu-system-$HOSTARCH -enable-kvm -m $HOSTMEMORY -hda $ROOT/img/$HOSTIMAGE $HOSTCOW -display none ${HOSTVNCID:+-vnc 10.0.0.11:$HOSTVNCID} -netdev tap,id=ctl,ifname=$HOSTTAP,script=no -device e1000,netdev=ctl,mac=$HOSTMAC $HOSTNICDEV -pidfile $ROOT/run/$NAME.pid -monitor unix:$ROOT/run/$NAME.sock,server,nowait -daemonize $INSTALL "$@"
#-runas $VIRTUSER
......@@ -52,5 +56,7 @@ ip link set $HOSTTAP up
vsctl add-port $VIRTBR $HOSTTAP tag=1
for T in ${HOSTNICVLAN[@]}; do
vsctl add-port $VIRTBR $T tag=$((100 + (0x${T:4:4} % 3800)))
IFS=, read TAPID TAG <<<"$T"
ip link set $TAPID up
vsctl add-port $VIRTBR $TAPID tag=$TAG
done
......@@ -15,9 +15,12 @@ function ok() {
if gethost $NAME; then
$ROOT/bin/omapi del $HOSTMAC
vsctl del-port $HOSTTAP
if [ -n "$HOSTNICMAC" ]; then
for M in $(tr ',' ' ' <<<"$HOSTNICMAC"); do
vsctl del-port vl-$(tr -d ':' <<<"$M")
if [ -n "$HOSTNIC" ]; then
for N in ${HOSTNIC[@]}; do
IFS=';' read _ MAC _ <<<"$N"
TAPID=$(mactotap $MAC)
echo $TAPID
vsctl del-port $TAPID
done
fi
else
......
......@@ -15,6 +15,10 @@ function vsctl() {
virtns ovs-vsctl "$@"
}
function mactotap() {
echo vl-$(tr -d ':' <<<"$1")
}
function wait_pidfile() {
CNT=0
FILE=$1
......@@ -81,26 +85,49 @@ function copyhost() {
}
function linkhosts() {
local an=$1
local ai=$2
local bn=$3
local bi=$4
local NAME=$1
local an=$2
local ai=$3
local bn=$4
local bi=$5
if [ -z "$an" ] || [ -z "$ai" ] || [ -z "$bn" ] || [ -z "$bi" ]; then
echo "Link usage: 'Link host IP host IP' in config."
exit 2
fi
local SHA=$(sha1sum <<<"$an;$ai;$bn;$bi" | head -c 16)
local SHA=$(sha1sum <<<"$an;$ai;$bn;$bi" | head -c 20)
local AMAC=$(getmac ${SHA:0:8})
local BMAC=$(getmac ${SHA:8:8})
local TAG=$((100 + (0x${SHA:16:4} % 3800)))
CONF[$an;NIC]="${CONF[$an;NIC]} $NAME;$AMAC;$TAG;$ai;$bi"
CONF[$bn;NIC]="${CONF[$bn;NIC]} $NAME;$BMAC;$TAG;$bi;$ai"
}
CONF[$an;NICMAC]=${CONF[$an;NICMAC]},$AMAC
CONF[$bn;NICMAC]=${CONF[$bn;NICMAC]},$BMAC
function nethosts() {
local SHA=$(sha1sum <<<"$*" | head -c 20)
local TAG=$((100 + (0x${SHA:0:4} % 3800)))
local H
local A
local MAC
local NAME=$1
shift
CONF[$an;NICIP4]=${CONF[$an;NICIP4]},$ai
CONF[$bn;NICIP4]=${CONF[$bn;NICIP4]},$bi
until [ -z "$1" ]; do
if [ -z "$2" ]; then
echo "Missing address for interface $1 in config."
exit 2
fi
H=$1
A=$2
SHA=$(sha1sum <<<"$SHA $H $A" | head -c 20)
MAC=$(getmac ${SHA:0:8})
shift 2
CONF[$H;NIC]="${CONF[$H;NIC]} $NAME;$MAC;$TAG;$A;"
done
}
HOSTNAME=
......@@ -134,6 +161,8 @@ while read item value; do
TYPE) CONF[$HOSTNAME;TYPE]="$value" ;;
COPY) copyhost $value ;;
LINK) linkhosts $value ;;
NET) nethosts $value ;;
DUMMY) dummynic $value ;;
*) echo "Unknown directive '$item' in config"
exit 2 ;;
esac
......@@ -144,7 +173,7 @@ HOSTNAME=
function gethost() {
if ${HOSTS[$1]}; then
eval $(echo ${!CONF[@]} | tr ' ' '\n' | sed -rn "/^$1;/{ s/$1;//; s/.*/HOST&=\\\${CONF[$1;&]}/p }")
eval $(echo ${!CONF[@]} | tr ' ' '\n' | sed -rn "/^$1;/{ s/$1;//; s/.*/HOST&=\"\\\${CONF[$1;&]}\"/p }")
HOSTNAME=$1
return 0
else
......
......@@ -48,10 +48,60 @@ Host debian5
Copy openbsd58 ob1 ob2 ob3
Copy freebsd10 fb1 fb2 fb3
Copy debian8 d1 d2 d3
Copy debian8 d1 d2 d3 d4
Copy debian8 minidebian
Host minidebian
Memory 192M
Copy minidebian md1111 md1112 md1121 md1122 md1211 md1212 md1221 md1222 md2111 md2112 md2121 md2122 md2211 md2212 md2221 md2222
Link dl1113 md1111 10.1.11.11/32 md1112 10.1.11.12/32
Link dl1123 md1121 10.1.12.11/32 md1122 10.1.12.12/32
Link dl1213 md1211 10.1.21.11/32 md1212 10.1.21.12/32
Link dl1223 md1221 10.1.22.11/32 md1222 10.1.22.12/32
Link dl2113 md2111 10.2.11.11/32 md2112 10.2.11.12/32
Link dl2123 md2121 10.2.12.11/32 md2122 10.2.12.12/32
Link dl2213 md2211 10.2.21.11/32 md2212 10.2.21.12/32
Link dl2223 md2221 10.2.22.11/32 md2222 10.2.22.12/32
Link dl1131 md1111 10.1.11.21/32 md1121 10.1.11.22/32
Link dl1132 md1112 10.1.12.21/32 md1122 10.1.12.22/32
Link dl1231 md1211 10.1.21.21/32 md1221 10.1.21.22/32
Link dl1232 md1212 10.1.22.21/32 md1222 10.1.22.22/32
Link dl2131 md2111 10.2.11.21/32 md2121 10.2.11.22/32
Link dl2132 md2112 10.2.12.21/32 md2122 10.2.12.22/32
Link dl2231 md2211 10.2.21.21/32 md2221 10.2.21.22/32
Link dl2232 md2212 10.2.22.21/32 md2222 10.2.22.22/32
Link dl1311 md1111 10.1.11.31/32 md1211 10.1.11.32/32
Link dl1312 md1112 10.1.12.31/32 md1212 10.1.12.32/32
Link dl1321 md1121 10.1.21.31/32 md1221 10.1.21.32/32
Link dl1322 md1122 10.1.22.31/32 md1222 10.1.22.32/32
Link dl2311 md2111 10.2.11.31/32 md2211 10.2.11.32/32
Link dl2312 md2112 10.2.12.31/32 md2212 10.2.12.32/32
Link dl2321 md2121 10.2.21.31/32 md2221 10.2.21.32/32
Link dl2322 md2122 10.2.22.31/32 md2222 10.2.22.32/32
Link dl3111 md1111 10.1.11.41/32 md2111 10.1.11.42/32
Link dl3112 md1112 10.1.12.41/32 md2112 10.1.12.42/32
Link dl3121 md1121 10.1.21.41/32 md2121 10.1.21.42/32
Link dl3122 md1122 10.1.22.41/32 md2122 10.1.22.42/32
Link dl3211 md1211 10.2.11.41/32 md2211 10.2.11.42/32
Link dl3212 md1212 10.2.12.41/32 md2212 10.2.12.42/32
Link dl3221 md1221 10.2.21.41/32 md2221 10.2.21.42/32
Link dl3222 md1222 10.2.22.41/32 md2222 10.2.22.42/32
#Net md1 192.168.1.1/24 md2 192.168.1.2/24 md3 192.168.1.3/24 md4 192.168.1.4/24 md5 192.168.1.5/24 md6 192.168.1.6/24
#Link fb1 192.168.55.64/32 d1 192.168.55.71/32
#Link ob1 192.168.55.77/32 d1 192.168.55.33/32
#Link ob1 192.168.55.17/32 fb1 192.168.55.241/32
#Link d2 192.168.55.15/32 d3 192.168.55.117/32
#Link d3 192.168.93.15/32 d4 192.168.15.93/32
Link fb1 192.168.55.64/32 d1 192.168.55.71/32
Link ob1 192.168.55.77/32 d1 192.168.55.33/32
Link ob1 192.168.55.17/32 fb1 192.168.55.241/32
#Net fb1 192.168.44.1/24 fb2 192.168.44.2/24 fb3 192.168.44.3/24
#Net d1 192.168.66.1/24 d2 192.168.66.2/24 d3 192.168.66.3/24
#Net ob1 192.168.77.1/24 ob2 192.168.77.2/24 ob3 192.168.77.3/24
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment