Commit 7e9803c7 authored by Maria Matejka's avatar Maria Matejka

easier install, network fixes

parent de97fe0c
......@@ -22,7 +22,6 @@ case ${HOSTTYPE^^} in
exit 2
;;
esac
AUTH=`mktemp`
......@@ -36,16 +35,18 @@ cat /root/.ssh/virt-rsa.pub >>$AUTH
echo EOC >>$AUTH
ssh root@$HOSTIP4 <$AUTH
ssh root@$HOSTIP4 bash <$AUTH
SCRIPT=`mktemp`
cat >$SCRIPT <<EOF
rm -f /etc/udev/rules.d/70-persistent-net.rules
if egrep -q '/mnt/nfs\s+nfs\s+' /etc/fstab; then
( egrep -q '/mnt/nfs\s+nfs\s+' /etc/fstab ; echo "$FSTAB") > /etc/fstab.new
mv /etc/fstab.new /etc/fstab
( egrep -v '/mnt/nfs\s+nfs\s+' /etc/fstab ; echo "$FSTAB") > /etc/fstab.new
cp /etc/fstab.new /etc/fstab
mkdir -p /mnt/nfs
mount -o remount /mnt/nfs
else
......@@ -54,9 +55,16 @@ else
mount /mnt/nfs
fi
cat >/etc/rc.local <<EOC
#!/bin/bash
if [ -x /mnt/nfs/rc.local ]; then
/mnt/nfs/rc.local
fi
EOC
chmod +x /etc/rc.local
EOF
ssh root@$HOSTIP4 <$SCRIPT
ssh root@$HOSTIP4 bash <$SCRIPT
rm $SCRIPT
rm $AUTH
......@@ -8,5 +8,7 @@ if [ -z "$NAME" ]; then
exit 2
fi
shift
gethost $NAME
ssh -i /root/.ssh/virt-rsa root@$HOSTIP4
ssh -i /root/.ssh/virt-rsa root@$HOSTIP4 "$@"
......@@ -27,17 +27,14 @@ if [ "$?" != 0 ]; then
exit 2
fi
#echo -e "Image:\t\t$HOSTIMAGE"
#echo -e "CD:\t\t$HOSTCDROM"
#echo -e "Arch:\t\t$HOSTARCH"
#echo -e "Network:\t$HOSTNETWORK"
#echo -e "MAC:\t\t$HOSTMAC"
#echo -e "IP4:\t\t$HOSTIP4"
#echo -e "TAP:\t\t$HOSTTAP"
$ROOT/bin/omapi add $HOSTMAC $HOSTIP4
qemu-system-$HOSTARCH -enable-kvm -m $HOSTMEMORY ${HOSTCDROM:+-cdrom $ROOT/iso/$HOSTCDROM -boot d} -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 -pidfile $ROOT/run/$NAME.pid -monitor unix:$ROOT/run/$NAME.sock,server,nowait -daemonize "$@"
if [ "$1" = "--install" ]; then
INSTALL="-cdrom $2 -boot d"
shift 2
fi
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 -pidfile $ROOT/run/$NAME.pid -monitor unix:$ROOT/run/$NAME.sock,server,nowait -daemonize $INSTALL "$@"
#-runas $VIRTUSER
ip link set $HOSTTAP up
......
......@@ -14,6 +14,7 @@ function ok() {
rm -f $ROOT/run/$NAME.sock $ROOT/run/$NAME.pid
if gethost $NAME; then
$ROOT/bin/omapi del $HOSTMAC
vsctl del-port $HOSTTAP
else
echo "Warning: Config not found for this host"
fi
......
......@@ -36,26 +36,57 @@ SOCAT=$ROOT/bin/socat
declare -A HOSTS
declare -A CONF
function hostctlnet() {
if [ -z "${CONF[$1;NETWORK]}" ]; then
local SHA=$(sha1sum <<<"$1" | head -c 12)
CONF[$1;TAP]=vc-$SHA
CONF[$1;MAC]=02:$(sed -r 's/^.*(..)(..)(..)(..)(..)$/\1:\2:\3:\4:\5/'<<<"$SHA")
CONF[$1;IP4]=192.168.$((193+((0x$SHA / 254) % 63))).$((0x$SHA % 254))
else
read CONF[$1;TAP] CONF[$1;MAC] CONF[$1;IP4] <<<"${CONF[$1;NETWORK]}"
fi
}
function hostdefaults() {
if [ -z "${CONF[$HOSTNAME;IMAGE]}" ]; then echo "Error: Image not set"; return 1; fi
if [ -z "${CONF[$HOSTNAME;ARCH]}" ]; then CONF[$HOSTNAME;ARCH]=x86_64; fi
if [ -z "${CONF[$HOSTNAME;MEMORY]}" ]; then CONF[$HOSTNAME;MEMORY]=64M; fi
if [ "${CONF[$HOSTNAME;COW]^^}" = "YES" ]; then CONF[$HOSTNAME;COW]=-snapshot; else CONF[$HOSTNAME;COW]=; fi
if [ -z "${CONF[$HOSTNAME;NETWORK]}" ]; then
local SHA=$(sha1sum <<<"$HOSTNAME" | head -c 12)
CONF[$HOSTNAME;TAP]=vc-$SHA
CONF[$HOSTNAME;MAC]=02:$(sed -r 's/^.*(..)(..)(..)(..)(..)$/\1:\2:\3:\4:\5/'<<<"$SHA")
CONF[$HOSTNAME;IP4]=192.168.$((193+((0x$SHA / 254) % 63))).$((0x$SHA % 254))
else
read CONF[$HOSTNAME;TAP] CONF[$HOSTNAME;MAC] CONF[$HOSTNAME;IP4] <<<"${CONF[$HOSTNAME;NETWORK]}"
fi
hostctlnet $HOSTNAME
HOSTS[$HOSTNAME]=true
HOSTNAME=
}
function copyhost() {
local src=$1
shift
if [ -z "${HOSTS[$src]}" ]; then
echo "No host '$src' found to copy from in config."
exit 2
fi
for H in "$@"; do
eval $(echo ${!CONF[@]} | tr ' ' '\n' | sed -rn "/^$src;/{ s/$src;//; s/.*/CONF[$H;&]=\\\${CONF[$src;&]}/p }")
hostctlnet $H
HOSTS[$H]=true
done
}
function linkhosts() {
local an=$1
local ai=$2
local bn=$3
local bi=$4
if [ -z "$an" ] || [ -z "$ai" ] || [ -z "$bn" ] || [ -z "$bi" ]; then
echo "Link usage: 'Link host IP host IP' in config."
exit 2
fi
}
HOSTNAME=
while read item value; do
if [ -z "$HOSTNAME" ]; then
......@@ -85,6 +116,8 @@ while read item value; do
COW) CONF[$HOSTNAME;COW]="$value" ;;
VNC) CONF[$HOSTNAME;VNCID]="$value" ;;
TYPE) CONF[$HOSTNAME;TYPE]="$value" ;;
COPY) copyhost $value ;;
LINK) linkhosts $value ;;
*) echo "Unknown directive '$item' in config"
exit 2 ;;
esac
......
Host openbsd58-install
Image openbsd58
Memory 512M
VNC 52
Type openbsd
Host openbsd58
Image openbsd58
Memory 512M
Type openbsd
Cow yes
Host freebsd10-install
Image freebsd10
Memory 512M
......@@ -33,3 +45,11 @@ Host debian5
Memory 512M
Type linux
Cow yes
Copy openbsd58 ob1 ob2 ob3
Copy freebsd10 fb1 fb2 fb3
Copy debian8 d1 d2 d3
Link fb1 192.168.55.64/32 d1 192.168.55.71/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
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