added vagrant scripts
This commit is contained in:
parent
6ff4033a13
commit
2997f0252a
2 changed files with 171 additions and 0 deletions
77
scripts/configure_vagrant_k3s.sh
Executable file
77
scripts/configure_vagrant_k3s.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script checks for Vagrant and VirtualBox prerequisites, ensures Vagrant VMs are running, and gathers network and system information from the VMs.
|
||||
|
||||
echo "Checking Vagrant prerequisites..."
|
||||
|
||||
# Check if Vagrant is installed
|
||||
if ! command -v vagrant &> /dev/null; then
|
||||
echo "Vagrant is not installed. Please install Vagrant to proceed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if VirtualBox is installed
|
||||
if ! command -v VBoxManage &> /dev/null; then
|
||||
echo "VirtualBox is not installed. Please install VirtualBox to proceed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
echo "Script directory: $SCRIPT_DIR"
|
||||
|
||||
VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/"
|
||||
|
||||
cd "$VAGRANT_DIR" || {
|
||||
echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if any VMs are running; if not, run 'vagrant up'
|
||||
if [ -z "$(vagrant status | grep 'running')" ]; then
|
||||
echo "No Vagrant VMs are running. Starting VMs with 'vagrant up'..."
|
||||
vagrant up
|
||||
fi
|
||||
|
||||
network_info=()
|
||||
|
||||
echo "Gathering network information from running VMs..."
|
||||
running_vms=$(vagrant status | grep "running" | awk '{print $1}')
|
||||
|
||||
for vm in $running_vms; do
|
||||
|
||||
# Check network interfaces
|
||||
vm_info=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '
|
||||
.[] |
|
||||
"Interface: \(.ifname)\n" + vm_info=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '
|
||||
|
||||
(if .addr_info then
|
||||
(.addr_info | map(" IP (\(.family)): \(.local)") | join("\n"))
|
||||
else
|
||||
""
|
||||
end)
|
||||
')
|
||||
|
||||
# Save the VM's network info to the array
|
||||
network_info+=("$vm:\n$vm_info")
|
||||
|
||||
done
|
||||
|
||||
for vm in $running_vms; do
|
||||
echo $vm
|
||||
echo "----------------------------------------"
|
||||
vagrant ssh "$vm" -c "free" | grep 'Mem:' | awk '{print "Memory in bytes: " $2 " Memory in MB: " $2/1024/1024}'
|
||||
vagrant ssh "$vm" -c "lscpu" | grep 'CPU(s):' | grep -v 'NUMA' | awk '{print "CPU count: " $2}'
|
||||
echo "----------------------------------------"
|
||||
done
|
||||
|
||||
echo "Network information gathered successfully."
|
||||
|
||||
# Print network information
|
||||
for info in "${network_info[@]}"; do
|
||||
echo "----------------------------------------"
|
||||
echo -e "$info"
|
||||
echo "----------------------------------------"
|
||||
done
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue