# py312
# requirements:
# pynetbox==7.9.0
from typing import TypedDict
import pynetbox
class netbox(TypedDict):
url: str
token: str
def api(auth: netbox):
# pynetbox adds /api itself; the resource URL may already end with it.
return pynetbox.api(
auth["url"].rstrip("/").removesuffix("/api"), token=auth["token"]
)
def main(
auth: netbox,
device_id: int,
):
"""
Get Device
Get one device by id, as raw NetBox JSON (platform, custom_fields, primary IPs…).
"""
record = api(auth).dcim.devices.get(device_id)
if record is None:
raise ValueError(f"No device with id {device_id}")
return dict(record)
Submitted by hugo989 3 hours ago