| 
						
					 | 
					 | 
					@ -3,7 +3,7 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					# 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 Available /proc/meminfo | grep -o '[0-9]*') * 1024))"
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					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
 | 
				
			
			
		
	
	
		
		
			
				
					
					| 
						
					 | 
					 | 
					@ -11,8 +11,8 @@ if echo "$ram_bytes_to_allocate" | grep -vqE "^[0-9]+$"; then
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  exit 1
 | 
					 | 
					 | 
					 | 
					  exit 1
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					fi
 | 
					 | 
					 | 
					 | 
					fi
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					# 20GB
 | 
					 | 
					 | 
					 | 
					# 0.25GB
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
 | 
					 | 
					 | 
					 | 
					if [ "$ram_bytes_remainder" -le $((1 * 1024 * 1024 * 1024 / 4)) ]; 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"
 | 
				
			
			
		
	
	
		
		
			
				
					
					| 
						
					 | 
					 | 
					@ -20,9 +20,12 @@ if [ "$ram_bytes_remainder" -le $((20 * 1024 * 1024 * 1024)) ]; then
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					fi
 | 
					 | 
					 | 
					 | 
					fi
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					ipv4_limit=61
 | 
					 | 
					 | 
					 | 
					ipv4_limit=61
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					total_addresses_used=$(virsh net-dhcp-leases public2 | grep -E '.+' | tail -n +3 | wc -l)
 | 
					 | 
					 | 
					 | 
					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)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					total_addresses_used=$(printf "$used_ips\n$reserved_ips" | sort | uniq | wc -l)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					ipv4_count=$(printf "$total_addresses_used")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					if [ "$total_addresses_used" -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
 | 
				
			
			
		
	
	
		
		
			
				
					
					| 
						
					 | 
					 | 
					
 
 |