Update (change) cable via API. #2404

Closed
opened 2025-12-29 17:25:47 +01:00 by adam · 1 comment
Owner

Originally created by @VictorPavlushin on GitHub (Feb 22, 2019).

Environment

  • Python version: 3.6.6
  • NetBox version: Example: 2.5.5

Perhaps the mechanism for updating the port information does not work or does not exist.

We have cable:

{

"id": 621,
"termination_a_type": "dcim.interface",
"termination_a_id": 10488,
"termination_a": {
    "id": 10488,
    "url": "http://netboxserver.local/api/dcim/interfaces/10488/",
    "device": {
        "id": 700,
        "url": "http://netboxserver.local/api/dcim/devices/700/",
        "name": "switch1",
        "display_name": "switch1"
    },
    "name": "Ethernet1/1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"termination_b_type": "dcim.interface",
"termination_b_id": 8492,
"termination_b": {
    "id": 8492,
    "url": "http://netboxserver.local/api/dcim/interfaces/8492/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "enp129s0f1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"type": null,
"status": {
    "value": true,
    "label": "Connected"
},
"label": "",
"color": "",
"length": null,
"length_unit": null

}

We have server ports:

{

"id": 8491,
"device": {
    "id": 689,
    "url": "http://netboxserver.local/api/dcim/devices/689/",
    "name": "server1",
    "display_name": "server1"
},
"name": "enp129s0f0",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 8489,
    "url": "http://netboxserver.local/api/dcim/interfaces/8489/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "team0",
    "cable": null,
    "connection_status": null
},
"mtu": 1500,
"mac_address": "3C:E8:24:87:C3:DD",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": null,
"connected_endpoint": null,
"connection_status": null,
"cable": null,
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

{

"id": 8492,
"device": {
    "id": 689,
    "url": "http://netboxserver.local/api/dcim/devices/689/",
    "name": "server1",
    "display_name": "server1"
},
"name": "enp129s0f1",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 8489,
    "url": "http://netboxserver.local/api/dcim/interfaces/8489/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "team0",
    "cable": null,
    "connection_status": null
},
"mtu": 1500,
"mac_address": "3C:E8:24:87:C3:DE",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": "dcim.interface",
"connected_endpoint": {
    "id": 10488,
    "url": "http://netboxserver.local/api/dcim/interfaces/10488/",
    "device": {
        "id": 700,
        "url": "http://netboxserver.local/api/dcim/devices/700/",
        "name": "switch1",
        "display_name": "switch1"
    },
    "name": "Ethernet1/1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"connection_status": {
    "value": true,
    "label": "Connected"
},
"cable": {
    "id": 621,
    "url": "http://netboxserver.local/api/dcim/cables/621/",
    "label": ""
},
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

Switch port where cable is plugged:

{

"id": 10488,
"device": {
    "id": 700,
    "url": "http://netboxserver.local/api/dcim/devices/700/",
    "name": "switch1",
    "display_name": "switch1"
},
"name": "Ethernet1/1",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 10475,
    "url": "http://netboxserver.local/api/dcim/interfaces/10475/",
    "device": {
        "id": 700,
        "url": "http://netboxserver.local/api/dcim/devices/700/",
        "name": "switch1",
        "display_name": "switch1"
    },
    "name": "port-channel31",
    "cable": null,
    "connection_status": null
},
"mtu": null,
"mac_address": "A0:93:51:08:D9:68",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": "dcim.interface",
"connected_endpoint": {
    "id": 8492,
    "url": "http://netboxserver.local/api/dcim/interfaces/8492/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "enp129s0f1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"connection_status": {
    "value": true,
    "label": "Connected"
},
"cable": {
    "id": 621,
    "url": "http://netboxserver.local/api/dcim/cables/621/",
    "label": ""
},
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

Update cable - change server port
curl -X PUT "http://netboxserver.local/api/dcim/cables/621/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken:....." -d "{ \"termination_a_type\": \"dcim.interface\", \"termination_a_id\": 10488, \"termination_b_type\": \"dcim.interface\", \"termination_b_id\": 8491, \"status\": true}"

Response body:

{

"id": 621,
"termination_a_type": "dcim.interface",
"termination_a_id": 10488,
"termination_a": {
  "id": 10488,
  "url": "http://netboxserver.local/api/dcim/interfaces/10488/",
  "device": {
    "id": 700,
    "url": "http://netboxserver.local/api/dcim/devices/700/",
    "name": "switch1",
    "display_name": "switch1"
  },
  "name": "Ethernet1/1",
  "cable": 621,
  "connection_status": {
    "value": true,
    "label": "Connected"
  }
},
"termination_b_type": "dcim.interface",
"termination_b_id": 8491,
"termination_b": {
  "id": 8491,
  "url": "http://netboxserver.local/api/dcim/interfaces/8491/",
  "device": {
    "id": 689,
    "url": "http://netboxserver.local/api/dcim/devices/689/",
    "name": "server1",
    "display_name": "server1"
  },
  "name": "enp129s0f0",
  "cable": 621,
  "connection_status": null
},
"type": null,
"status": {
  "value": true,
  "label": "Connected"
},
"label": "",
"color": "",
"length": null,
"length_unit": null

}

All is well.
But there is a problem with the interfaces.
On the port to which the cable was switched - information appeared about the cable but about connected_endpoint not:

{

"id": 8491,
"device": {
    "id": 689,
    "url": "http://netboxserver.local/api/dcim/devices/689/",
    "name": "server1",
    "display_name": "server1"
},
"name": "enp129s0f0",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 8489,
    "url": "http://netboxserver.local/api/dcim/interfaces/8489/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "team0",
    "cable": null,
    "connection_status": null
},
"mtu": 1500,
"mac_address": "3C:E8:24:87:C3:DD",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": null,
"connected_endpoint": null,
"connection_status": null,
"cable": {
    "id": 621,
    "url": "http://netboxserver.local/api/dcim/cables/621/",
    "label": ""
},
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

From the port from which you switched, the information is not deleted:

{

"id": 8492,
"device": {
    "id": 689,
    "url": "http://netboxserver.local/api/dcim/devices/689/",
    "name": "server1",
    "display_name": "server1"
},
"name": "enp129s0f1",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 8489,
    "url": "http://netboxserver.local/api/dcim/interfaces/8489/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "team0",
    "cable": null,
    "connection_status": null
},
"mtu": 1500,
"mac_address": "3C:E8:24:87:C3:DE",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": "dcim.interface",
"connected_endpoint": {
    "id": 10488,
    "url": "http://netboxserver.local/api/dcim/interfaces/10488/",
    "device": {
        "id": 700,
        "url": "http://netboxserver.local/api/dcim/devices/700/",
        "name": "switch1",
        "display_name": "switch1"
    },
    "name": "Ethernet1/1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"connection_status": {
    "value": true,
    "label": "Connected"
},
"cable": {
    "id": 621,
    "url": "http://netboxserver.local/api/dcim/cables/621/",
    "label": ""
},
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

On the switch port information has not been updated:

{

"id": 10488,
"device": {
    "id": 700,
    "url": "http://netboxserver.local/api/dcim/devices/700/",
    "name": "switch1",
    "display_name": "switch1"
},
"name": "Ethernet1/1",
"form_factor": {
    "value": 1200,
    "label": "SFP+ (10GE)"
},
"enabled": true,
"lag": {
    "id": 10475,
    "url": "http://netboxserver.local/api/dcim/interfaces/10475/",
    "device": {
        "id": 700,
        "url": "http://netboxserver.local/api/dcim/devices/700/",
        "name": "switch1",
        "display_name": "switch1"
    },
    "name": "port-channel31",
    "cable": null,
    "connection_status": null
},
"mtu": null,
"mac_address": "A0:93:51:08:D9:68",
"mgmt_only": false,
"description": "",
"connected_endpoint_type": "dcim.interface",
"connected_endpoint": {
    "id": 8492,
    "url": "http://netboxserver.local/api/dcim/interfaces/8492/",
    "device": {
        "id": 689,
        "url": "http://netboxserver.local/api/dcim/devices/689/",
        "name": "server1",
        "display_name": "server1"
    },
    "name": "enp129s0f1",
    "cable": 621,
    "connection_status": {
        "value": true,
        "label": "Connected"
    }
},
"connection_status": {
    "value": true,
    "label": "Connected"
},
"cable": {
    "id": 621,
    "url": "http://netboxserver.local/api/dcim/cables/621/",
    "label": ""
},
"mode": null,
"untagged_vlan": null,
"tagged_vlans": [],
"tags": [],
"count_ipaddresses": 0

}

Originally created by @VictorPavlushin on GitHub (Feb 22, 2019). ### Environment * Python version: 3.6.6 * NetBox version: Example: 2.5.5 Perhaps the mechanism for updating the port information does not work or does not exist. We have cable: > { "id": 621, "termination_a_type": "dcim.interface", "termination_a_id": 10488, "termination_a": { "id": 10488, "url": "http://netboxserver.local/api/dcim/interfaces/10488/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "termination_b_type": "dcim.interface", "termination_b_id": 8492, "termination_b": { "id": 8492, "url": "http://netboxserver.local/api/dcim/interfaces/8492/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "type": null, "status": { "value": true, "label": "Connected" }, "label": "", "color": "", "length": null, "length_unit": null } We have server ports: > { "id": 8491, "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f0", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 8489, "url": "http://netboxserver.local/api/dcim/interfaces/8489/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "team0", "cable": null, "connection_status": null }, "mtu": 1500, "mac_address": "3C:E8:24:87:C3:DD", "mgmt_only": false, "description": "", "connected_endpoint_type": null, "connected_endpoint": null, "connection_status": null, "cable": null, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } > { "id": 8492, "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f1", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 8489, "url": "http://netboxserver.local/api/dcim/interfaces/8489/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "team0", "cable": null, "connection_status": null }, "mtu": 1500, "mac_address": "3C:E8:24:87:C3:DE", "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 10488, "url": "http://netboxserver.local/api/dcim/interfaces/10488/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 621, "url": "http://netboxserver.local/api/dcim/cables/621/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } Switch port where cable is plugged: > { "id": 10488, "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 10475, "url": "http://netboxserver.local/api/dcim/interfaces/10475/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "port-channel31", "cable": null, "connection_status": null }, "mtu": null, "mac_address": "A0:93:51:08:D9:68", "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 8492, "url": "http://netboxserver.local/api/dcim/interfaces/8492/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 621, "url": "http://netboxserver.local/api/dcim/cables/621/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } Update cable - change server port `curl -X PUT "http://netboxserver.local/api/dcim/cables/621/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken:....." -d "{ \"termination_a_type\": \"dcim.interface\", \"termination_a_id\": 10488, \"termination_b_type\": \"dcim.interface\", \"termination_b_id\": 8491, \"status\": true}"` Response body: > { "id": 621, "termination_a_type": "dcim.interface", "termination_a_id": 10488, "termination_a": { "id": 10488, "url": "http://netboxserver.local/api/dcim/interfaces/10488/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "termination_b_type": "dcim.interface", "termination_b_id": 8491, "termination_b": { "id": 8491, "url": "http://netboxserver.local/api/dcim/interfaces/8491/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f0", "cable": 621, "connection_status": null }, "type": null, "status": { "value": true, "label": "Connected" }, "label": "", "color": "", "length": null, "length_unit": null } All is well. But there is a problem with the interfaces. On the port to which the cable was switched - information appeared about the cable but about connected_endpoint not: > { "id": 8491, "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f0", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 8489, "url": "http://netboxserver.local/api/dcim/interfaces/8489/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "team0", "cable": null, "connection_status": null }, "mtu": 1500, "mac_address": "3C:E8:24:87:C3:DD", "mgmt_only": false, "description": "", "connected_endpoint_type": null, "connected_endpoint": null, "connection_status": null, "cable": { "id": 621, "url": "http://netboxserver.local/api/dcim/cables/621/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } From the port from which you switched, the information is not deleted: > { "id": 8492, "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f1", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 8489, "url": "http://netboxserver.local/api/dcim/interfaces/8489/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "team0", "cable": null, "connection_status": null }, "mtu": 1500, "mac_address": "3C:E8:24:87:C3:DE", "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 10488, "url": "http://netboxserver.local/api/dcim/interfaces/10488/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 621, "url": "http://netboxserver.local/api/dcim/cables/621/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } On the switch port information has not been updated: > { "id": 10488, "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "Ethernet1/1", "form_factor": { "value": 1200, "label": "SFP+ (10GE)" }, "enabled": true, "lag": { "id": 10475, "url": "http://netboxserver.local/api/dcim/interfaces/10475/", "device": { "id": 700, "url": "http://netboxserver.local/api/dcim/devices/700/", "name": "switch1", "display_name": "switch1" }, "name": "port-channel31", "cable": null, "connection_status": null }, "mtu": null, "mac_address": "A0:93:51:08:D9:68", "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 8492, "url": "http://netboxserver.local/api/dcim/interfaces/8492/", "device": { "id": 689, "url": "http://netboxserver.local/api/dcim/devices/689/", "name": "server1", "display_name": "server1" }, "name": "enp129s0f1", "cable": 621, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 621, "url": "http://netboxserver.local/api/dcim/cables/621/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 }
adam closed this issue 2025-12-29 17:25:47 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 22, 2019):

This issue has been closed as it does not conform to one of the provided templates as required by the contributing guide. If you'd like to request that your issue be re-opened, please first update the content so that it matches the appropriate template (this may require rewriting your issue entirely).

@jeremystretch commented on GitHub (Feb 22, 2019): This issue has been closed as it does not conform to one of the [provided templates](https://github.com/digitalocean/netbox/issues/new/choose) as required by the [contributing guide](https://github.com/digitalocean/netbox/blob/master/CONTRIBUTING.md). If you'd like to request that your issue be re-opened, please first update the content so that it matches the appropriate template (this may require rewriting your issue entirely).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2404