- Organized 252 files across project - Root directory: 187 → 2 files (98.9% reduction) - Moved configuration guides to docs/04-configuration/ - Moved troubleshooting guides to docs/09-troubleshooting/ - Moved quick start guides to docs/01-getting-started/ - Moved reports to reports/ directory - Archived temporary files - Generated comprehensive reports and documentation - Created maintenance scripts and guides All files organized according to established standards.
3.8 KiB
3.8 KiB
List Proxmox VMs Scripts
Two scripts to list all Proxmox VMs with VMID, Name, IP Address, FQDN, and Description.
Scripts
1. list_vms.py (Python - Recommended)
Python script using the Proxmox API. More robust and feature-rich.
Features:
- Supports both API token and password authentication
- Automatically loads credentials from
~/.envfile - Retrieves IP addresses via QEMU guest agent or network config
- Gets FQDN from hostname configuration
- Handles both QEMU VMs and LXC containers
- Graceful error handling
Prerequisites:
pip install proxmoxer requests
# Or if using venv:
source venv/bin/activate
pip install proxmoxer requests
Usage:
Option 1: Using ~/.env file (Recommended)
# Create/edit ~/.env file with:
PROXMOX_HOST=your-proxmox-host
PROXMOX_USER=root@pam
PROXMOX_TOKEN_NAME=your-token-name
PROXMOX_TOKEN_VALUE=your-token-value
# OR use password:
PROXMOX_PASSWORD=your-password
# Then run:
python3 list_vms.py
Option 2: Environment variables
export PROXMOX_HOST=your-proxmox-host
export PROXMOX_USER=root@pam
export PROXMOX_TOKEN_NAME=your-token-name
export PROXMOX_TOKEN_VALUE=your-token-value
python3 list_vms.py
Option 3: JSON config file
export PROXMOX_MCP_CONFIG=/path/to/config.json
python3 list_vms.py
2. list_vms.sh (Shell Script)
Shell script using pvesh via SSH. Requires SSH access to Proxmox node.
Prerequisites:
- SSH access to Proxmox node
pveshcommand available on Proxmox node- Python3 for JSON parsing
Usage:
export PROXMOX_HOST=your-proxmox-host
export PROXMOX_USER=root
./list_vms.sh
Output Format
Both scripts output a formatted table:
VMID | Name | Type | IP Address | FQDN | Description
-------|-------------------------|------|-------------------|-------------------------|----------------
100 | vm-example | QEMU | 192.168.1.100 | vm-example.local | Example VM
101 | container-example | LXC | 192.168.1.101 | container.local | Example container
How IP Addresses are Retrieved
For QEMU VMs:
- First tries QEMU guest agent (
network-get-interfaces) - Falls back to network configuration parsing
- Shows "N/A" if neither method works
For LXC Containers:
- Executes
hostname -Icommand inside container - Filters out localhost addresses
- Shows "N/A" if command fails or container is stopped
How FQDN is Retrieved
- Gets hostname from VM/container configuration
- For running VMs, tries to execute
hostname -fcommand - Falls back to hostname from config if command fails
- Shows "N/A" if no hostname is configured
Troubleshooting
Connection Timeout
- Verify Proxmox host is reachable:
ping your-proxmox-host - Check firewall rules allow port 8006
- Verify credentials in
~/.envare correct
Authentication Failed
- Verify API token is valid and not expired
- Check user permissions in Proxmox
- Try using password authentication instead
IP Address Shows "N/A"
- For QEMU: Ensure QEMU guest agent is installed and running in VM
- For LXC: Container must be running to execute commands
- Check network configuration in VM/container
FQDN Shows "N/A"
- Set hostname in VM/container configuration
- For running VMs, ensure hostname command is available
Examples
List all VMs
python3 list_vms.py
List VMs from specific host
PROXMOX_HOST=192.168.11.10 python3 list_vms.py
Using shell script
PROXMOX_HOST=192.168.11.10 PROXMOX_USER=root ./list_vms.sh
Notes
- Scripts automatically sort VMs by VMID
- Both QEMU VMs and LXC containers are included
- Scripts handle missing information gracefully (shows "N/A")
- Python script is recommended for better error handling and features