netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
567 stars 168 forks source link

Cable Creation Failed #522

Closed HarishankarYellapragada closed 1 year ago

HarishankarYellapragada commented 1 year ago
cable = nb.dcim.cables.create(termination_a_type='dcim.interface',termination_a_id=interface_a.id, termination_b_type='dcim.interface',termination_b_id=interface_b.id, status="connected")
print(cable.id)

output =

switch-01
Interface_a: Ethernet1/18
Interface_a id: 2354
Interface_b: TenGigabitEthernet1/49
Interface_b id: 2283
pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'__all__': ['Must define A and B terminations when creating a new cable.']}

Seeking advice on how to write the script to create a cable.

HarishankarYellapragada commented 1 year ago

Works fine with this method

   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,
                }
            ],
        )