kvmagent synchronizes VM inventory from a libvirt/KVM host into NetBox.
- Connects to a local or remote libvirt host.
- Discovers VMs, interfaces, and disks.
- Creates/updates corresponding objects in NetBox.
- Retries transient NetBox API failures with exponential backoff.
- Emits structured logs with configurable log levels.
- Python 3.11+
- Access to libvirt (local socket or remote TCP endpoint)
- NetBox API token and URL
pip install -r requirements.txtSet environment variables (see .env.example):
NETBOX_URL(required)NETBOX_TOKEN(required)NETBOX_TENANT(default:default)NETBOX_SITE(default:default)NETBOX_CLUSTER_TYPE(default:KVM)NETBOX_API_RETRIES(default:3)NETBOX_RETRY_BACKOFF(default:1.5)KVM_ADDR(empty means local libvirt)CHECK_INTERVAL(default:300)RUN_ONCE(true/false, default:true)LOG_LEVEL(DEBUG,INFO,WARNING,ERROR; default:INFO)
Run one sync pass:
RUN_ONCE=true python3 main.pyRun continuously:
RUN_ONCE=false CHECK_INTERVAL=300 python3 main.pyThe app logs at multiple levels:
DEBUG: payload-level and decision logsINFO: normal lifecycle/sync operationsWARNING: transient issues and retriesERROR: failed API/libvirt operations
Example:
LOG_LEVEL=DEBUG python3 main.py