# 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,
interface_id: int,
):
"""
Get Interface
Get one interface by id, as raw NetBox JSON.
"""
record = api(auth).dcim.interfaces.get(interface_id)
if record is None:
raise ValueError(f"No interface with id {interface_id}")
return dict(record)
Submitted by hugo989 3 hours ago