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
|
|
|
|
2021-04-20 22:20:44 +00:00
|
|
|
ram_bytes_to_allocate="$1"
|
|
|
|
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-04-20 22:20:44 +00:00
|
|
|
if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
|
|
|
|
echo "ram_bytes_to_allocate \"$ram_bytes_to_allocate\" must be an integer"
|
2020-05-13 18:56:43 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-03-09 01:24:47 +00:00
|
|
|
# 20GB
|
2021-04-20 22:20:44 +00:00
|
|
|
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."
|
2021-04-20 22:20:44 +00:00
|
|
|
echo "Bytes requested: $ram_bytes_to_allocate"
|
|
|
|
echo "Bytes available: $ram_bytes_available"
|
2020-05-20 21:37:45 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-05-13 18:56:43 +00:00
|
|
|
|
2021-07-12 16:29:37 +00:00
|
|
|
ipv4_limit=61
|
2022-04-12 19:21:26 +00:00
|
|
|
total_addresses_used=$(virsh net-dhcp-leases public2 | grep -E '.+' | tail -n +3 | wc -l)
|
2020-05-13 18:56:43 +00:00
|
|
|
|
2022-04-11 22:34:02 +00:00
|
|
|
if [ "$total_addresses_used" -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"
|