Disks and dryn-run mode can be defined in config file

This commit is contained in:
Victor LABORIE 2018-05-15 14:04:50 +02:00
parent f3b8cccbae
commit 592f00c047
1 changed files with 10 additions and 9 deletions

View File

@ -29,11 +29,11 @@ warn() {
echo -ne "\e[33m${1}\e[39m\n"
}
masterKVMIP=""
slaveKVMIP=""
[ -f "/etc/evolinux/add-vm.cnf" ] && . /etc/evolinux/add-vm.cnf
[ -z "$masterKVMIP" ] && critical "You must define masterKVMIP in /etc/evolinux/add-vm.cnf!!"
[ -z "$slaveKVMIP" ] && critical "You must define slaveKVMIP in /etc/evolinux/add-vm.cnf!!"
masterKVMIP="${masterKVMIP:-127.0.0.1}"
slaveKVMIP="${slaveKVMIP:-}"
disks="${disks:-(ssd hdd)}"
doDryRun=${doDryRun:-false}
export DIALOGOUT=$(mktemp --tmpdir=/tmp addvm.XXX)
# TODO: How to replace _ with a space??
@ -44,7 +44,6 @@ tmpResFile=$(mktemp --tmpdir=/tmp addvm.XXX)
xmlVM=$(mktemp --tmpdir=/tmp addvm.XXX)
masterKVM="$(hostname -s)"
slaveKVM="$(ssh $slaveKVMIP hostname -s)"
doDryRun=false
# Exit & Cleanup function.
clean() {
@ -62,8 +61,8 @@ $DIALOG --hfile $HELPFILE --title "KVM Config" --form "Set the right config. "\
"If you do not want a type of disk, type none." 0 0 0 \
"vCPU" 1 1 "2" 1 10 20 0 \
"memory" 2 1 "4G" 2 10 20 0 \
"volroot" 3 1 "ssd-20G" 3 10 20 0 \
"volhome" 4 1 "hdd-40G" 4 10 20 0 \
"volroot" 3 1 "${disks[0]}-20G" 3 10 20 0 \
"volhome" 4 1 "${disks[1]}-40G" 4 10 20 0 \
"vmName" 5 1 "" 5 10 20 0 \
2>$DIALOGOUT
vCPU=$(sed 1'q;d' $DIALOGOUT)
@ -82,21 +81,23 @@ if [[ $? -ne 0 ]]; then
exit 1
fi
if ! [[ "$volroot" =~ (ssd|hdd)-([0-9]+G) ]]; then
if ! [[ "$volroot" =~ ([^-]+)-([0-9]+G) ]]; then
critical "No volume for root device (/dev/vda)?!!"
else
volrootDisk="${BASH_REMATCH[1]}"
volrootSize="${BASH_REMATCH[2]}"
[[ " ${disks[*]} " == *"$volrootDisk"* ]] || critical "Unknow disk $volrootDisk !"
dryRun lvcreate -L$volrootSize -n${vmName}_root $volrootDisk
dryRun ssh $slaveKVMIP lvcreate -L$volrootSize -n${vmName}_root $volrootDisk
fi
if ! [[ "$volhome" =~ (ssd|hdd)-([0-9]+G) ]]; then
if ! [[ "$volhome" =~ ([^-]+)-([0-9]+G) ]]; then
warn "No volume for home device (/dev/vdb)... Okay, not doing it!"
volhomeDisk="none"
else
volhomeDisk="${BASH_REMATCH[1]}"
volhomeSize="${BASH_REMATCH[2]}"
[[ " ${disks[*]} " == *"$volhomeDisk"* ]] || critical "Unknow disk $volhomeDisk !"
dryRun lvcreate -L$volhomeSize -n${vmName}_home $volhomeDisk
dryRun ssh $slaveKVMIP lvcreate -L$volhomeSize -n${vmName}_home $volhomeDisk
fi