101 lines
4.4 KiB
Text
101 lines
4.4 KiB
Text
# Particle-OS VM Management Justfile
|
|
# Manages VMs on remote server via SSH
|
|
# Usage: just -f vm-justfile <command>
|
|
|
|
# Configuration variables - customize these for your environment
|
|
server := env_var_or_default("VM_SERVER", "joe@192.168.122.76")
|
|
vm_dir := env_var_or_default("VM_DIR", "/var/lib/libvirt/images")
|
|
iso_dir := env_var_or_default("ISO_DIR", "/var/lib/libvirt/isos")
|
|
ssh_key := env_var_or_default("VM_SSH_KEY", "~/.ssh/virt-manager-access")
|
|
ssh_port := env_var_or_default("VM_SSH_PORT", "22")
|
|
|
|
# Helper function to build SSH command with proper authentication
|
|
_ssh_cmd := if ssh_key != "" { "ssh -i " + ssh_key + " -p " + ssh_port } else { "ssh -p " + ssh_port }
|
|
|
|
# Default recipe - show available commands
|
|
default:
|
|
@echo "Particle-OS VM Management Commands:"
|
|
@echo " just -f vm-justfile test-connection - Test SSH connection"
|
|
@echo " just -f vm-justfile list - List all VMs and their status"
|
|
@echo " just -f vm-justfile start <name> - Start VM"
|
|
@echo " just -f vm-justfile stop <name> - Stop VM"
|
|
@echo " just -f vm-justfile force-stop <name> - Force stop VM"
|
|
@echo " just -f vm-justfile status [name] - Check VM status"
|
|
@echo " just -f vm-justfile info <name> - Show VM information"
|
|
@echo " just -f vm-justfile console <name> - Connect to VM console"
|
|
@echo " just -f vm-justfile remove <name> - Remove VM and its storage"
|
|
@echo " just -f vm-justfile create <name> <size> - Create new VM"
|
|
@echo " just -f vm-justfile list-storage-files - List storage files"
|
|
@echo " just -f vm-justfile list-isos - List ISO files"
|
|
|
|
# Test SSH connection to server
|
|
test-connection:
|
|
@echo "Testing SSH connection to {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "echo 'Connection successful!' && virsh version"
|
|
|
|
# List all VMs and their status
|
|
list:
|
|
@echo "Listing VMs on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh list --all"
|
|
|
|
# Start a VM
|
|
start name:
|
|
@echo "Starting VM '{{name}}' on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh start '{{name}}'"
|
|
@echo "VM '{{name}}' started!"
|
|
|
|
# Stop a VM gracefully
|
|
stop name:
|
|
@echo "Stopping VM '{{name}}' on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh shutdown '{{name}}'"
|
|
@echo "VM '{{name}}' shutdown initiated!"
|
|
|
|
# Force stop a VM
|
|
force-stop name:
|
|
@echo "Force stopping VM '{{name}}' on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh destroy '{{name}}'"
|
|
@echo "VM '{{name}}' force stopped!"
|
|
|
|
# Check VM status
|
|
status name="":
|
|
@echo "Checking status of VMs on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh list --all"
|
|
|
|
# Check specific VM status
|
|
status-vm name:
|
|
@echo "Checking status of VM '{{name}}' on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh domstate '{{name}}'"
|
|
|
|
# Show detailed VM information
|
|
info name:
|
|
@echo "Getting information for VM '{{name}}' on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh dominfo '{{name}}'"
|
|
|
|
# Connect to VM console
|
|
console name:
|
|
@echo "Connecting to console of VM '{{name}}' on {{server}}..."
|
|
@echo "Press Ctrl+] to exit console"
|
|
{{_ssh_cmd}} -t "{{server}}" "virsh console '{{name}}'"
|
|
|
|
# Remove VM and its storage
|
|
remove name:
|
|
@echo "Removing VM '{{name}}' from {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virsh undefine '{{name}}' --remove-all-storage"
|
|
@echo "VM '{{name}}' removed successfully!"
|
|
|
|
# Create a new VM with storage
|
|
create name size:
|
|
@echo "Creating VM '{{name}}' with {{size}} storage on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "virt-install --name '{{name}}' --ram 2048 --vcpus 2 --disk path={{vm_dir}}/{{name}}.qcow2,size={{size}},format=qcow2 --network default --graphics vnc,listen=0.0.0.0,port=5900 --video qxl --os-variant debian12 --noautoconsole --pxe"
|
|
@echo "VM '{{name}}' created successfully!"
|
|
@echo "VNC access: {{server}}:5900"
|
|
|
|
# List storage files (disk images)
|
|
list-storage-files:
|
|
@echo "Listing storage files in {{vm_dir}} on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "ls -lh {{vm_dir}}/*.{qcow2,qcow,img,raw} 2>/dev/null || echo 'No storage files found in {{vm_dir}}'"
|
|
|
|
# List available ISO files on server
|
|
list-isos:
|
|
@echo "Listing ISO files in {{iso_dir}} on {{server}}..."
|
|
{{_ssh_cmd}} "{{server}}" "ls -lh {{iso_dir}}/*.iso 2>/dev/null || echo 'No ISO files found in {{iso_dir}}'"
|