Prefixes and Addresses
Outcome: the IPAM half of the map works — a prefix exists, an address inside it is assigned to a device's interface, and the device names that address as its primary one. If DCIM is NetBox's answer to "what is where", IPAM is its answer to "which addresses are spoken for" — the question whose spreadsheet failure mode is two machines with the same address and a bad afternoon.
Prefixes: the pools
A prefix is a block of addresses in
CIDR notation — 10.250.0.0/24 is the
block of 256 addresses from 10.250.0.0
to 10.250.0.255. Prefixes can contain
other prefixes (a /16 carved into /24s)
and belong, optionally, to a site. The
lab created its block in one call
(transcript t08-api-proof.txt, step 7):
curl -s -H "Authorization: Bearer nbt_<key>.<token>" \
-X POST http://127.0.0.1:18080/api/ipam/prefixes/ \
-d '{"prefix":"10.250.0.0/24","site":1,
"description":"Invented lab prefix"}'
HTTP 201
A prefix records intent about space: its status, which addresses inside it are already handed out (NetBox computes the used percentage from the address records), and — the point — which are still free.
Addresses: the handouts
An IP address record is one address, with its mask, and optionally an assignment: the interface it belongs to. An address that exists but is assigned to nothing is a reservation; an address assigned to an interface is a fact about a device. The lab created one of the second kind, on the interface chapter 8 makes (step 8 of the same transcript):
{"address":"10.250.0.10/24",
"assigned_object_type":"dcim.interface",
"assigned_object_id":1,
"description":"lab-sw-01 management address"}
Read back, the record shows the link
in so many words: assigned to:
dcim.interface 1.
The primary address
A device with interfaces and addresses still leaves one question ambiguous: "the device's address" — the one management tools should use. NetBox makes you say it: the device's primary IP field points at one of its addresses. The lab set it with a PATCH — the API's partial-update verb, which changes one field and leaves the rest alone (step 9):
curl -s -X PATCH .../api/dcim/devices/1/ \
-d '{"primary_ip4":1}'
After that, the device record itself carries its primary address, and a script asking about the device — not about addresses — gets the answer in one read. This is the shape automation actually consumes, and it exists only because somebody made the small, explicit decision the field represents.
The rules doing quiet work
Two behaviours are worth naming because they are the spreadsheet failures being prevented. NetBox tracks overlapping and duplicate space: an address inside a prefix is accounted against it, and where your settings forbid it, a duplicate assignment is refused rather than filed. And addresses have statuses of their own — active, reserved, deprecated, handed out by DHCP — so "free" is a query, not a guess.
The check
The prefix list closes the loop:
count: 1 | first prefix: 10.250.0.0/24
(Step 10 of t08-api-proof.txt.) In the
web pages, IPAM → Prefixes shows the
block with its utilisation, and the
device page from chapter 6 now shows
10.250.0.10/24 as lab-sw-01's primary
address.