[PR #4226] [CLOSED] Fixes #3377: Cascade power draw calculation on all downstream power ports #12798

Closed
opened 2025-12-29 22:23:40 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/4226
Author: @hSaria
Created: 2/21/2020
Status: Closed

Base: developHead: 3377-recursive-power


📝 Commits (5)

  • 860c399 Handle divide by zero power stats with very low values
  • 8bcf12d Cache upstream and downstream power ports for each outlet
  • be307b4 Cascade power draw calculation on all downstream power ports
  • 6fa80bd Corrected caching extra (cache the values, not the queryset object)
  • 991c9b8 Privatized the cached fields (to assist with #4227)

📊 Changes

7 files changed (+387 additions, -37 deletions)

View changed files

netbox/dcim/migrations/0099_outlet_related_powerports.py (+76 -0)
📝 netbox/dcim/models/__init__.py (+10 -12)
📝 netbox/dcim/models/device_components.py (+107 -18)
📝 netbox/dcim/signals.py (+13 -1)
📝 netbox/dcim/tests/test_models.py (+170 -0)
📝 netbox/templates/dcim/device.html (+10 -5)
📝 netbox/templates/dcim/powerfeed.html (+1 -1)

📄 Description

Fixes: #3377

During the calculation of power draw, include all downstream power ports (i.e. non-immediate). To maintain efficiency, each power outlet caches the upstream and downstream power ports.

A power topology change will update the cached fields. The trigger for a topology change is the cable being updated/deleted (in dcim.signals).

downstream_powerports flattens what would otherwise be a recursive process during power calculation to a single query.

upstream_powerports is used as part of the power calculation to update the cached fields for any power outlet affected by the topology change.

This PR is a refactor following the extended discussion in #3916, which has more information on this topic.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/4226 **Author:** [@hSaria](https://github.com/hSaria) **Created:** 2/21/2020 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `3377-recursive-power` --- ### 📝 Commits (5) - [`860c399`](https://github.com/netbox-community/netbox/commit/860c39944f992efa7675485bd81bee1953d555ad) Handle divide by zero power stats with very low values - [`8bcf12d`](https://github.com/netbox-community/netbox/commit/8bcf12dbd1ad3d3b2c31e3d55f90299762ed8a02) Cache upstream and downstream power ports for each outlet - [`be307b4`](https://github.com/netbox-community/netbox/commit/be307b4574d8f7157f283f9c204a3bf53a9279db) Cascade power draw calculation on all downstream power ports - [`6fa80bd`](https://github.com/netbox-community/netbox/commit/6fa80bd971690f236b59982bbc089c4285d34af0) Corrected caching extra (cache the values, not the queryset object) - [`991c9b8`](https://github.com/netbox-community/netbox/commit/991c9b8f0aecebe5f06dacc37ee58db70f2096f3) Privatized the cached fields (to assist with #4227) ### 📊 Changes **7 files changed** (+387 additions, -37 deletions) <details> <summary>View changed files</summary> ➕ `netbox/dcim/migrations/0099_outlet_related_powerports.py` (+76 -0) 📝 `netbox/dcim/models/__init__.py` (+10 -12) 📝 `netbox/dcim/models/device_components.py` (+107 -18) 📝 `netbox/dcim/signals.py` (+13 -1) 📝 `netbox/dcim/tests/test_models.py` (+170 -0) 📝 `netbox/templates/dcim/device.html` (+10 -5) 📝 `netbox/templates/dcim/powerfeed.html` (+1 -1) </details> ### 📄 Description ### Fixes: #3377 During the calculation of power draw, include all downstream power ports (i.e. non-immediate). To maintain efficiency, each power outlet caches the upstream and downstream power ports. A power topology change will update the cached fields. The trigger for a topology change is the cable being updated/deleted (in `dcim.signals`). `downstream_powerports` flattens what would otherwise be a recursive process during power calculation to a single query. `upstream_powerports` is used as part of the power calculation to update the cached fields for any power outlet affected by the topology change. > This PR is a refactor following the extended discussion in #3916, which has more information on this topic. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:23:40 +01:00
adam closed this issue 2025-12-29 22:23:40 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12798