Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetBox v3.3 has multiple endpoints for dcim.cables (appears as 'AttributeError: object has no attribute "id"') #491

Open
maznu opened this issue Aug 24, 2022 · 11 comments
Labels
pynetbox status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@maznu
Copy link

maznu commented Aug 24, 2022

When talking to NetBox v3.3, pynetbox v6.6.2 chokes when POSTing to dcim.cable by raising exception AttributeError: object has no attribute "id"

This is because in NetBox v3.2 and earlier:

{
    "id": 1,
    "termination_a_type": "circuits.circuittermination",
    "termination_a_id": 1,
    "termination_a": {
        ...
    }
    ...
}

Whereas NetBox v3.3 has a list of dicts:

{
    "id": 1,
    "a_terminations": [
        {
            "object_type": "dcim.interface",
            "object_id": 42,
            ...
        }
    ]
    ...
}
@maznu maznu changed the title NetBox v3.3 has multiple endpoints for cables NetBox v3.3 has multiple endpoints for dcim.cables (appears as 'AttributeError: object has no attribute "id"') Aug 24, 2022
@jcollie
Copy link

jcollie commented Sep 7, 2022

This does not appear to be a problem when creating a cable, only when updating an existing one.

@PaulWestphal
Copy link

PaulWestphal commented Oct 20, 2022

This is also an issue when GETting cables. a_terminations and b_terminations are returned as empty lists.

e: a_terminations and b_terminations are not in fact empty lists. They just show up as empty lists in the cable string representation. As a workaround, cable.termination_a.device.id can be replaced like this: cable.a_terminations[0].object.device.id

@egreenspan2
Copy link

Any ideas on workaround for this? Getting works fine for me, but updates are failing using pynetbox library

@arthanson
Copy link
Collaborator

I've got this on my list to work on next, but will take a while before I can get it updated. If you see any other APIs broken for 3.3, please let me know.

@arthanson arthanson self-assigned this Oct 24, 2022
@karolyczovek
Copy link

Any updates here?

allenrobel added a commit to allenrobel/netbox-tools that referenced this issue Nov 12, 2022
Add link to bug causing update to fail.

netbox-community/pynetbox#491

Add commented update method for when issue 491 is fixed.

generate_args_create_or_update: move label to a separate method.

Other minor formatting changes.
@arthanson
Copy link
Collaborator

@karolyczovek @maznu @jcollie would any of you be able to get the feature branch and test it out for the cabling a_terminations changes? The feature branch will only work for NetBox 3.3 due to the changes. I'd like to get it tested more if possible before cutting a new release.

@jcollie
Copy link

jcollie commented Dec 8, 2022

So far so good. Not much time to do anything serious with it yet. Tomorrow I should be able to do some more testing. One unrelated thing that I noticed tonight is that the link peers on a cable termination are not cast to a specific model but are left as a generic record.

@arthanson
Copy link
Collaborator

Thanks @jcollie The link_peers looks like a bit of a different issue, I'll open a separate issue for it but will probably want to change the API in NetBox (probably 3.5 release) as the return for these types of things currently isn't consistent.

@jcollie
Copy link

jcollie commented Dec 8, 2022

Things seem to be working well today so far. One thing that would be nice would be the ability to create a cable just by passing the whole object (like in the commented-out code) vs passing a dict.

    cable = nb.dcim.cables.create(
            # a_terminations=[remote_interface],
            # b_terminations=[local_interface],
            a_terminations=[
                {
                    "object_type": "dcim.interface",
                    "object_id": local_interface.id,
                }
            ],
            b_terminations=[
                {
                    "object_type": "dcim.interface",
                    "object_id": remote_interface.id,
                }
            ],
        )

@whizkidTRW
Copy link

whizkidTRW commented Apr 18, 2023

I just upgraded to 7.0.1 and now I don't get the object_type or object_id parameters any more (they're still present in the NetBox API). I'm specifically working with the dcim.cables endpoint. What happened?

I'm using NetBox 3.3.10 and I upgraded from pynetbox 6.6.2

6.6.2:

{'a_terminations': [{'object': {'_occupied': True,
                                'cable': 57,
                                'device': {'display': 'ESC2-MI-RT-CN-01-01',
                                           'id': 547,
                                           'name': 'ESC2-MI-RT-CN-01-01',
                                           'url': 'https://netbox.XXXXXXXX.com/api/dcim/devices/547/'},
                                'display': '1',
                                'id': 9670,
                                'name': '1',
                                'url': 'https://netbox.XXXXXXXX.com/api/dcim/interfaces/9670/'},
                     'object_id': 9670,
                     'object_type': 'dcim.interface'}],
 'b_terminations': [{'object': {'_occupied': True,
                                'cable': 57,
                                'device': {'display': 'ESC2-MI-OL-CX-01-01',
                                           'id': 836,
                                           'name': 'ESC2-MI-OL-CX-01-01',
                                           'url': 'https://netbox.XXXXXXXX.com/api/dcim/devices/836/'},
                                'display': '1/1/x1',
                                'id': 9923,
                                'name': '1/1/x1',
                                'url': 'https://netbox.XXXXXXXX.com/api/dcim/interfaces/9923/'},
                     'object_id': 9923,
                     'object_type': 'dcim.interface'}]
}

7.0.1:

{'a_terminations': [{'_occupied': True,
                     'cable': 57,
                     'device': {'display': 'ESC2-MI-RT-CN-01-01',
                                'id': 547,
                                'name': 'ESC2-MI-RT-CN-01-01',
                                'url': 'https://netbox.XXXXXXXX.com/api/dcim/devices/547/'},
                     'display': '1',
                     'id': 9670,
                     'name': '1',
                     'url': 'https://netbox.XXXXXXXX.com/api/dcim/interfaces/9670/'}],
 'b_terminations': [{'_occupied': True,
                     'cable': 57,
                     'device': {'display': 'ESC2-MI-OL-CX-01-01',
                                'id': 836,
                                'name': 'ESC2-MI-OL-CX-01-01',
                                'url': 'https://netbox.XXXXXXXX.com/api/dcim/devices/836/'},
                     'display': '1/1/x1',
                     'id': 9923,
                     'name': '1/1/x1',
                     'url': 'https://netbox.XXXXXXXX.com/api/dcim/interfaces/9923/'}]
}

@markkuleinio
Copy link
Contributor

Looks like one level of attributes are missing:

  • object
  • object_id
  • object_type

@abhi1693 abhi1693 added type: bug A confirmed report of unexpected behavior in the application status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Aug 28, 2023
@jeremystretch jeremystretch added the pynetbox label Nov 1, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pynetbox status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

10 participants