weizhouapache commented on a change in pull request #5769:
URL: https://github.com/apache/cloudstack/pull/5769#discussion_r778728310



##########
File path: server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
##########
@@ -1833,8 +1860,63 @@ public PrivateGateway createVpcPrivateGateway(final long 
vpcId, Long physicalNet
             throw ex;
         }
 
+        // Validate vlanId and associatedNetworkId
+        if (broadcastUri == null && associatedNetworkId == null) {
+            throw new InvalidParameterValueException("One of vlanId and 
associatedNetworkId must be specified");
+        }
+        if (broadcastUri != null && associatedNetworkId != null) {
+            throw new InvalidParameterValueException("vlanId and 
associatedNetworkId are mutually exclusive");
+        }
+
+        // Validate network offering
+        NetworkOfferingVO ntwkOff = null;
+        if (networkOfferingIdPassed != null) {
+            ntwkOff = _networkOfferingDao.findById(networkOfferingIdPassed);
+            if (ntwkOff == null) {
+                throw new InvalidParameterValueException("Unable to find 
network offering by id specified");
+            }
+            if (! TrafficType.Guest.equals(ntwkOff.getTrafficType())) {
+                throw new InvalidParameterValueException("The network offering 
cannot be used to create Guest network");
+            }
+            if (! GuestType.Isolated.equals(ntwkOff.getGuestType())) {
+                throw new InvalidParameterValueException("The network offering 
cannot be used to create Isolated network");
+            }
+        } else if (broadcastUri != null) {
+            ntwkOff = 
_networkOfferingDao.findByUniqueName(NetworkOffering.SystemPrivateGatewayNetworkOffering);
+        } else {
+            ntwkOff = 
_networkOfferingDao.findByUniqueName(NetworkOffering.SystemPrivateGatewayNetworkOfferingWithoutVlan);
+        }
+        final Long networkOfferingId = ntwkOff.getId();
+
+        Account caller = CallContext.current().getCallingAccount();
+        if (!_accountMgr.isRootAdmin(caller.getId()) && 
(ntwkOff.isSpecifyVlan() || broadcastUri != null || bypassVlanOverlapCheck)) {
+            throw new InvalidParameterValueException("Only ROOT admin is 
allowed to specify vlanId or bypass vlan overlap check");
+        }
+        if (ntwkOff.isSpecifyVlan() && broadcastUri == null) {
+            throw new InvalidParameterValueException("vlanId must be specified 
for this network offering");
+        }
+        if (! ntwkOff.isSpecifyVlan() && associatedNetworkId == null) {
+            throw new InvalidParameterValueException("associatedNetworkId must 
be specified for this network offering");
+        }
+
+        final Long dcId = vpc.getZoneId();
         PhysicalNetwork physNet = null;
         // Validate physical network
+        if (associatedNetworkId != null) {
+            Network associatedNetwork = _entityMgr.findById(Network.class, 
associatedNetworkId);
+            if (associatedNetwork == null) {
+                throw new InvalidParameterValueException("Unable to find 
network by ID " + associatedNetworkId);
+            }
+            if (physicalNetworkId != null && 
!physicalNetworkId.equals(associatedNetwork.getPhysicalNetworkId())) {
+                throw new InvalidParameterValueException("The network can only 
be created on the same physical network as the associated network");
+            } else if (physicalNetworkId == null) {
+                physicalNetworkId = associatedNetwork.getPhysicalNetworkId();
+            }
+        }
+        if (physicalNetworkId == null) {
+            // Determine the physical network by network offering tags
+            physicalNetworkId = _ntwkSvc.findPhysicalNetworkId(dcId, 
ntwkOff.getTags(), ntwkOff.getTrafficType());
+        }

Review comment:
       will do




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