# Enable Guest Agent on VMs

## Automated Scripts (Recommended)

The project includes automated scripts for managing guest agent:

### Enable Guest Agent

```bash
./scripts/enable-guest-agent-existing-vms.sh
```

This script will:
- Automatically discover all nodes on each Proxmox site
- Automatically discover all VMs on each node
- Check if guest agent is already enabled
- Enable guest agent on VMs that need it
- Provide detailed summary statistics

### Verify Guest Agent Status

```bash
./scripts/verify-guest-agent.sh
```

This script will:
- List all VMs with their guest agent status
- Show which VMs have guest agent enabled/disabled
- Provide per-node and per-site summaries
- Display VM names and VMIDs for easy identification

## Manual Instructions (Alternative)

If the automated script doesn't work, you can use Proxmox CLI via SSH.

## Site 1 (ml110-01) - 192.168.11.10

### Step 1: Connect to Proxmox Host
```bash
ssh root@192.168.11.10
```

### Step 2: Enable Guest Agent for All VMs
```bash
for vmid in 118 132 133 127 128 123 124 121; do
  echo "Enabling guest agent on VMID $vmid..."
  qm set $vmid --agent 1
  echo "✅ VMID $vmid done"
done
```

### Step 3: Verify (Optional)
```bash
for vmid in 118 132 133 127 128 123 124 121; do
  agent=$(qm config $vmid | grep '^agent:' | cut -d: -f2 | tr -d ' ')
  echo "VMID $vmid: agent=${agent:-not set}"
done
```

### Step 4: Exit
```bash
exit
```

## Site 2 (r630-01) - 192.168.11.11

### Step 1: Connect to Proxmox Host
```bash
ssh root@192.168.11.11
```

### Step 2: Enable Guest Agent for All VMs
```bash
for vmid in 119 134 135 122 129 130 125 126 131 120; do
  echo "Enabling guest agent on VMID $vmid..."
  qm set $vmid --agent 1
  echo "✅ VMID $vmid done"
done
```

### Step 3: Verify (Optional)
```bash
for vmid in 119 134 135 122 129 130 125 126 131 120; do
  agent=$(qm config $vmid | grep '^agent:' | cut -d: -f2 | tr -d ' ')
  echo "VMID $vmid: agent=${agent:-not set}"
done
```

### Step 4: Exit
```bash
exit
```

## Quick One-Liners (Alternative)

If you have SSH key-based authentication set up, you can run these one-liners:

```bash
# Site 1
ssh root@192.168.11.10 "for vmid in 118 132 133 127 128 123 124 121; do qm set \$vmid --agent 1; done"

# Site 2
ssh root@192.168.11.11 "for vmid in 119 134 135 122 129 130 125 126 131 120; do qm set \$vmid --agent 1; done"
```

## VMID Reference

### Site 1 (ml110-01)
- 118: nginx-proxy-vm
- 132: smom-validator-01
- 133: smom-validator-02
- 127: smom-sentry-01
- 128: smom-sentry-02
- 123: smom-rpc-node-01
- 124: smom-rpc-node-02
- 121: smom-management

### Site 2 (r630-01)
- 119: cloudflare-tunnel-vm
- 134: smom-validator-03
- 135: smom-validator-04
- 122: smom-sentry-03
- 129: smom-sentry-04
- 130: smom-rpc-node-03
- 125: smom-rpc-node-04
- 126: smom-services
- 131: smom-blockscout
- 120: smom-monitoring

## Next Steps

After enabling guest agent in Proxmox:

1. **Wait for VMs to get IP addresses** (if they don't have them yet)
2. **Install guest agent package in each VM** (if not already installed):
   ```bash
   ssh admin@<vm-ip>
   sudo apt-get update
   sudo apt-get install -y qemu-guest-agent
   sudo systemctl enable qemu-guest-agent
   sudo systemctl start qemu-guest-agent
   ```

## Automatic Guest Agent Enablement

**New VMs** created with the updated Crossplane provider will automatically have guest agent enabled in Proxmox configuration. The provider code has been updated to set `agent=1` for all new VMs, cloned VMs, and when updating existing VMs.

The guest agent package (`qemu-guest-agent`) is also automatically installed via cloud-init userData in the VM manifests, so new VMs will have both:
1. Guest agent enabled in Proxmox config (`agent=1`)
2. Guest agent package installed and running in the OS

For existing VMs, use the automated script above or follow the manual instructions below.

