Skip to content

feat: persist and expose effective network rate for NIC and Guest Network - #14055

Closed
sudo87 wants to merge 2 commits into
apache:mainfrom
sudo87:networkThrottling
Closed

sudo87 wants to merge 2 commits into
apache:mainfrom
sudo87:networkThrottling

Conversation

@sudo87

@sudo87 sudo87 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Persists the effective network rate (bandwidth throttling) for both NICs and Guest Networks in their respective detail tables, and exposes the values through the API and UI.

What changed

Persistence — NIC (nic_details)

  • On VM deploy: allocateNetworksForVm() calls refreshNicNetworkRates() after NICs are created in the DB
  • On NIC hot-plug: addNicToVm() persists the rate immediately after allocation
  • On VM start (StartVMCmd): refreshNicNetworkRates() refreshes all NIC rates so stale values are corrected when the network offering changes between stop/start cycles
  • On NIC/VM removal: NetworkOrchestrator.removeNic() and removeNics() clean up nic_details co-located with the _nicDao.remove() call, respecting the preserveNics guard

Persistence — Guest Network (network_details)

  • On network create: NetworkOrchestrator.setupNetwork() calls saveNetworkRateInDetails() after the network record is committed
  • On network offering update: NetworkServiceImpl.updateGuestNetwork() upserts the rate inside the offering-change transaction

API

  • NicResponse: new networkrate field (since = "4.24.0") populated from nic_details
  • NetworkResponse: new networkrate field (since = "4.21.0") populated from network_details
  • ApiResponseHelper: reads rate detail for both NIC and Network responses

UI

  • Guest Network detail page: networkrate added to the fields array in network.js
  • VM NIC expanded row (NicsTable.vue): networkrate shown under the Admin/DomainAdmin guard alongside broadcasturi and isolationuri

Design notes

  • Rate is stored as a string: a positive integer (Mb/s) or "unlimited" when the offering has no limit
  • NicVO and NetworkVO use soft-delete (removed = NOW()), so ON DELETE CASCADE on the FK never fires — cleanup is explicit
  • refreshNicNetworkRates() uses NetworkModelImpl.getNetworkRate() which resolves the current offering dynamically, matching what the hypervisor enforces when rebuilding domain XML

Test plan

  • Deploy a VM on a network with throttling configured — verify nic_details has the rate
  • Hot-plug a NIC — verify nic_details entry created
  • Update the network offering on an existing network, stop/start the VM — verify nic_details reflects the new rate
  • Destroy a VM — verify nic_details rows are removed
  • listNics response includes networkrate
  • listNetworks response includes networkrate
  • Guest Network detail page shows Network Rate field
  • VM details NIC expanded row shows Network Rate (Admin/DomainAdmin only)

sudo87 added 2 commits June 3, 2026 22:53
# Conflicts:
#	server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
#	ui/src/config/section/network.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It touches VM lifecycle/network persistence plus API/UI surfaces, and the impact on runtime behavior and query/load characteristics needs careful human validation and end-to-end testing.

Pull request overview

Persists the effective network rate (bandwidth throttling) for NICs and Guest Networks into their respective *_details tables, and exposes these values via CloudStack API responses and UI detail views.

Changes:

  • Persist NIC network rate into nic_details on NIC hot-plug and refresh persisted values on VM start.
  • Persist Guest Network network rate into network_details on network creation and on guest network offering updates.
  • Expose networkrate through API (NicResponse, NetworkResponse) and display it in the UI (Guest Network details + VM NIC expanded row; plus Service Offering columns/details).
File summaries
File Description
ui/src/views/network/NicsTable.vue Displays NIC networkrate in the expanded NIC details (Admin/DomainAdmin only).
ui/src/config/section/offering.js Adds networkrate to compute service offering list columns and details fields.
ui/src/config/section/network.js Adds networkrate to Guest Network detail fields.
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Persists NIC effective rate on hot-plug and refreshes NIC rates on VM start.
server/src/main/java/com/cloud/network/NetworkServiceImpl.java Upserts Guest Network rate into network_details when updating the guest network offering.
server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java Populates per-NIC networkrate in VM responses from nic_details.
server/src/main/java/com/cloud/api/ApiResponseHelper.java Populates networkrate for Network and NIC responses from *_details.
server/src/main/java/com/cloud/api/ApiDBUtils.java Adds DAO wiring + helper to fetch NIC details by key.
api/src/main/java/org/apache/cloudstack/api/response/NicResponse.java Introduces networkrate field on NIC API response.
api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java Introduces networkrate field on Network API response.
api/src/main/java/org/apache/cloudstack/api/ApiConstants.java Adds UNLIMITED string constant for persisted rate representation.
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java Persists Guest Network rate into network_details during network setup.
Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +451 to +454
NicDetailVO nicNetworkRateDetail = ApiDBUtils.findNicDetailByName(userVm.getNicId(), ApiConstants.NETWORKRATE);
if (nicNetworkRateDetail != null) {
nicResponse.setNetworkRate(nicNetworkRateDetail.getValue());
}
Comment on lines +314 to +316
@SerializedName(ApiConstants.NETWORKRATE)
@Param(description = "Network rate (in Mb/s) configured for the Guest interface of this network", since = "4.24.0")
private String networkRate;
Comment on lines 527 to +529
@Inject
private NicDetailsDao nicDetailsDao;
@Inject
@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.78%. Comparing base (44ab7dd) to head (c8ac2a0).

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 0.00% 14 Missing ⚠️
...pache/cloudstack/api/response/NetworkResponse.java 0.00% 6 Missing ⚠️
...rg/apache/cloudstack/api/response/NicResponse.java 0.00% 6 Missing ⚠️
...tack/engine/orchestration/NetworkOrchestrator.java 0.00% 6 Missing ⚠️
...src/main/java/com/cloud/api/ApiResponseHelper.java 0.00% 6 Missing ⚠️
...ava/com/cloud/api/query/dao/UserVmJoinDaoImpl.java 0.00% 6 Missing ⚠️
server/src/main/java/com/cloud/api/ApiDBUtils.java 0.00% 4 Missing ⚠️
...ain/java/com/cloud/network/NetworkServiceImpl.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #14055   +/-   ##
=========================================
  Coverage     19.77%   19.78%           
- Complexity    19989    19997    +8     
=========================================
  Files          6371     6371           
  Lines        575899   575949   +50     
  Branches      70495    70502    +7     
=========================================
+ Hits         113912   113963   +51     
+ Misses       449563   449560    -3     
- Partials      12424    12426    +2     
Flag Coverage Δ
uitests 3.53% <ø> (ø)
unittests 21.06% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sudo87 sudo87 closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants