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

25 lines
520 B
Bash

#!/bin/sh
## check avaliable RAM and IPv4s
RAM_BYTES_TO_ALLOCATE="$1"
if echo "$RAM_BYTES_TO_ALLOCATE" | grep -vqE "^[0-9]+$"; then
echo "RAM_BYTES_TO_ALLOCATE \"$RAM_BYTES_TO_ALLOCATE\" must be an integer"
exit 1
fi
#100GB
RAM_LIMIT=100000000000
## compare current allocated ram + RAM_BYTES_TO_ALLOCATE with RAM_LIMIT
IPV4_LIMIT=26
IPV4_COUNT=$(grep ip-add /var/lib/libvirt/dnsmasq/virbr1.status | wc -l)
if [ $IPV4_COUNT -gt $IPV4_LIMIT ]; then
echo "IPv4 address limit reached"
exit 1
fi
echo "yes"