Power utilization not going fully downstream #7925

Closed
opened 2025-12-29 20:30:02 +01:00 by adam · 3 comments
Owner

Originally created by @dutchman80 on GitHub (Apr 19, 2023).

NetBox version

v3.4.8

Python version

3.9

Steps to Reproduce

Create Power Feed "powerfeed"
Create Device "pdu1" with one Power Port and one Power Outlet
Create Device "pdu2" with one Power Port and one Power Outlet
Create Device "device" with one Power Port and set Allocated Draw to 3000VA

Connect Power Ports to Power Outlets in this order: powerfeed -> pdu1 -> pdu2 -> device

Expected Behavior

powerfeed, pdu1, and pdu2 should all be registering device's power utilization of 3000VA

Observed Behavior

Only pdu2 registers the load of device

Originally created by @dutchman80 on GitHub (Apr 19, 2023). ### NetBox version v3.4.8 ### Python version 3.9 ### Steps to Reproduce Create Power Feed "**powerfeed**" Create Device "**pdu1**" with one Power Port and one Power Outlet Create Device "**pdu2**" with one Power Port and one Power Outlet Create Device "**device**" with one Power Port and set Allocated Draw to 3000VA Connect Power Ports to Power Outlets in this order: **powerfeed** -> **pdu1** -> **pdu2** -> **device** ### Expected Behavior **powerfeed**, **pdu1**, and **pdu2** should all be registering **device**'s power utilization of 3000VA ### Observed Behavior Only **pdu2** registers the load of **device**
adam closed this issue 2025-12-29 20:30:02 +01:00
Author
Owner

@dutchman80 commented on GitHub (Apr 19, 2023):

Suggested Fix:

At the bottom of the PowerPort.get_downstream_powerports() method definition in /netbox/dcim/models/device_components.py, replace:

        return PowerPort.objects.filter(q)

with:

        allports = PowerPort.objects.none()
        for powerport in PowerPort.objects.filter(q):
            nextports =  powerport.get_downstream_powerports()
            if not nextports:
                allports |= PowerPort.objects.filter(pk=powerport.pk)
            else:
                allports = allports.union(nextports)

        return allports

This will make the method recursively search out all connected loads

@dutchman80 commented on GitHub (Apr 19, 2023): Suggested Fix: At the bottom of the **PowerPort.get_downstream_powerports()** method definition in _/netbox/dcim/models/device_components.py_, replace: ``` return PowerPort.objects.filter(q) ``` with: ``` allports = PowerPort.objects.none() for powerport in PowerPort.objects.filter(q): nextports = powerport.get_downstream_powerports() if not nextports: allports |= PowerPort.objects.filter(pk=powerport.pk) else: allports = allports.union(nextports) return allports ``` This will make the method recursively search out all connected loads
Author
Owner

@arthanson commented on GitHub (May 2, 2023):

In talking with Jeremy, the issue with the proposed fix, and why this was left out in the original code, is due to performance - going down recursively can get very expensive if many connected devices and long chains of cabling. This probably needs to be re-worked with a stored cached value.

@arthanson commented on GitHub (May 2, 2023): In talking with Jeremy, the issue with the proposed fix, and why this was left out in the original code, is due to performance - going down recursively can get very expensive if many connected devices and long chains of cabling. This probably needs to be re-worked with a stored cached value.
Author
Owner

@jeremystretch commented on GitHub (May 2, 2023):

While I understand the current behavior does not meet your needs, it is functioning as intended. If you'd like to see this functionality improved, I invite you to resubmit this as a feature request citing your use case and a proposed implementation.

@jeremystretch commented on GitHub (May 2, 2023): While I understand the current behavior does not meet your needs, it is functioning as intended. If you'd like to see this functionality improved, I invite you to resubmit this as a feature request citing your use case and a proposed implementation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7925