Merge remote-tracking branch 'origin/master'

This commit is contained in:
forest 2021-05-12 11:49:25 -05:00
commit 9d6fe075b0
2 changed files with 15 additions and 12 deletions

View File

@ -2,27 +2,30 @@
#
# check available RAM and IPv4s
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))"
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))"
if echo "$RAM_BYTES_TO_ALLOCATE" | grep -vqE "^[0-9]+$"; then
echo "RAM_BYTES_TO_ALLOCATE \"$RAM_BYTES_TO_ALLOCATE\" must be an integer"
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
# 20GB
if [ "$RAM_BYTES_REMAINDER" -le $((20 * 1024 * 1024 * 1024)) ]; then
if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
echo "VM is requesting more RAM than $(hostname -f) has available."
echo "Bytes requested: $RAM_BYTES_TO_ALLOCATE"
echo "Bytes available: $RAM_BYTES_AVAILABLE"
echo "Bytes requested: $ram_bytes_to_allocate"
echo "Bytes available: $ram_bytes_available"
exit 1
fi
IPV4_LIMIT=60
IPV4_COUNT=$(grep ip-add /var/lib/libvirt/dnsmasq/virbr2.status | wc -l)
ipv4_limit=28
used_ips=$(grep ip-add "/var/lib/libvirt/dnsmasq/virbr1.status" | cut -d '"' -f 4)
reserved_ips=$(cat "/var/lib/libvirt/dnsmasq/public1.hostsfile" | cut -d ',' -f 2)
total_addresses_used=$(printf "$used_ips\n$reserved_ips" | sort | uniq | wc -l)
ipv4_count=$(printf "$total_addresses_used")
if [ "$IPV4_COUNT" -ge "$IPV4_LIMIT" ]; then
if [ "$ipv4_count" -ge "$ipv4_limit" ]; then
echo "IPv4 address limit reached"
exit 1
fi

View File

@ -66,7 +66,7 @@ virt-install \
--os-variant generic \
--virt-type kvm \
--graphics vnc,listen=127.0.0.1 \
--network network=public2,filterref=clean-traffic,model=virtio \
--network network=public1,filterref=clean-traffic,model=virtio \
--import \
--print-xml > "$xml"