0

Get Interface

by
Published today

Get one interface by id, as raw NetBox JSON.

Script netbox Verified

The script

Submitted by hugo989 Python3
Verified 3 hours ago
1
# py312
2
# requirements:
3
# pynetbox==7.9.0
4

5

6
from typing import TypedDict
7

8
import pynetbox
9

10

11
class netbox(TypedDict):
12
    url: str
13
    token: str
14

15

16
def api(auth: netbox):
17
    # pynetbox adds /api itself; the resource URL may already end with it.
18
    return pynetbox.api(
19
        auth["url"].rstrip("/").removesuffix("/api"), token=auth["token"]
20
    )
21

22

23
def main(
24
    auth: netbox,
25
    interface_id: int,
26
):
27
    """
28
    Get Interface
29
    Get one interface by id, as raw NetBox JSON.
30
    """
31
    record = api(auth).dcim.interfaces.get(interface_id)
32
    if record is None:
33
        raise ValueError(f"No interface with id {interface_id}")
34
    return dict(record)
35