forked from 3wordchant/capsul-flask
Switch shellscripts to customer pool
This commit is contained in:
parent
5a4c67d202
commit
773aa78ac4
@ -1,25 +1,30 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
## check avaliable 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_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
|
||||||
|
|
||||||
#100GB
|
# I picked 10GB arbitrarily
|
||||||
RAM_LIMIT=100000000000
|
if [ "$RAM_BYTES_REMAINDER" -le $((10 * 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"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
## compare current allocated ram + RAM_BYTES_TO_ALLOCATE with RAM_LIMIT
|
IPV4_LIMIT=60
|
||||||
|
IPV4_COUNT=$(grep ip-add /var/lib/libvirt/dnsmasq/virbr2.status | wc -l)
|
||||||
|
|
||||||
IPV4_LIMIT=26
|
if [ "$IPV4_COUNT" -ge "$IPV4_LIMIT" ]; then
|
||||||
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"
|
echo "IPv4 address limit reached"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "yes"
|
echo "yes"
|
||||||
|
@ -66,14 +66,12 @@ 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=public1,filterref=clean-traffic,model=virtio \
|
--network network=public2,filterref=clean-traffic,model=virtio \
|
||||||
--import \
|
--import \
|
||||||
--print-xml > "$xml"
|
--print-xml > "$xml"
|
||||||
|
|
||||||
# --network network=public6,filterref=clean-traffic,model=virtio
|
|
||||||
chmod 0600 "$xml" "$disk" "$cdrom"
|
chmod 0600 "$xml" "$disk" "$cdrom"
|
||||||
virsh define "$xml"
|
virsh define "$xml"
|
||||||
virsh start "$vmname"
|
virsh start "$vmname"
|
||||||
|
|
||||||
echo "success"
|
echo "success"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user