DaanHoogland commented on code in PR #14217:
URL: https://github.com/apache/cloudstack/pull/14217#discussion_r4564539799


##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -4271,6 +4310,17 @@ public Network updateGuestNetwork(final UpdateNetworkCmd 
cmd) {
                 }
             }
 
+            // 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));
+                }
+            }

Review Comment:
   can you extract this as a method?



##########
api/src/main/java/com/cloud/network/Network.java:
##########
@@ -461,6 +461,16 @@ public void setIp6Address(String ip6Address) {
 
     void setCidr(String cidr);
 
+    // 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.

Review Comment:
   ```suggestion
       /**
        * 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.
        */
   ```



##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -2682,10 +2682,23 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) 
throws InsufficientCapac
             }
         }
 
+        // 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);
+        }

Review Comment:
   can you extract this as a method with javadoc?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to