Skip to content

hetzner: fix disk sizes before NetBox 4.1 and handle API errors - #626

Merged
semx merged 2 commits into
developmentfrom
fix/hetzner-units-auth
Nov 7, 2026
Merged

semx merged 2 commits into
developmentfrom
fix/hetzner-units-auth

Conversation

@semx

@semx semx commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Two fixes for the Hetzner source, one commit each.

Disk sizes on NetBox 3.7 to 4.0

The volume size was always multiplied by 1024. Before 4.1 NetBox stores virtual disk sizes in GB (#413), so a 10 GB volume ended up as 10240 GB. The size is now converted to MB only on NetBox 4.1+, like the vmware and aws sources do. Nothing changes on 4.1+, and disks written with the wrong size on an older NetBox get fixed on the next run.

Bad token / API not reachable

init_successful was always True and the first API call happened in apply(), so a revoked token or an unreachable API ended the whole run with a bare traceback

hcloud._exceptions.APIException: unable to authenticate (unauthorized)

and none of the other sources got synced either.

  • __init__() now makes one small request (GET /servers?per_page=1). If it fails, the error is logged and the source is skipped, the same way vmware and ovirt handle a failed login. The other sources still sync, and netbox-sync disables pruning for that run, so the objects of the Hetzner source stay in NetBox (tagged as orphaned until the token works again).
  • If an API call fails later in apply() (the server list or a volume lookup), the Hetzner error is logged and the run stops like it does for the aws source ("No NetBox writes or pruning will be performed."). Skipping the source at that point isn't safe: pruning is already on, so its objects would be marked orphaned and eventually deleted.

The if not token check in apply() is gone: api_token is mandatory, so the config parser already exits on an empty value.

Tests are in the new tests/test_hetzner_source.py; they feed hcloud with responses shaped like the Hetzner API (401 for an unknown token). Also checked end to end against a stub Hetzner API and a fake NetBox 4.0.11 and 4.3.0.

@semx
semx merged commit b6ee992 into development Nov 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant