Synchronization Workflows¶
This page explains the major synchronization workflows between Proxmox and NetBox.
Full Update Flow¶
HTTP endpoint:
GET /full-update
Current execution order:
- Sync Proxmox nodes into NetBox devices.
- Sync Proxmox storages into NetBox plugin storage records.
- Sync Proxmox virtual machines into NetBox VMs.
- Sync task history records.
- Sync virtual disks for discovered VMs.
- Sync VM backups.
- Sync VM snapshots.
- Sync node interfaces and IP addresses.
- Sync VM interfaces.
- Sync VM IP addresses and primary IP assignment.
The streaming variant at GET /full-update/stream emits the same stage transitions over Server-Sent Events.
Virtual Machine Sync Flow¶
Primary endpoint:
GET /virtualization/virtual-machines/create
Core behavior:
- Reads cluster resources from Proxmox sessions.
- Resolves VM configs per VM (
qemuandlxc). - Builds normalized NetBox payloads.
- Creates dependencies such as cluster, device, and role as needed.
- Creates VM interfaces and IP addresses when possible.
- Writes journal entries for auditability.
- In full-update mode, VM creation skips network writes so the dedicated VM interface and IP stages own that work.
Backup Sync Flow¶
Endpoints:
GET /virtualization/virtual-machines/backups/createGET /virtualization/virtual-machines/backups/all/createGET /virtualization/virtual-machines/backups/all/create/stream
Core behavior:
- Discovers backup content in Proxmox storage.
- Maps backups to NetBox VMs.
- Creates backup objects under the NetBox plugin model.
- Handles duplicate detection.
- Optional deletion of backups missing from the Proxmox source.
Snapshot Sync Flow¶
Endpoints:
GET /virtualization/virtual-machines/snapshots/createGET /virtualization/virtual-machines/snapshots/all/createGET /virtualization/virtual-machines/snapshots/all/create/stream
Core behavior:
- Discovers snapshots for NetBox VMs mapped to Proxmox VM IDs.
- Reconciles snapshot objects in the NetBox plugin model.
- Resolves related storage records when possible.
Storage Sync Flow¶
Endpoints:
GET /virtualization/virtual-machines/storage/createGET /virtualization/virtual-machines/storage/create/stream
Core behavior:
- Discovers Proxmox storage definitions.
- Reconciles NetBox plugin storage records used by backup and snapshot flows.
SSE Streaming Mode¶
Each sync flow has a corresponding /stream endpoint that emits Server-Sent Events in real time:
GET /full-update/streamGET /dcim/devices/create/streamGET /virtualization/virtual-machines/create/stream
How it works:
- The stream endpoint creates a
WebSocketSSEBridgeinstance. - The sync service is called with
use_websocket=Trueand the bridge as thewebsocketargument. - As the sync service processes each object, it calls
await websocket.send_json(...)with per-object progress. - The bridge converts each websocket payload into an SSE
stepevent with normalized fields. - The stream endpoint iterates
bridge.iter_sse()and yields each SSE frame to the HTTP client. - On completion, the bridge is closed and a final
completeevent is emitted.
This provides granular progress like:
Processing device pve01Synced device pve01Processing virtual_machine vm101Synced virtual_machine vm101
WebSocket Mode¶
The /ws websocket endpoint provides interactive sync with the same per-object progress, but over a bidirectional WebSocket channel.
The full-update command triggers the same sync logic but sends JSON messages directly to the websocket client.
Tracking and Observability¶
- Sync process records are created in NetBox plugin objects.
- Journal entries are written with summaries and errors.
- WebSocket and SSE workflows provide interactive, real-time status output.
Failure Handling¶
Comprehensive error handling is implemented via decorators and validation utilities:
Error Validation¶
- NetBox responses are validated to ensure they contain required fields before processing.
- Proxmox responses are validated against Pydantic models where typed helpers are available.
- Invalid responses raise typed exceptions such as
NetBoxAPIErrororProxmoxAPIError.
Sync Error Hierarchy¶
Custom exception types provide detailed context:
VMSyncError: Virtual machine sync failuresDeviceSyncError: Node/device sync failuresStorageSyncError: Storage definition failuresNetworkSyncError: Network interface and VLAN failures- Base:
SyncErrorfor generic sync operation failures
Retry and Resilience¶
- Retry helpers apply exponential backoff to transient failures.
- The retry behavior is configurable through
PROXBOX_NETBOX_MAX_RETRIESandPROXBOX_NETBOX_RETRY_DELAY. - Failed attempts are logged with context before retry.
- Final failures bubble up with full error context.
Structured Logging¶
All sync operations use structured logging for observability:
- Phase logging: each distinct phase emits logs with operation and phase context.
- Resource logging: per-object events are logged with resource ID, type, and status.
- Completion logging: sync results include success and failure counts plus elapsed time.
- Error logging: failures include exception details, stack traces, and full operation context.
Response Handling¶
- Domain errors are raised via
ProxboxExceptionand returned as structured JSON by app-level handlers. - Unhandled exceptions are caught by the global exception handler and returned as structured JSON with status 500.
- Route handlers perform best-effort continuation in certain batch loops.
- In SSE streaming mode, errors are emitted as
event: errorframes followed by a finalevent: completewithok: false.
For details on error handling implementation, see proxbox_api/utils/sync_error_handling.py and proxbox_api/utils/structured_logging.py.