netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
538 stars 165 forks source link

Problem accesing rearports, seems endpoint url is wrong (should be rear-ports) #617

Closed nicolatron closed 3 weeks ago

nicolatron commented 1 month ago

pynetbox version

v7.3.3

NetBox version

v4.0.3

Python version

3.11

Steps to Reproduce

int_a = nb.dcim.rearports.get(name="RP 1", device=str("device_name")

Expected Behavior

Getting a pointer to given rearport, i plan to then use it to connect with another rear port using:

               result = nb.dcim.cables.create(
                    a_terminations=[{
                        "object_type" : "dcim.rearport",
                        "object_id" : int_a.id
                        }],
                    b_terminations=[{
                        "object_type" : "dcim.rearport",
                        "object_id" : int_b.id
                        }]
                    )

But can't get there yet.

Observed Behavior

pynetbox.core.query.RequestError: The requested url: https://netbox.mydomain.com/api/dcim/rearports/?name=RP+1&device=J1%3AC0F1%3AOV01PAT02V&limit=0 could not be found.

If I go to https://netbox.mydomain.com/api/dcim/rear-ports/?name=RP+1&device=J1%3AC0F1%3AOV01PAT02V&limit=0 instead the correct information is there.

Looking at pynetbox/models/dcim.py there is a TraceableRecord class with an entry: "dcim/rear-ports": RearPorts,

Not sure what's preventing that from being used in this case.

markkuleinio commented 4 weeks ago

int_a = nb.dcim.rearports.get(name="RP 1", device=str("device_name")

If you say that the correct URL has /dcim/rear-ports/, then you need to call nb.dcim.rear_ports.get() (= replace dash with underscore)

nicolatron commented 3 weeks ago

Thank you very much. This works like a charm. int_a = nb.dcim.rear_ports.get(name="RP 1",device_id=orig_device.id) I see now that it is clearly mentioned in documentation I failed to read (like here), and not a bug at all.