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"
|
2021-07-13 22:42:28 +00:00
|
|
|
ram_bytes_available="$(($(grep Available /proc/meminfo | grep -o '[0-9]*') * 1024))"
|
2021-04-20 22:20:44 +00:00
|
|
|
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-07-13 22:42:28 +00:00
|
|
|
# 0.25GB
|
|
|
|
if [ "$ram_bytes_remainder" -le $((1 * 1024 * 1024 * 1024 / 4)) ]; 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
|
|
|
|
used_ips=$(grep ip-add "/var/lib/libvirt/dnsmasq/virbr3.status" | cut -d '"' -f 4)
|
|
|
|
reserved_ips=$(cat "/var/lib/libvirt/dnsmasq/public3.hostsfile" | cut -d ',' -f 2)
|
2021-04-20 22:20:44 +00:00
|
|
|
total_addresses_used=$(printf "$used_ips\n$reserved_ips" | sort | uniq | wc -l)
|
|
|
|
ipv4_count=$(printf "$total_addresses_used")
|
2020-05-13 18:56:43 +00:00
|
|
|
|
2021-04-20 22:20:44 +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"
|