andrijapanicsb commented on a change in pull request #3732: [Vmware] Enable 
PVLAN support on L2 networks
URL: https://github.com/apache/cloudstack/pull/3732#discussion_r360809379
 
 

 ##########
 File path: server/src/main/java/com/cloud/network/NetworkServiceImpl.java
 ##########
 @@ -1348,11 +1363,63 @@ public Network createGuestNetwork(CreateNetworkCmd 
cmd) throws InsufficientCapac
         return network;
     }
 
+    /**
+     * Retrieve information (if set) for private VLAN when creating the network
+     */
+    protected Pair<String, PVlanType> getPrivateVlanPair(String pvlanId, 
String pvlanTypeStr, String vlanId) {
+        String secondaryVlanId = pvlanId;
+        PVlanType type = null;
+
+        if (isNotBlank(secondaryVlanId) && (secondaryVlanId.startsWith("i") || 
secondaryVlanId.startsWith("c") || secondaryVlanId.startsWith("p"))) {
+            String[] parts = secondaryVlanId.split("-");
+            if (parts.length < 2) {
+                throw new CloudRuntimeException("Could not properly parse the 
secondary VLAN ID to format TYPE-SVLANID: " + secondaryVlanId);
+            }
+            secondaryVlanId = parts[1];
+            type = PVlanType.fromValue(parts[0]);
+        }
+
+        if (isNotBlank(pvlanTypeStr)) {
+            PVlanType providedType = PVlanType.fromValue(pvlanTypeStr);
+            if (type != null && type != providedType) {
+                throw new CloudRuntimeException("The type set in the secondary 
VLAN ID: " + secondaryVlanId + " does not match the provided Private VLAN type: 
" + providedType);
+            }
+            type = providedType;
+        }
+
+        if (isBlank(secondaryVlanId) && type != null && type == 
PVlanType.Promiscuous) {
+            secondaryVlanId = vlanId;
+        }
+
+        if (isNotBlank(secondaryVlanId)) {
+            try {
+                Integer.parseInt(secondaryVlanId);
+            } catch (NumberFormatException e) {
+                throw new CloudRuntimeException("The secondary VLAN ID: " + 
secondaryVlanId + " is not in numeric format", e);
+            }
+        }
+
+        return new Pair<>(secondaryVlanId, type);
+    }
+
+    /**
+     * Basic checks for setting up private VLANs, considering the VLAN ID, 
secondary VLAN ID and private VLAN type
+     */
+    protected void performBasicPrivateVlanChecks(String vlanId, String 
secondaryVlanId, PVlanType privateVlanType) {
+        if (isNotBlank(vlanId) && isBlank(secondaryVlanId) && privateVlanType 
!= null && privateVlanType != PVlanType.Promiscuous) {
+            throw new InvalidParameterValueException("Private VLAN ID has not 
been set, therefore Promiscuous type is expected");
+        } else if (isNotBlank(vlanId) && isNotBlank(secondaryVlanId) && 
!vlanId.equalsIgnoreCase(secondaryVlanId) && privateVlanType == 
PVlanType.Promiscuous) {
+            throw new InvalidParameterValueException("Private VLAN type is set 
to Promiscouos, but VLAN ID and Secondary VLAN ID differ");
 
 Review comment:
   this one not fixed @nvazquez (I'm already running tests, but it's safe to 
replace that after now I guess)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to