Skip to content

network: custom DHCP range for isolated networks (API and UI) - #14217

Open
rootnomad wants to merge 4 commits into
apache:mainfrom
rootnomad:feature/isolated-dhcp-range
Open

rootnomad wants to merge 4 commits into
apache:mainfrom
rootnomad:feature/isolated-dhcp-range

Conversation

@rootnomad

Copy link
Copy Markdown
Contributor

Description

An isolated guest network allocates guest IPs from the whole CIDR, so there is no way
to reserve part of the address space or keep the DHCP pool to a sub-range. createNetwork
already takes startip/endip, but NetworkServiceImpl only uses them for shared
networks.

This stores the start and end IP on an isolated network as a DHCP range, in two new
networks columns dhcp_start_ip/dhcp_end_ip, validated to be within the network CIDR,
in order, and not to include the gateway. NetworkModelImpl.getAvailableIps then restricts
the guest IP pool to that range when it is set; without one the whole CIDR is used, so
existing networks are unaffected.

The dnsmasq config on the VR is unchanged: for an isolated network it serves the host entry
CloudStack writes for the IP it allocated, so constraining the allocation is enough and no
system VM template change is needed. The range is returned by listNetworks as startip
and endip.

Creating an isolated network with a range needs gateway and netmask passed too
(already enforced by createNetwork), so the CIDR is deterministic. The create form shows
the start and end IP fields once a gateway is entered, and the network details tab shows the
range on an existing network, so the whole flow is usable from the UI.

Fixes: #12661

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Screenshots (if appropriate):
dhcp-create-form
dhcp-vms-in-network

Isolated network detail showing the DHCP range, and the deployed VMs leased inside it.

How Has This Been Tested?

Unit tests in server, 101 green. NetworkModelImplTest adds two for getAvailableIps:
the pool is restricted to the range when set, and is the whole CIDR (minus the gateway)
when it is not. NetworkServiceImplTest adds five for the validation: a valid range is
stored, the end defaults to the start, and a range outside the CIDR, a start greater than
the end, or a range that includes the gateway are each rejected. DatabaseUpgradeCheckerTest
is green with the schema change. The two changed UI files pass eslint clean.

Manually on a KVM advanced zone. Created an isolated network with gateway 10.99.99.1,
netmask /24 and a DHCP range 10.99.99.10-10.99.99.20, confirmed listNetworks returned
that range, then deployed three VMs on it. All three leased inside the range
(10.99.99.14, .15, .19), where without the change they would draw from the whole /24.

How did you try to break this feature and the system with this change?

  • Range outside the CIDR, reversed range, and a range covering the gateway are all rejected
    at create time.
  • A network created without a range still allocates from the whole CIDR, so existing
    networks and shared networks are unchanged.
  • Deployed several VMs against an 11-address range and confirmed each landed inside it.

@rootnomad rootnomad changed the title network: custom DHCP range for isolated networks (API and UI) network: custom DHCP range for isolated networks (API and UI) Sep 21, 2026
@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.50000% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.81%. Comparing base (2737087) to head (dfdc7f5).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...ain/java/com/cloud/network/NetworkServiceImpl.java 50.00% 9 Missing and 6 partials ⚠️
...rc/main/java/com/cloud/network/NetworkProfile.java 14.28% 12 Missing ⚠️
...pache/cloudstack/api/response/NetworkResponse.java 0.00% 6 Missing ⚠️
...src/main/java/com/cloud/api/ApiResponseHelper.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##               main   #14217     +/-   ##
===========================================
  Coverage     20.80%   20.81%             
- Complexity    20919    20933     +14     
===========================================
  Files          6053     6053             
  Lines        548451   548507     +56     
  Branches      78719    73289   -5430     
===========================================
+ Hits         114128   114166     +38     
- Misses       420958   420966      +8     
- Partials      13365    13375     +10     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.25% <37.50%> (+<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.

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@rootnomad
rootnomad force-pushed the feature/isolated-dhcp-range branch from 6ba5120 to 590e476 Compare October 8, 2026 18:25
@Damans227

Copy link
Copy Markdown
Collaborator

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@Damans227 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19501

@Damans227 Damans227 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks @rootnomad, tested both fixes on a kvm lab and they work. LGTM

@Damans227

Copy link
Copy Markdown
Collaborator

tested the two fixes from 1bade4b on a kvm lab. a bad range is refused and no network is left behind. shrinking with guestvmcidr is refused when the range wont fit, and works when it does.

Complete async job-42, jobStatus: FAILED, resultCode: 431 ... "The network has a custom DHCP range 10.2.2.100-10.2.2.110 that falls outside the requested Guest VM CIDR 10.2.2.0/26.

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

@nvazquez nvazquez added this to the 24.0 milestone Oct 29, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@DaanHoogland DaanHoogland 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.

just style remarks, clgtm

Comment on lines +464 to +465
// For an isolated guest network, an optional custom DHCP range within the CIDR that guest IPs
// are allocated from; null means the whole CIDR is used, which is the default.

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.

Suggested change
// For an isolated guest network, an optional custom DHCP range within the CIDR that guest IPs
// are allocated from; null means the whole CIDR is used, which is the default.
/**
* For an isolated guest network, an optional custom DHCP range within the CIDR that guest IPs
* are allocated from; null means the whole CIDR is used, which is the default.
*/

Comment on lines +2685 to +2692
// For an isolated network a start/end IP defines a custom DHCP range within the CIDR that guest IPs are
// allocated from; without it the whole CIDR is used, which is the default. Validate it up front so a bad
// range is rejected before the network is persisted, rather than throwing after commit and leaving an
// orphaned network.
boolean hasIsolatedDhcpRange = ntwkOff.getGuestType() == GuestType.Isolated && StringUtils.isNotBlank(startIP);
if (hasIsolatedDhcpRange) {
validateIsolatedNetworkDhcpRange(startIP, endIP, cidr, gateway);
}

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.

can you extract this as a method with javadoc?

Comment on lines +4313 to +4322
// A custom DHCP range must stay within the reserved Guest VM CIDR; reject a reservation that would
// leave the stored range partly or wholly outside it, otherwise guest IP allocation could be starved.
if (StringUtils.isNoneBlank(network.getDhcpStartIp(), network.getDhcpEndIp())) {
long dhcpStart = NetUtils.ip2Long(network.getDhcpStartIp());
long dhcpEnd = NetUtils.ip2Long(network.getDhcpEndIp());
if (dhcpStart < startIp || dhcpEnd > endIp) {
throw new InvalidParameterValueException(String.format("The network has a custom DHCP range %s-%s that falls outside the requested Guest VM CIDR %s. Remove or adjust the DHCP range before applying the reservation.",
network.getDhcpStartIp(), network.getDhcpEndIp(), guestVmCidr));
}
}

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.

can you extract this as a method?

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Ramgopal Nagaboina and others added 3 commits November 20, 2026 18:23
An isolated guest network allocates guest IPs from the whole CIDR, so there is no
way to reserve part of the address space or restrict the DHCP pool. createNetwork
already takes startip and endip, but they were only used for shared networks.

This stores the start and end IP on an isolated network as a DHCP range, in two new
networks columns dhcp_start_ip and dhcp_end_ip, validated to be within the network
CIDR, in order, and not to include the gateway. NetworkModelImpl.getAvailableIps
then restricts the guest IP pool to that range when it is set. The dnsmasq config on
the VR is unchanged, since it serves the host entry CloudStack writes for the IP it
allocated, so no system VM template change is needed. Without a range the whole CIDR
is used, so existing networks are unaffected. The range is returned by listNetworks.
Show the start/end IP fields on the isolated network create form once a
gateway is set, and surface the range on the network details tab so an
operator can see and set the guest IP allocation window without the API.
… it on reservation

Validate a custom isolated-network DHCP range before committing the network, so a
range outside the CIDR (or reversed, or over the gateway) is rejected up front
instead of throwing after the network is saved and leaving an orphaned network.
The checks move into validateIsolatedNetworkDhcpRange, reused by
storeIsolatedNetworkDhcpRange.

Also reject an IP reservation (guestvmcidr) that would leave the stored DHCP range
outside the reserved Guest VM CIDR, which would otherwise starve guest IP
allocation.
@RosiKyu

RosiKyu commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@RosiKyu a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20131

@RosiKyu

RosiKyu commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@RosiKyu a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@weizhouapache

Copy link
Copy Markdown
Member

can we simply honor the start_ip and end_ip, instead of introducing new columns ?

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17614)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 68547 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14217-t17614-kvm-ol8.zip
Smoke tests completed. 153 look OK, 5 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_isolated_network_custom_dhcp_range Error 68.91 test_isolated_network_dhcp_range.py
test_01_sys_vm_start Failure 181.04 test_secondary_storage.py
test_11_destroy_ssvm Failure 923.09 test_ssvm.py
test_1_userdata_on_ssvm Failure 921.41 test_systemvm_userdata.py
test_01_vpc_site2site_vpn_multiple_options Failure 503.91 test_vpc_vpn.py

@RosiKyu

RosiKyu commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@rootnomad the smoke run on the current commit has 5 errors, and one of them is the new test from this PR: test_isolated_network_custom_dhcp_range (Error, test_isolated_network_dhcp_range.py). Could you please check it in the Marvin logs linked in the result above?

Could you please also answer @weizhouapache's question above (using the existing start_ip and end_ip instead of the new columns), and look at the 3 open review threads from @DaanHoogland?

I will run the lab test once the design question is settled and the new test passes. Thank you!

Addresses the review request not to introduce new columns. The optional custom
DHCP range for an isolated network is now stored as network details (dhcpStartIp,
dhcpEndIp) instead of dedicated dhcp_start_ip and dhcp_end_ip columns on the
networks table, and read back from the details during guest IP allocation, on the
Guest VM CIDR reservation check and when building the network response. The
reservation-within-CIDR check is extracted into its own method.
@rootnomad

Copy link
Copy Markdown
Contributor Author

@weizhouapache good point. Reworked in 8f911ef to drop the new columns: the custom DHCP range is now stored as network details (dhcpStartIp, dhcpEndIp) instead of the dhcp_start_ip and dhcp_end_ip columns, and read back from the details during guest IP allocation, on the Guest VM CIDR reservation check and in the network response. I kept it off the vlan IP range table on purpose, since a SourceNat isolated network creates no vlan range (it allocates guest IPs straight from the CIDR), so network details is the minimal fit without changing how isolated networks allocate.

@RosiKyu the design is settled above. The new smoke test failure was a cleanup ordering bug in the test, not the feature: the asserts passed (the VM got an IP inside the custom range), it only failed in tearDown because the network was deleted before the VM. Fixed by deleting the VM first.

@DaanHoogland the reservation-within-CIDR check is now extracted into its own method with javadoc. The getDhcpStartIp accessor was removed in favour of the detail keys, so that earlier javadoc suggestion no longer applies.

Ready for the lab re-run.

This branch has not been deployed

No deployments
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.

Allow Custom DHCP Range for Isolated Guest Networks

7 participants