DCIM/Devices: Modules not added #10410

Closed
opened 2025-12-29 21:31:06 +01:00 by adam · 0 comments
Owner

Originally created by @heidl89 on GitHub (Oct 25, 2024).

Deployment Type

Self-hosted

Triage priority

I'm a NetBox Labs customer

NetBox Version

v4.1.4

Python Version

3.12

Steps to Reproduce

  1. Create a custom script "new device"
  2. Add some data to "Device" Object
  3. device.save()
  4. add interface, assign ip to interface
  5. settattr -> primary ip
  6. device.save()

Within the second save, modules (power outlets, console ports) were not added in the gui.
The Change Log of the device says the modules are generated....

Important:
If i skip the second device.save() the modules were created...
But the ip assignment (settattr) is not added...

My code:

def run (self, data, commit):

if not data['gps_lat']:   
        data['gps_lat'] = 0
if not data['gps_long']:
        data['gps_long'] = 0



device = Device(
        name = data['device_name'],
        device_type = data['device_type'],
        role = data['device_role'],
        status = data['status'],
        latitude = data['gps_lat'],
        longitude = data['gps_long'],
        site_id = data['site'].id
 )
 
if data['location']:             
        device.location = data['location']

device.full_clean()
device.save()


interface = Interface(
        device = device,
        name = "vmgmt0",
        type = InterfaceTypeChoices.TYPE_VIRTUAL,
        enabled = True,
        mgmt_only = True
)

interface.full_clean()
interface.save()

ip = IPAddress(
    address = data['ipaddress'],
    status = IPAddressStatusChoices.STATUS_ACTIVE,
    assigned_object = interface
    
)
ip.full_clean()
ip.save()

setattr(device,"primary_ip4", ip)

device.save()
     
self.log_success(f"Created new Device {device}")

Expected Behavior

Make Topic Console Ports, Power Ports visible in Device View

Observed Behavior

These Objects were generated, but arent visible...

device_view
device_changelog

Originally created by @heidl89 on GitHub (Oct 25, 2024). ### Deployment Type Self-hosted ### Triage priority I'm a NetBox Labs customer ### NetBox Version v4.1.4 ### Python Version 3.12 ### Steps to Reproduce 1. Create a custom script "new device" 2. Add some data to "Device" Object 3. device.save() 4. add interface, assign ip to interface 5. settattr -> primary ip 6. device.save() Within the second save, modules (power outlets, console ports) were not added in the gui. The Change Log of the device says the modules are generated.... Important: If i skip the second device.save() the modules were created... But the ip assignment (settattr) is not added... My code: def run (self, data, commit): if not data['gps_lat']: data['gps_lat'] = 0 if not data['gps_long']: data['gps_long'] = 0 device = Device( name = data['device_name'], device_type = data['device_type'], role = data['device_role'], status = data['status'], latitude = data['gps_lat'], longitude = data['gps_long'], site_id = data['site'].id ) if data['location']: device.location = data['location'] device.full_clean() device.save() interface = Interface( device = device, name = "vmgmt0", type = InterfaceTypeChoices.TYPE_VIRTUAL, enabled = True, mgmt_only = True ) interface.full_clean() interface.save() ip = IPAddress( address = data['ipaddress'], status = IPAddressStatusChoices.STATUS_ACTIVE, assigned_object = interface ) ip.full_clean() ip.save() setattr(device,"primary_ip4", ip) device.save() self.log_success(f"Created new Device {device}") ### Expected Behavior Make Topic Console Ports, Power Ports visible in Device View ### Observed Behavior These Objects were generated, but arent visible... ![device_view](https://github.com/user-attachments/assets/97ae0c53-66f6-48e8-b9cc-75995386f29a) ![device_changelog](https://github.com/user-attachments/assets/a52354cf-7831-4806-9445-f52d8812d93a)
adam added the netbox label 2025-12-29 21:31:06 +01:00
adam closed this issue 2025-12-29 21:31:06 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10410