|
38 | 38 | import javax.inject.Inject;
|
39 | 39 | import javax.naming.ConfigurationException;
|
40 | 40 |
|
| 41 | +import com.cloud.network.dao.NetworkDetailVO; |
| 42 | +import com.cloud.network.dao.NetworkDetailsDao; |
41 | 43 | import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
| 44 | +import org.apache.cloudstack.api.ApiConstants; |
42 | 45 | import org.apache.cloudstack.context.CallContext;
|
43 | 46 | import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO;
|
44 | 47 | import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao;
|
|
222 | 225 | import com.cloud.vm.dao.VMInstanceDao;
|
223 | 226 | import com.google.common.base.Strings;
|
224 | 227 |
|
| 228 | +import static org.apache.commons.lang.StringUtils.isNotBlank; |
| 229 | + |
225 | 230 | /**
|
226 | 231 | * NetworkManagerImpl implements NetworkManager.
|
227 | 232 | */
|
@@ -251,6 +256,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
|
251 | 256 | @Inject
|
252 | 257 | NetworkDao _networksDao;
|
253 | 258 | @Inject
|
| 259 | + NetworkDetailsDao networkDetailsDao; |
| 260 | + @Inject |
254 | 261 | NicDao _nicDao;
|
255 | 262 | @Inject
|
256 | 263 | RulesManager _rulesMgr;
|
@@ -698,6 +705,11 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
|
698 | 705 | finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()));
|
699 | 706 | networks.add(networkPersisted);
|
700 | 707 |
|
| 708 | + if (network.getPvlanType() != null) { |
| 709 | + NetworkDetailVO detailVO = new NetworkDetailVO(networkPersisted.getId(), ApiConstants.ISOLATED_PVLAN_TYPE, network.getPvlanType().toString(), true); |
| 710 | + networkDetailsDao.persist(detailVO); |
| 711 | + } |
| 712 | + |
701 | 713 | if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions){
|
702 | 714 | final NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
|
703 | 715 | functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO)predefined).getVlanIdAsUUID());
|
@@ -2168,7 +2180,7 @@ public void expungeNics(final VirtualMachineProfile vm) {
|
2168 | 2180 | public Network createGuestNetwork(final long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId,
|
2169 | 2181 | boolean bypassVlanOverlapCheck, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk,
|
2170 | 2182 | final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
|
2171 |
| - final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, String externalId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { |
| 2183 | + final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { |
2172 | 2184 |
|
2173 | 2185 | final NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
|
2174 | 2186 | final DataCenterVO zone = _dcDao.findById(zoneId);
|
@@ -2280,16 +2292,25 @@ public Network createGuestNetwork(final long networkOfferingId, final String nam
|
2280 | 2292 |
|
2281 | 2293 | if (vlanSpecified) {
|
2282 | 2294 | URI uri = BroadcastDomainType.fromString(vlanId);
|
| 2295 | + // Aux: generate secondary URI for secondary VLAN ID (if provided) for performing checks |
| 2296 | + URI secondaryUri = isNotBlank(isolatedPvlan) ? BroadcastDomainType.fromString(isolatedPvlan) : null; |
2283 | 2297 | //don't allow to specify vlan tag used by physical network for dynamic vlan allocation
|
2284 | 2298 | if (!(bypassVlanOverlapCheck && ntwkOff.getGuestType() == GuestType.Shared) && _dcDao.findVnet(zoneId, pNtwk.getId(), BroadcastDomainType.getValue(uri)).size() > 0) {
|
2285 | 2299 | throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone "
|
2286 | 2300 | + zone.getName());
|
2287 | 2301 | }
|
| 2302 | + if (secondaryUri != null && !(bypassVlanOverlapCheck && ntwkOff.getGuestType() == GuestType.Shared) && |
| 2303 | + _dcDao.findVnet(zoneId, pNtwk.getId(), BroadcastDomainType.getValue(secondaryUri)).size() > 0) { |
| 2304 | + throw new InvalidParameterValueException("The VLAN tag " + isolatedPvlan + " is already being used for dynamic vlan allocation for the guest network in zone " |
| 2305 | + + zone.getName()); |
| 2306 | + } |
2288 | 2307 | if (! UuidUtils.validateUUID(vlanId)){
|
2289 | 2308 | // For Isolated and L2 networks, don't allow to create network with vlan that already exists in the zone
|
2290 |
| - if (ntwkOff.getGuestType() == GuestType.Isolated || !hasGuestBypassVlanOverlapCheck(bypassVlanOverlapCheck, ntwkOff)) { |
| 2309 | + if (ntwkOff.getGuestType() == GuestType.Isolated || ntwkOff.getGuestType() == GuestType.L2 || !hasGuestBypassVlanOverlapCheck(bypassVlanOverlapCheck, ntwkOff)) { |
2291 | 2310 | if (_networksDao.listByZoneAndUriAndGuestType(zoneId, uri.toString(), null).size() > 0) {
|
2292 | 2311 | throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists or overlaps with other network vlans in zone " + zoneId);
|
| 2312 | + } else if (secondaryUri != null && _networksDao.listByZoneAndUriAndGuestType(zoneId, secondaryUri.toString(), null).size() > 0) { |
| 2313 | + throw new InvalidParameterValueException("Network with vlan " + isolatedPvlan + " already exists or overlaps with other network vlans in zone " + zoneId); |
2293 | 2314 | } else {
|
2294 | 2315 | final List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, BroadcastDomainType.getValue(uri));
|
2295 | 2316 | //for the network that is created as part of private gateway,
|
@@ -2436,8 +2457,15 @@ public Network doInTransaction(final TransactionStatus status) {
|
2436 | 2457 | if (vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
|
2437 | 2458 | throw new InvalidParameterValueException("Cannot support pvlan with untagged primary vlan!");
|
2438 | 2459 | }
|
2439 |
| - userNetwork.setBroadcastUri(NetUtils.generateUriForPvlan(vlanIdFinal, isolatedPvlan)); |
| 2460 | + URI uri = NetUtils.generateUriForPvlan(vlanIdFinal, isolatedPvlan); |
| 2461 | + if (_networksDao.listByPhysicalNetworkPvlan(physicalNetworkId, uri.toString(), isolatedPvlanType).size() > 0) { |
| 2462 | + throw new InvalidParameterValueException("Network with primary vlan " + vlanIdFinal + |
| 2463 | + " and secondary vlan " + isolatedPvlan + " type " + isolatedPvlanType + |
| 2464 | + " already exists or overlaps with other network pvlans in zone " + zoneId); |
| 2465 | + } |
| 2466 | + userNetwork.setBroadcastUri(uri); |
2440 | 2467 | userNetwork.setBroadcastDomainType(BroadcastDomainType.Pvlan);
|
| 2468 | + userNetwork.setPvlanType(isolatedPvlanType); |
2441 | 2469 | }
|
2442 | 2470 | }
|
2443 | 2471 |
|
|
0 commit comments