Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion pynetbox/core/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,36 @@

def response_loader(req, return_obj, endpoint):
if isinstance(req, list):
return [return_obj(i, endpoint.api, endpoint) for i in req]
# interface/cable traces are lists of lists
if req and isinstance(req[0], list) and isinstance(return_obj, dict):
# we will have to build the response piecewise since the items contained
# within it are of varying types
ret = []
for i in req:
this_sub_ret = []
for ii in i:
# the individual items in a trace are comprised of [<interface/
# frontport/rearport>, <cable>, <interface/frontport/rearport>].
# The last trace can consist of [<interface/frontport/rearport>,
# None, None] if the last hop is not actually connected to anything
if ii:
this_sub_ret.append(
next(
(
return_obj_class(ii, endpoint.api, endpoint)
for (return_obj_uri, return_obj_class) in return_obj.items()
if return_obj_uri in ii["url"]
)
)
)
else:
# the last trace can consist of [cable_a, None, None] if there is no

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy pasta, I will remove

this_sub_ret.append(None)

ret.append(this_sub_ret)
return ret
else:
return [return_obj(i, endpoint.api, endpoint) for i in req]
return return_obj(req, endpoint.api, endpoint)


Expand Down
35 changes: 35 additions & 0 deletions pynetbox/models/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,33 @@ class Interfaces(Record):
interface_connection = InterfaceConnection
connected_endpoint = ConnectedEndpoint

@property
def trace(self):
""" Represents the ``trace`` detail endpoint.

Returns a DetailEndpoint object that is the interface for
viewing response from the trace endpoint.

:returns: :py:class:`.DetailEndpoint`

:Examples:

>>> interface = nb.dcim.interfaces.get(123)
>>> interface.trace.list()
{"get_facts": {"interface_list": ["ge-0/0/0"]}}

"""
return RODetailEndpoint(
self,
"trace",
custom_return={
"dcim/cables": Cables,
"dcim/interfaces": Interfaces,
"dcim/front-ports": FrontPorts,
"dcim/rear-ports": RearPorts,
},
)


class RackReservations(Record):
def __str__(self):
Expand All @@ -99,6 +126,14 @@ class RUs(Record):
device = Devices


class FrontPorts(Record):
device = Devices


class RearPorts(Record):
device = Devices


class Racks(Record):
@property
def units(self):
Expand Down