Skip to content

Devices

Outcome: a device exists — a named switch, in the lab's site, with a type and a role — built by creating the three records it hangs from first. This is the chapter where NetBox's personality shows: a device is not a row you type freely. It is the end of a short chain, and each link is a record of its own.

The chain

To say "there is a switch", NetBox needs four records, in this order:

  1. A manufacturer — who made it. Just a name and a slug.
  2. A device type — the model: a manufacturer plus a model name. ("ExampleSwitch 2400" is a type; the particular box on your shelf is not.)
  3. A device role — what the thing is for: switch, router, server, patch panel. Roles carry a colour, because maps get drawn.
  4. The device — the individual unit: a name, a type, a role, a site, and a status.

Chapter 5's site is the fifth ingredient, already made. The lab created all four through the API in one run — each answered 201, each returned its ID for the next call to spend (transcript t08-api-proof.txt, steps 2 to 5):

POST /api/dcim/manufacturers/   -> 201  (Example Networks)
POST /api/dcim/device-types/    -> 201  (ExampleSwitch 2400)
POST /api/dcim/device-roles/    -> 201  (Lab Switch)
POST /api/dcim/devices/         -> 201  (lab-sw-01, status active)

The device creation itself is one JSON object naming the IDs it hangs from:

{"name":"lab-sw-01","device_type":1,"role":1,"site":1,"status":"active"}

Why the chain is worth it

Each link is shared. The second switch of the same model reuses the manufacturer and the type; the tenth reuses the role too, and a device becomes a name plus three picks. That sharing is what makes the records queryable: "every device of this type", "every switch in this site" are questions the database can answer because the facts live in one place each, instead of being typed — and mistyped — per row. Later, a device type can carry the model's standard parts (its interface and power-port template), so new devices of the type arrive pre-shaped; that template layer is documented-only here.

Status is a statement, not a reading

A device's status — planned, staged, active, offline, decommissioning, and friends — is a claim a person makes, not a measurement NetBox takes. The lab set active on both its devices, and NetBox believed it, because believing records is the job (chapter 1 makes the same point about intent, and chapter 12 about the risk inside it).

The check

Two devices exist when the list says so. The lab added a twin (chapter 8 needs it for a cable) and read the list back:

devices: 2 ['lab-sw-01', 'lab-sw-02']

(Transcript t11-cable.txt.) In the web pages, DCIM → Devices shows the same two rows, each opening onto a page that assembles everything known about the device — including, next chapter, its addresses.