Skip to content

Commit b9928d4

Browse files
committed
CLOUDSTACK-9074: More fixes
1 parent 582ca98 commit b9928d4

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

api/src/com/cloud/network/Networks.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.net.URI;
2020
import java.net.URISyntaxException;
2121

22-
import com.cloud.utils.UuidUtils;
2322
import com.cloud.utils.exception.CloudRuntimeException;
2423

2524
/**
@@ -252,10 +251,6 @@ public static URI fromString(String candidate) {
252251
if (com.cloud.dc.Vlan.UNTAGGED.equalsIgnoreCase(candidate)) {
253252
return Native.toUri(candidate);
254253
}
255-
if (UuidUtils.validateUUID(candidate)){
256-
//Supporting lswitch uuid as vlan id: set broadcast_uri = null and add row on nicira_nvp_router_map with logicalrouter_uuid = candidate
257-
return null;
258-
}
259254
try {
260255
URI uri = new URI(candidate);
261256
BroadcastDomainType tiep = getSchemeValue(uri);

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
import com.cloud.user.User;
171171
import com.cloud.user.dao.AccountDao;
172172
import com.cloud.utils.Pair;
173+
import com.cloud.utils.UuidUtils;
173174
import com.cloud.utils.component.AdapterBase;
174175
import com.cloud.utils.component.ManagerBase;
175176
import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -1922,43 +1923,45 @@ public Network createGuestNetwork(long networkOfferingId, final String name, fin
19221923
throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone "
19231924
+ zone.getName());
19241925
}
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+
}
19521955
}
19531956
}
19541957
}
19551958
}
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+
}
19621965
}
19631966
}
19641967

@@ -2049,9 +2052,15 @@ public Network doInTransaction(TransactionStatus status) {
20492052

20502053
if (vlanIdFinal != null) {
20512054
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+
}
20532063
userNetwork.setBroadcastUri(uri);
2054-
userNetwork.setVlanIdAsUUID((uri == null) ? vlanIdFinal : null); //Set transient field
20552064
if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
20562065
userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
20572066
} else {

0 commit comments

Comments
 (0)