capsul-flask/capsulflask/shell_scripts/capacity-avaliable.sh

31 lines
880 B
Bash
Raw Normal View History

2020-05-13 18:56:43 +00:00
#!/bin/sh
2020-05-20 21:37:45 +00:00
#
# check available RAM and IPv4s
2020-05-13 18:56:43 +00:00
RAM_BYTES_TO_ALLOCATE="$1"
2020-05-20 21:37:45 +00:00
RAM_BYTES_AVAILABLE=$(grep -E "^(size|memory_available_bytes)" /proc/spl/kstat/zfs/arcstats | awk '{sum+=$3} END {printf "%.0f", sum}')
RAM_BYTES_REMAINDER="$((RAM_BYTES_AVAILABLE - RAM_BYTES_TO_ALLOCATE))"
2020-05-13 18:56:43 +00:00
2021-03-09 01:24:47 +00:00
if echo "$RAM_BYTES_TO_ALLOCATE" | grep -vqE "^[0-9]+$"; then
2020-05-13 18:56:43 +00:00
echo "RAM_BYTES_TO_ALLOCATE \"$RAM_BYTES_TO_ALLOCATE\" must be an integer"
exit 1
fi
2021-03-09 01:24:47 +00:00
# 20GB
if [ "$RAM_BYTES_REMAINDER" -le $((20 * 1024 * 1024 * 1024)) ]; then
2020-05-20 21:37:45 +00:00
echo "VM is requesting more RAM than $(hostname -f) has available."
echo "Bytes requested: $RAM_BYTES_TO_ALLOCATE"
echo "Bytes available: $RAM_BYTES_AVAILABLE"
exit 1
fi
2020-05-13 18:56:43 +00:00
2020-05-20 21:37:45 +00:00
IPV4_LIMIT=60
IPV4_COUNT=$(grep ip-add /var/lib/libvirt/dnsmasq/virbr2.status | wc -l)
2020-05-13 18:56:43 +00:00
2020-05-20 21:37:45 +00:00
if [ "$IPV4_COUNT" -ge "$IPV4_LIMIT" ]; then
2020-05-13 18:56:43 +00:00
echo "IPv4 address limit reached"
exit 1
fi
2021-03-09 01:24:47 +00:00
2020-05-20 21:37:45 +00:00
echo "yes"