bernardodemarco commented on code in PR #10168:
URL: https://github.com/apache/cloudstack/pull/10168#discussion_r1929017999


##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -1634,6 +1634,18 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) 
throws InsufficientCapac
             throwInvalidIdException("Network offering with specified id 
doesn't support adding multiple ip ranges", ntwkOff.getUuid(), 
NETWORK_OFFERING_ID);
         }
 
+        if (GuestType.Shared == ntwkOff.getGuestType()) {
+            if (!ntwkOff.isSpecifyIpRanges()) {
+                throw new CloudRuntimeException("Specify IP Ranged should be 
true for Shared Networks");
+            }
+            if (ipv4 && Objects.isNull(startIP)) {

Review Comment:
   @Pearl1594, I'm trying to reproduce some test cases in which `endip` is not 
specified:
   
   
![image](https://github.com/user-attachments/assets/2744b6e7-1978-41cd-b1ff-68a7f52eca85)
   
   VM deploy is always failing. By analyzing the logs, first the management 
server allocates a NIC for the VM:
   
   ```bash
   2025-01-24 16:56:04,303 DEBUG [c.c.v.VirtualMachineManagerImpl] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) Allocating nics 
for VM instance 
{"id":24,"instanceName":"i-2-24-VM","type":"User","uuid":"41bdd147-7c47-4b27-b3a8-d157041ea2c0"}
   2025-01-24 16:56:04,304 DEBUG [o.a.c.e.o.NetworkOrchestrator] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) Allocating nic 
for vm VM instance 
{"id":24,"instanceName":"i-2-24-VM","type":"User","uuid":"41bdd147-7c47-4b27-b3a8-d157041ea2c0"}
 in network Network {"id": 209, "name": "shared-nw", "uuid": 
"c474ffef-f38e-445b-8e8b-95aa1470ec49", "networkofferingid": 8} with requested 
profile NicProfile 
{"broadcastUri":null,"deviceId":null,"iPv4Address":null,"id":0,"reservationId":null,"vmId":0}
   2025-01-24 16:56:04,307 DEBUG [c.c.n.IpAddressManagerImpl] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) Public IP address 
[Ip[172.16.10.2-1]] is not in quarantine; therefore, it is allowed to be 
allocated.
   2025-01-24 16:56:04,307 DEBUG [c.c.n.IpAddressManagerImpl] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) trying ip address 
172.16.10.2
   2025-01-24 16:56:04,309 DEBUG [c.c.n.IpAddressManagerImpl] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) locked row for ip 
address 172.16.10.2 (id: 68cc5587-996f-438a-8328-5cc9c9e05fcf)
   2025-01-24 16:56:04,309 INFO  [c.c.n.IpAddressManagerImpl] 
(qtp1690859824-20:ctx-c8dcbbaf ctx-a83bcdfb) (logid:ae7eab07) successfully 
allocated ip address 172.16.10.2
   2025-0
   ``` 
   
   In this test, the IP 172.16.10.2 has been allocated to the VM. Later, the 
deploy flow tries to allocate a NIC for the VR. However, it is not able to 
acquire an IP and the deploy fails:
   
   ```bash
   2025-01-24 16:56:05,835 DEBUG [c.c.n.r.NetworkHelperImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) First ipv4 172.16.10.2 in network id=209 is already allocated, 
can't use it for domain router; will get random ip address from the range
   2025-01-24 16:56:05,835 DEBUG [c.c.n.r.NetworkHelperImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Adding nic for Virtual Router in Control network 
   2025-01-24 16:56:05,837 DEBUG [o.a.c.e.o.NetworkOrchestrator] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Found existing network configuration for offering [Network 
Offering [3-Control-System-Control-Network]: Network {"id": 202, "name": 
"null", "uuid": "b825efb5-ff0d-47e7-b872-3fcff1e48de9", "networkofferingid": 3}
   2025-01-24 16:56:05,837 DEBUG [o.a.c.e.o.NetworkOrchestrator] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Releasing lock for Account 
[{"accountName":"system","id":1,"uuid":"20384e8f-4b71-11ef-87b4-cec422422af1"}]
   2025-01-24 16:56:05,839 INFO  [c.c.v.VirtualMachineManagerImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) allocating virtual machine from 
template:8b5adbc2-e515-43ab-9db0-2a57945ddc44 with hostname:r-25-VM and 2 
networks
   2025-01-24 16:56:05,840 DEBUG [c.c.v.VirtualMachineManagerImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Allocating entries for VM: VM instance 
{"id":25,"instanceName":"r-25-VM","type":"DomainRouter","uuid":"3cf270f8-9415-460e-85d8-dfafe0a4191c"}
   2025-01-24 16:56:05,842 DEBUG [c.c.v.VirtualMachineManagerImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Allocating nics for VM instance 
{"id":25,"instanceName":"r-25-VM","type":"DomainRouter","uuid":"3cf270f8-9415-460e-85d8-dfafe0a4191c"}
   2025-01-24 16:56:05,842 DEBUG [o.a.c.e.o.NetworkOrchestrator] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Allocating nic for vm VM instance 
{"id":25,"instanceName":"r-25-VM","type":"DomainRouter","uuid":"3cf270f8-9415-460e-85d8-dfafe0a4191c"}
 in network Network {"id": 209, "name": "shared-nw", "uuid": 
"c474ffef-f38e-445b-8e8b-95aa1470ec49", "networkofferingid": 8} with requested 
profile NicProfile 
{"broadcastUri":null,"deviceId":null,"iPv4Address":null,"id":0,"reservationId":null,"vmId":0}
   2025-01-24 16:56:05,844 WARN  [c.c.n.IpAddressManagerImpl] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Unable to get ip address in  zone id=1, network id=209
   2025-01-24 16:56:05,845 DEBUG [c.c.u.d.T.Transaction] 
(Work-Job-Executor-32:ctx-a6146aba job-148/job-149 ctx-7eb36780) 
(logid:c96fd0f5) Rolling back the transaction: Time = 2 Name =  
Work-Job-Executor-32; called by 
-TransactionLegacy.rollback:890-TransactionLegacy.removeUpTo:833-TransactionLegacy.close:657-Transaction.execute:38-IpAddressManagerImpl.allocateDirectIp:2268-DirectNetworkGuru$1.doInTransactionWithoutResult:324-TransactionCallbackWithExceptionNoReturn.doInTransaction:25-TransactionCallbackWithExceptionNoReturn.doInTransaction:21-Transaction.execute:40-DirectNetworkGuru.allocateDirectIp:317-DirectNetworkGuru.allocate:290-NetworkOrchestrator.checkForRaceAndAllocateNic:1049
   ``` 
   
   Although the first log of the above code block states that `can't use it for 
domain router; will get random ip address from the range`, that did not happen 
in my tests. Therefore, I believe that it would be interesting to check if the 
`endip` is specified as well.



-- 
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