Unable to Add/Update MAC Address #10807

Closed
opened 2025-12-29 21:36:08 +01:00 by adam · 2 comments
Owner

Originally created by @giffordjim on GitHub (Feb 25, 2025).

Deployment Type

Self-hosted

NetBox Version

v,4.2.3

Python Version

3.11

Steps to Reproduce

Use the following script. Says everything works, but no update of the MAC Address.
`import requests
import json

netbox_url = "http://192.168.5.22"
netbox_token = "token"

http_headers = {
"Content-Type": "application/json",
"Authorization": f"Token {netbox_token}",
}

interface_data = {
"device": 1, # Replace with the actual device ID
"name": "test-0/0/0",
"type": "1000base-t",
"mac_address": "00:11:22:33:44:55",
}

url = f"{netbox_url}/api/dcim/interfaces/"

response = requests.post(url, headers=http_headers, data=json.dumps(interface_data), verify=False)

if response.status_code == 201:
print("Interface created successfully!")
print(response.json())
else:
print(f"Error creating interface: {response.status_code}")
print(response.json())

Expected Behavior

To create of port and MAC/address

Observed Behavior

Script gives the following output but mac_address is not populated confirmed in the GUI
Output
Interface created successfully! {'id': 9071, 'url': 'http://192.168.5.22/api/dcim/interfaces/9071/', 'display_url': 'http://192.168.5.22/dcim/interfaces/9071/', 'display': 'test-0/0/0', 'device': {'id': 41, 'url': 'http://192.168.5.22/api/dcim/devices/41/', 'display': 'WCL000', 'name': 'WL000', 'description': 'WAN Connection Layer Switch'}, 'vdcs': [], 'module': None, 'name': 'test-0/0/0', 'label': '', 'type': {'value': '1000base-t', 'label': '1000BASE-T (1GE)'}, 'enabled': True, 'parent': None, 'bridge': None, 'lag': None, 'mtu': None, 'mac_address': None, 'primary_mac_address': None, 'mac_addresses': [], 'speed': None, 'duplex': None, 'wwn': None, 'mgmt_only': False, 'description': '', 'mode': None, 'rf_role': None, 'rf_channel': None, 'poe_mode': None, 'poe_type': None, 'rf_channel_frequency': None, 'rf_channel_width': None, 'tx_power': None, 'untagged_vlan': None, 'tagged_vlans': [], 'qinq_svlan': None, 'vlan_translation_policy': None, 'mark_connected': False, 'cable': None, 'cable_end': None, 'wireless_link': None, 'link_peers': [], 'link_peers_type': None, 'wireless_lans': [], 'vrf': None, 'l2vpn_termination': None, 'connected_endpoints': None, 'connected_endpoints_type': None, 'connected_endpoints_reachable': None, 'tags': [], 'custom_fields': {}, 'created': '2025-02-25T15:49:43.489529Z', 'last_updated': '2025-02-25T15:49:43.489557Z', 'count_ipaddresses': 0, 'count_fhrp_groups': 0, '_occupied': False}

Originally created by @giffordjim on GitHub (Feb 25, 2025). ### Deployment Type Self-hosted ### NetBox Version v,4.2.3 ### Python Version 3.11 ### Steps to Reproduce Use the following script. Says everything works, but no update of the MAC Address. `import requests import json netbox_url = "http://192.168.5.22" netbox_token = "token" http_headers = { "Content-Type": "application/json", "Authorization": f"Token {netbox_token}", } interface_data = { "device": 1, # Replace with the actual device ID "name": "test-0/0/0", "type": "1000base-t", "mac_address": "00:11:22:33:44:55", } url = f"{netbox_url}/api/dcim/interfaces/" response = requests.post(url, headers=http_headers, data=json.dumps(interface_data), verify=False) if response.status_code == 201: print("Interface created successfully!") print(response.json()) else: print(f"Error creating interface: {response.status_code}") print(response.json()) ### Expected Behavior To create of port and MAC/address ### Observed Behavior Script gives the following output but mac_address is not populated confirmed in the GUI Output `Interface created successfully! {'id': 9071, 'url': 'http://192.168.5.22/api/dcim/interfaces/9071/', 'display_url': 'http://192.168.5.22/dcim/interfaces/9071/', 'display': 'test-0/0/0', 'device': {'id': 41, 'url': 'http://192.168.5.22/api/dcim/devices/41/', 'display': 'WCL000', 'name': 'WL000', 'description': 'WAN Connection Layer Switch'}, 'vdcs': [], 'module': None, 'name': 'test-0/0/0', 'label': '', 'type': {'value': '1000base-t', 'label': '1000BASE-T (1GE)'}, 'enabled': True, 'parent': None, 'bridge': None, 'lag': None, 'mtu': None, 'mac_address': None, 'primary_mac_address': None, 'mac_addresses': [], 'speed': None, 'duplex': None, 'wwn': None, 'mgmt_only': False, 'description': '', 'mode': None, 'rf_role': None, 'rf_channel': None, 'poe_mode': None, 'poe_type': None, 'rf_channel_frequency': None, 'rf_channel_width': None, 'tx_power': None, 'untagged_vlan': None, 'tagged_vlans': [], 'qinq_svlan': None, 'vlan_translation_policy': None, 'mark_connected': False, 'cable': None, 'cable_end': None, 'wireless_link': None, 'link_peers': [], 'link_peers_type': None, 'wireless_lans': [], 'vrf': None, 'l2vpn_termination': None, 'connected_endpoints': None, 'connected_endpoints_type': None, 'connected_endpoints_reachable': None, 'tags': [], 'custom_fields': {}, 'created': '2025-02-25T15:49:43.489529Z', 'last_updated': '2025-02-25T15:49:43.489557Z', 'count_ipaddresses': 0, 'count_fhrp_groups': 0, '_occupied': False} `
adam closed this issue 2025-12-29 21:36:09 +01:00
Author
Owner

@ninabel commented on GitHub (Feb 26, 2025):

I had similar problem, but my bug was closed.
https://github.com/netbox-community/netbox/issues/18708
The source of problem that Mac Addresses are separate objects now, so you have to

  1. create Interface
  2. create mac_address object, assigned to that interface
  3. update interface to set primary mac address.
@ninabel commented on GitHub (Feb 26, 2025): I had similar problem, but my bug was closed. https://github.com/netbox-community/netbox/issues/18708 The source of problem that Mac Addresses are separate objects now, so you have to 1) create Interface 2) create mac_address object, assigned to that interface 3) update interface to set primary mac address.
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2025):

Beginning with NetBox v4.2, MAC addresses are managed as independent entities, which enables the assignment of multiple MAC addresses to a common interface (see #4867). The mac_address field is no longer used to set the MAC address of an interface; it is now a read-only field which provides the primary assigned MAC address (if any) for backward compatibility.

@jeremystretch commented on GitHub (Feb 28, 2025): Beginning with NetBox v4.2, MAC addresses are managed as independent entities, which enables the assignment of multiple MAC addresses to a common interface (see #4867). The `mac_address` field is no longer used to set the MAC address of an interface; it is now a read-only field which provides the primary assigned MAC address (if any) for backward compatibility.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10807