forked from 3wordchant/capsul-flask
Correct ip detection logic, flip network to public1 (capacity issues)
This commit is contained in:
parent
46a691b876
commit
525de7450e
@ -2,27 +2,30 @@
|
|||||||
#
|
#
|
||||||
# check available RAM and IPv4s
|
# check available RAM and IPv4s
|
||||||
|
|
||||||
RAM_BYTES_TO_ALLOCATE="$1"
|
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_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_remainder="$((ram_bytes_available - ram_bytes_to_allocate))"
|
||||||
|
|
||||||
if echo "$RAM_BYTES_TO_ALLOCATE" | grep -vqE "^[0-9]+$"; then
|
if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
|
||||||
echo "RAM_BYTES_TO_ALLOCATE \"$RAM_BYTES_TO_ALLOCATE\" must be an integer"
|
echo "ram_bytes_to_allocate \"$ram_bytes_to_allocate\" must be an integer"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 20GB
|
# 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 "VM is requesting more RAM than $(hostname -f) has available."
|
||||||
echo "Bytes requested: $RAM_BYTES_TO_ALLOCATE"
|
echo "Bytes requested: $ram_bytes_to_allocate"
|
||||||
echo "Bytes available: $RAM_BYTES_AVAILABLE"
|
echo "Bytes available: $ram_bytes_available"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IPV4_LIMIT=60
|
ipv4_limit=28
|
||||||
IPV4_COUNT=$(grep ip-add /var/lib/libvirt/dnsmasq/virbr2.status | wc -l)
|
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"
|
echo "IPv4 address limit reached"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -66,7 +66,7 @@ virt-install \
|
|||||||
--os-variant generic \
|
--os-variant generic \
|
||||||
--virt-type kvm \
|
--virt-type kvm \
|
||||||
--graphics vnc,listen=127.0.0.1 \
|
--graphics vnc,listen=127.0.0.1 \
|
||||||
--network network=public2,filterref=clean-traffic,model=virtio \
|
--network network=public1,filterref=clean-traffic,model=virtio \
|
||||||
--import \
|
--import \
|
||||||
--print-xml > "$xml"
|
--print-xml > "$xml"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user