|
170 | 170 | import com.cloud.user.User; |
171 | 171 | import com.cloud.user.dao.AccountDao; |
172 | 172 | import com.cloud.utils.Pair; |
| 173 | +import com.cloud.utils.UuidUtils; |
173 | 174 | import com.cloud.utils.component.AdapterBase; |
174 | 175 | import com.cloud.utils.component.ManagerBase; |
175 | 176 | import com.cloud.utils.concurrency.NamedThreadFactory; |
@@ -1922,43 +1923,45 @@ public Network createGuestNetwork(long networkOfferingId, final String name, fin |
1922 | 1923 | throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone " |
1923 | 1924 | + zone.getName()); |
1924 | 1925 | } |
1925 | | - String uri = (BroadcastDomainType.fromString(vlanId) != null ? BroadcastDomainType.fromString(vlanId).toString() : null); |
1926 | | - // For Isolated networks, don't allow to create network with vlan that already exists in the zone |
1927 | | - if (ntwkOff.getGuestType() == GuestType.Isolated) { |
1928 | | - if (uri != null && _networksDao.countByZoneAndUri(zoneId, uri) > 0) { |
1929 | | - throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId); |
1930 | | - } else { |
1931 | | - List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString()); |
1932 | | - //for the network that is created as part of private gateway, |
1933 | | - //the vnet is not coming from the data center vnet table, so the list can be empty |
1934 | | - if (!dcVnets.isEmpty()) { |
1935 | | - DataCenterVnetVO dcVnet = dcVnets.get(0); |
1936 | | - // Fail network creation if specified vlan is dedicated to a different account |
1937 | | - if (dcVnet.getAccountGuestVlanMapId() != null) { |
1938 | | - Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId(); |
1939 | | - AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId); |
1940 | | - if (map.getAccountId() != owner.getAccountId()) { |
1941 | | - throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account"); |
1942 | | - } |
1943 | | - // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool |
1944 | | - } else { |
1945 | | - List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId()); |
1946 | | - if (maps != null && !maps.isEmpty()) { |
1947 | | - int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId()); |
1948 | | - int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId()); |
1949 | | - if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) { |
1950 | | - throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner " |
1951 | | - + owner.getAccountName()); |
| 1926 | + if (! UuidUtils.validateUUID(vlanId)){ |
| 1927 | + String uri = BroadcastDomainType.fromString(vlanId).toString(); |
| 1928 | + // For Isolated networks, don't allow to create network with vlan that already exists in the zone |
| 1929 | + if (ntwkOff.getGuestType() == GuestType.Isolated) { |
| 1930 | + if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) { |
| 1931 | + throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId); |
| 1932 | + } else { |
| 1933 | + List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString()); |
| 1934 | + //for the network that is created as part of private gateway, |
| 1935 | + //the vnet is not coming from the data center vnet table, so the list can be empty |
| 1936 | + if (!dcVnets.isEmpty()) { |
| 1937 | + DataCenterVnetVO dcVnet = dcVnets.get(0); |
| 1938 | + // Fail network creation if specified vlan is dedicated to a different account |
| 1939 | + if (dcVnet.getAccountGuestVlanMapId() != null) { |
| 1940 | + Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId(); |
| 1941 | + AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId); |
| 1942 | + if (map.getAccountId() != owner.getAccountId()) { |
| 1943 | + throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account"); |
| 1944 | + } |
| 1945 | + // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool |
| 1946 | + } else { |
| 1947 | + List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId()); |
| 1948 | + if (maps != null && !maps.isEmpty()) { |
| 1949 | + int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId()); |
| 1950 | + int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId()); |
| 1951 | + if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) { |
| 1952 | + throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner " |
| 1953 | + + owner.getAccountName()); |
| 1954 | + } |
1952 | 1955 | } |
1953 | 1956 | } |
1954 | 1957 | } |
1955 | 1958 | } |
1956 | | - } |
1957 | | - } else { |
1958 | | - // don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or |
1959 | | - // shared network with same Vlan ID in the zone |
1960 | | - if (uri != null && (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 || _networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Shared) > 0)) { |
1961 | | - throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId); |
| 1959 | + } else { |
| 1960 | + // don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or |
| 1961 | + // shared network with same Vlan ID in the zone |
| 1962 | + if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 ) { |
| 1963 | + throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId); |
| 1964 | + } |
1962 | 1965 | } |
1963 | 1966 | } |
1964 | 1967 |
|
@@ -2049,9 +2052,15 @@ public Network doInTransaction(TransactionStatus status) { |
2049 | 2052 |
|
2050 | 2053 | if (vlanIdFinal != null) { |
2051 | 2054 | if (isolatedPvlan == null) { |
2052 | | - URI uri = BroadcastDomainType.fromString(vlanIdFinal); |
| 2055 | + URI uri = null; |
| 2056 | + if (UuidUtils.validateUUID(vlanIdFinal)){ |
| 2057 | + //Logical router's UUID provided as VLAN_ID |
| 2058 | + userNetwork.setVlanIdAsUUID(vlanIdFinal); //Set transient field |
| 2059 | + } |
| 2060 | + else { |
| 2061 | + uri = BroadcastDomainType.fromString(vlanIdFinal); |
| 2062 | + } |
2053 | 2063 | userNetwork.setBroadcastUri(uri); |
2054 | | - userNetwork.setVlanIdAsUUID((uri == null) ? vlanIdFinal : null); //Set transient field |
2055 | 2064 | if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) { |
2056 | 2065 | userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan); |
2057 | 2066 | } else { |
|
0 commit comments