kvm-host: Add support for kvm solo
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|2625|4|2621|5|:+1:
Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/324//ansiblelint">Evolix » ansible-roles » unstable #324</a>
gitea/ansible-roles/pipeline/head This commit looks good
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|2625|4|2621|5|:+1:
Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/324//ansiblelint">Evolix » ansible-roles » unstable #324</a>
gitea/ansible-roles/pipeline/head This commit looks good
This commit is contained in:
parent
feba74c469
commit
a56682a7ca
|
@ -26,6 +26,10 @@ dryRun() {
|
|||
fi
|
||||
}
|
||||
|
||||
isSolo() {
|
||||
test -z "$slaveKVMIP"
|
||||
}
|
||||
|
||||
critical() {
|
||||
echo -ne "\e[31m${1}\e[39m\n" && exit 1
|
||||
}
|
||||
|
@ -50,6 +54,7 @@ defaultVCPU="${defaultVCPU:-"2"}"
|
|||
defaultRAM="${defaultRAM:-"4G"}"
|
||||
defaultRootSize="${defaultRootSize:-"20G"}"
|
||||
defaultHomeSize="${defaultHomeSize:-"40G"}"
|
||||
defaultVmName="${defaultVmName:-}"
|
||||
|
||||
DIALOGOUT=$(mktemp --tmpdir=/tmp addvm.XXX)
|
||||
export DIALOGOUT
|
||||
|
@ -62,7 +67,9 @@ HELPFILE=$(mktemp --tmpdir=/tmp addvm.XXX)
|
|||
export HELPFILE
|
||||
tmpResFile=$(mktemp --tmpdir=/tmp addvm.XXX)
|
||||
masterKVM="$(hostname -s)"
|
||||
if ! isSolo; then
|
||||
slaveKVM="$(ssh "${slaveKVMIP}" hostname -s)"
|
||||
fi
|
||||
|
||||
# Exit & Cleanup function.
|
||||
clean() {
|
||||
|
@ -81,7 +88,7 @@ ${DIALOG} \
|
|||
"memory" 2 1 "${defaultRAM}" 2 10 20 0 \
|
||||
"volRoot" 3 1 "${disks[0]}-${defaultRootSize}" 3 10 20 0 \
|
||||
"volHome" 4 1 "${disks[1]}-${defaultHomeSize}" 4 10 20 0 \
|
||||
"vmName" 5 1 "" 5 10 20 0 \
|
||||
"vmName" 5 1 "${defaultVmName}" 5 10 20 0 \
|
||||
2> "${DIALOGOUT}"
|
||||
|
||||
vCPU=$(sed 1'q;d' "${DIALOGOUT}")
|
||||
|
@ -114,8 +121,10 @@ else
|
|||
critical "Unknow disk ${volRootDisk} !"
|
||||
fi
|
||||
dryRun lvcreate -L"${volRootSize}" -n"${vmName}_root" "${volRootDisk}"
|
||||
if ! isSolo; then
|
||||
dryRun ssh "${slaveKVMIP}" "lvcreate -L$volRootSize -n${vmName}_root ${volRootDisk}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! [[ "${volHome}" =~ ([^-]+)-([0-9]+G) ]]; then
|
||||
warn "No volume for home device (/dev/vdb)... Okay, not doing it!"
|
||||
|
@ -127,10 +136,12 @@ else
|
|||
critical "Unknow disk ${volHomeDisk} !"
|
||||
fi
|
||||
dryRun lvcreate -L"${volHomeSize}" -n"${vmName}_home" "${volHomeDisk}"
|
||||
if ! isSolo; then
|
||||
dryRun ssh "${slaveKVMIP}" "lvcreate -L$volHomeSize -n${vmName}_home ${volHomeDisk}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "/etc/drbd.d/${vmName}.res" ]; then
|
||||
if ! isSolo && [ -f "/etc/drbd.d/${vmName}.res" ]; then
|
||||
warn "The DRBD resource file ${vmName}.res is already present! Continue? [y/N]"
|
||||
read -r
|
||||
if ! [[ "${REPLY}" =~ (Y|y) ]]; then
|
||||
|
@ -138,6 +149,7 @@ if [ -f "/etc/drbd.d/${vmName}.res" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if ! isSolo; then
|
||||
# Generates drbd resource file.
|
||||
|
||||
# shellcheck disable=SC2012
|
||||
|
@ -230,12 +242,19 @@ if ! isDryRun; then
|
|||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if isSolo; then
|
||||
virtRootDisk="--disk path=/dev/${volRootDisk}/${vmName}_root,bus=virtio,io=threads,cache=none,format=raw"
|
||||
virtHomeDisk="--disk path=/dev/${volHomeDisk}/${vmName}_home,bus=virtio,io=threads,cache=none,format=raw"
|
||||
else
|
||||
virtRootDisk="--disk path=/dev/drbd/by-disk/${volRootDisk}/${vmName}_root,bus=virtio,io=threads,cache=none,format=raw"
|
||||
virtHomeDisk=""
|
||||
if [ "${volHomeDisk}" != "none" ]; then
|
||||
virtHomeDisk="--disk path=/dev/drbd/by-disk/${volHomeDisk}/${vmName}_home,bus=virtio,io=threads,cache=none,format=raw"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${preseedURL}" ]; then
|
||||
bootMode="--location https://deb.debian.org/debian/dists/${debianVersion}/main/installer-amd64/ --extra-args auto=true priority=critical url=${preseedURL} hostname=${vmName}"
|
||||
fi
|
||||
|
@ -269,5 +288,3 @@ fi
|
|||
if ! isDryRun && [ -x /usr/share/scripts/evomaintenance.sh ]; then
|
||||
echo "Install VM ${vmName} (add-vm.sh)" | /usr/share/scripts/evomaintenance.sh
|
||||
fi
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue