Various fixes to scripts and conf

This commit is contained in:
Guillaume
2023-05-24 20:12:07 +02:00
parent 8675219622
commit 83defa740f
8 changed files with 181 additions and 107 deletions

View File

@ -2,8 +2,6 @@
#
# This collection of scripts aims to install a NOVIT cluster easily, with help of QEMU
#
# Admin token to unlock the DLS store
DLS_UNLOCK_TOKEN=changeme
#
# QEMU local bridge name. If you specificy a custom name, you may have to configure qemu bridge helper to allow it
QEMU_BR_NAME=virbr0
@ -25,54 +23,54 @@ prereqs_qemu() {
done
}
setup_network_qemu() {
#
ip li show $QEMU_BR_NAME &>/dev/null && ip li del $QEMU_BR_NAME
ip li add name $QEMU_BR_NAME type bridge
ip li set $QEMU_BR_NAME up
if ! ip li show $QEMU_BR_NAME ; then
ip li add name $QEMU_BR_NAME type bridge
ip li set $QEMU_BR_NAME up
fi
QEMU_BR_IP=$(extract_var clusters gateway)
QEMU_BR_MASK=$(extract_var clusters netmask)
if [ $(echo $QEMU_BR_IP | wc -w) -gt 1 ]; then
perror "More than one cluster is configured, not compatible with our quick-start setup, exiting"
fi
pinfo "Using detected gateway IP $QEMU_BR_IP for bridge $QEMU_BR_NAME"
ip a add $QEMU_BR_IP dev $QEMU_BR_NAME && {
if ! ip a show dev $QEMU_BR_NAME | grep $QEMU_BR_IP ; then
ip a add $QEMU_BR_IP/$QEMU_BR_MASK dev $QEMU_BR_NAME
sudo iptables -t nat -I POSTROUTING -j MASQUERADE -s $QEMU_BR_IP/$QEMU_BR_MASK \! -o $QEMU_BR_NAME
sudo iptables -I FORWARD -o $QEMU_BR_NAME -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -I FORWARD -j ACCEPT -i $QEMU_BR_NAME
}
fi
}
run_qemu() {
id=1
for host in ${!hosts[*]}; do
ip route add ${hosts[$host]} dev $QEMU_BR_NAME
info "Starting host $host with ip ${hosts[$host]}"
ip route show |grep "${hosts[$host]} dev $QEMU_BR_NAME" ||\
ip route add ${hosts[$host]} dev $QEMU_BR_NAME
if test -f $ctxdir/data/$host/pid ; then
info "Detected a pid file, killing process in case VM was already started"
kill $(<$ctxdir/$host/pid) && sleep 1
pinfo "Detected a pid file, killing process in case VM was already started"
kill $(cat $ctxdir/data/$host/pid) && sleep 1
fi
pinfo "Starting host $host with ip ${hosts[$host]}"
qemu-system-x86_64 -enable-kvm -smp $QEMU_VM_CPU -m $QEMU_VM_MEM \
-nic bridge,br=$QEMU_BR_NAME,mac=42:42:42:42:42:0${id} \
-kernel $ctxdir/data/$host/kernel -initrd $ctxdir/data/$host/initrd-v2 -vga qxl \
-hda $ctxdir/data/$host/disk.raw &
-drive format=raw,file=$ctxdir/data/$host/disk &
echo $! >$ctxdir/data/$host/pid
((++id))
done
info "$(ls $ctxdir/data/*/pid|wc -w) host(s) have been started"
pinfo "$(ls $ctxdir/data/*/pid|wc -w) host(s) have been started"
}
# # # # # # # #
source .common
source $(dirname $0)/.common
check_root
prereqs
prereqs_qemu
check_conf
fresh_start
#unlock_store
#fresh_start
trap clean SIGINT SIGTERM SIGKILL
declare -A hosts
setup_network_qemu
get_hosts
get_parts
run_qemu
create_kubeconfig
clean
#clean