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