Merge branch 'master' into debian

This commit is contained in:
Victor LABORIE 2018-09-06 13:54:43 +02:00
commit 519e9a063a
2 changed files with 29 additions and 16 deletions

10
add-vm
View file

@ -34,7 +34,9 @@ masterKVMIP="${masterKVMIP:-127.0.0.1}"
slaveKVMIP="${slaveKVMIP:-}"
disks="${disks:-}"
[ -n "${disks}" ] || disks=("ssd" "hdd")
bridgeName="${bridgeName:-br0}"
doDryRun=${doDryRun:-false}
isoImagePath="${isoImagePath:-}"
export DIALOGOUT=$(mktemp --tmpdir=/tmp addvm.XXX)
# TODO: How to replace _ with a space??
@ -197,6 +199,8 @@ fi
virtHome=""
[ "$volhomeDisk" != "none" ] && virtHome="--disk path=/dev/drbd/by-disk/${volhomeDisk}/${vmName}_home,bus=virtio,io=threads,cache=none,format=raw"
bootMode="--pxe"
[ -f "$isoImagePath" ] && bootMode="--cdrom=$isoImagePath"
dryRun virt-install --connect=qemu:///system \
--name=${vmName} \
@ -204,11 +208,11 @@ dryRun virt-install --connect=qemu:///system \
--memory=${memory} \
--disk path=/dev/drbd/by-disk/${volrootDisk}/${vmName}_root,bus=virtio,io=threads,cache=none,format=raw \
$virtHome \
--network=bridge:br0,model=virtio \
$bootMode \
--network=bridge:${bridgeName},model=virtio \
--noautoconsole --graphics vnc,listen=127.0.0.1,keymap=fr \
--rng /dev/random \
--os-variant=none \
--pxe
--os-variant=none
if [ -x /usr/share/scripts/evomaintenance.sh ]; then
($doDryRun) || echo "Install VM ${vmName} (add-vm.sh)" | /usr/share/scripts/evomaintenance.sh

View file

@ -1,16 +1,25 @@
#!/bin/sh
# NOTE: kvmstats relies on the hxselect command to parse virsh' xml
# NOTE: kvmstats relies on the hxselect(1) command to parse virsh' xml
# files. On Debian, this command is provided by the 'html-xml-utils'
# package.
set -e -u
usage () {
echo 'usage: kvmstats.sh [-u K|M|G]'
echo 'usage: kvmstats.sh [-a] [-u K|M|G]'
exit 1
}
for DEP in hxselect lvs tempfile bc
do
if [ -z "$(which $DEP)" ]
then
echo "kvmstats.sh: $DEP not found in \$PATH" 1>&2
exit 1
fi
done
POW=$(echo 1024 ^ 3 | bc)
while [ $# -ne 0 ] && echo "$1" | grep -q '^-[[:alnum:]]'
do
@ -30,6 +39,9 @@ do
usage
esac
;;
'-a')
SHOW_AVAIL=y
;;
*)
usage
esac
@ -39,15 +51,6 @@ done
# since libvirt seems to store memoy in KiB, POW must be lowered by 1
POW=$((POW / 1024))
for DEP in hxselect lvs tempfile
do
if [ -z "$(which $DEP)" ]
then
echo "kvmstats.sh: $DEP not found in \$PATH" 1>&2
exit 1
fi
done
TMPFILE=$(tempfile -s kvmstats)
LVSOUT=$(tempfile -s kvmstats)
@ -73,13 +76,19 @@ do
esac
done
RUNNING=$(virsh domstate "$VM" | grep -q '^running$' && echo yes || echo no)
echo "$VM $VCPU $RAM $DISK $RUNNING"
echo "$VM" "$VCPU" "$RAM" "$DISK" "$RUNNING"
done >"$TMPFILE"
(
echo vm vcpu ram disk running
cat "$TMPFILE"
awk '{ vcpu += $2; ram += $3; disk += $4; running += length($5) } END { print "TOTAL", vcpu, ram, disk, running }' <"$TMPFILE"
awk '/yes$/ { vcpu += $2; ram += $3; disk += $4; running++ } END { print "TOTAL(running)", vcpu, ram, disk, running }' <"$TMPFILE"
if [ $SHOW_AVAIL ]
then
AV_CPU=$(awk '/^processor/ { cpu++ } END { print cpu }' /proc/cpuinfo)
AV_MEM=$(awk '/^MemTotal:/ { print int($2 / 1024 ^ 2) }' /proc/meminfo)
echo AVAILABLE "$AV_CPU" "$AV_MEM"
fi
) | column -t
rm "$TMPFILE" "$LVSOUT"