Sync objects between two NetBox instances using the NetBox API.
main.py: CLI entry point for running a sync.sync/: Sync implementations per object type and base sync logic.tests/: Unit tests for core sync behavior.
- Create a virtual environment.
- Install dependencies:
pip install -r requirements.txtFor development tooling and tests:
pip install -r requirements-dev.txtpython main.py \
--master-url https://netbox.example/api/ \
--master-token <MASTER_TOKEN> \
--slave-url https://netbox.example/api/ \
--slave-token <SLAVE_TOKEN>To receive error logs via email, pass SMTP settings (repeat --smtp-to for
multiple recipients). Only error-level logs are emailed.
python main.py \
--master-url https://netbox.example/api/ \
--master-token <MASTER_TOKEN> \
--slave-url https://netbox.example/api/ \
--slave-token <SLAVE_TOKEN> \
--smtp-host smtp.example.com \
--smtp-port 587 \
--smtp-user netbox-sync \
--smtp-password "<SMTP_PASSWORD>" \
--smtp-from netbox-sync@example.com \
--smtp-to ops@example.com \
--smtp-starttlsFor larger sync runs, you can enable pynetbox request threading for both API clients:
python main.py \
--master-url https://netbox.example/api/ \
--master-token <MASTER_TOKEN> \
--slave-url https://netbox.example/api/ \
--slave-token <SLAVE_TOKEN> \
--enable-threadingpytestThe integration tests require access to two NetBox instances. You can use the provided Docker Compose configuration to spin up a test NetBox stack and then point the tests at it.
- Start NetBox:
docker compose -f docker-compose.netbox-test.yml up -d- Create API tokens for the master and slave NetBox instances (or reuse one instance for both while testing) and export the required environment variables:
export NETBOX_MASTER_URL="http://localhost:8080/api/"
export NETBOX_MASTER_TOKEN="..."
export NETBOX_SLAVE_URL="http://localhost:8080/api/"
export NETBOX_SLAVE_TOKEN="..."- Run the integration test:
pytest tests/test_integration_virtualization.py- The
Syncbase class encapsulates common diff/creation logic. - Errors during object sync are logged and do not stop the full sync run.
- Each sync module can override
pre_sync,post_sync, orpost_createfor object-specific behavior.