Skip to content

Commit f157148

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
aclType is Domain for Guest network in Basic zone
1 parent 87f5150 commit f157148

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

‎api/src/com/cloud/api/commands/CreateNetworkCmd.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.apache.log4j.Logger;
2222

23-
import com.cloud.acl.ControlledEntity;
2423
import com.cloud.api.ApiConstants;
2524
import com.cloud.api.BaseCmd;
2625
import com.cloud.api.IdentityMapper;
@@ -92,7 +91,7 @@ public class CreateNetworkCmd extends BaseCmd {
9291
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
9392
private String networkDomain;
9493

95-
@Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values are account and domain. If not specified, defaulted to Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
94+
@Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values are account and domain. If not specified, defaulted to Account in Adavnce zone, and to Domain in Basic zone. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
9695
private String aclType;
9796

9897
@IdentityMapper(entityTableName="physical_network")
@@ -155,7 +154,7 @@ public Long getProjectId() {
155154
}
156155

157156
public String getAclType() {
158-
return aclType == null ? ControlledEntity.ACLType.Account.toString() : aclType;
157+
return aclType;
159158
}
160159

161160
public Long getZoneId() {

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,17 +1734,49 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
17341734
if (networkOffering.getState() != NetworkOffering.State.Enabled) {
17351735
throw new InvalidParameterValueException("Can't use network offering id=" + networkOfferingId + " as its state is not " + NetworkOffering.State.Enabled);
17361736
}
1737+
1738+
//validate physical network and zone
1739+
// Check if physical network exists
1740+
PhysicalNetwork pNtwk = null;
1741+
if (physicalNetworkId != null) {
1742+
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
1743+
if (pNtwk == null) {
1744+
throw new InvalidParameterValueException("Unable to find physical network by id " + physicalNetworkId);
1745+
}
1746+
1747+
//check that the physical network is enabled
1748+
if (pNtwk.getState() != PhysicalNetwork.State.Enabled) {
1749+
throw new InvalidParameterValueException("Physical network id " + physicalNetworkId + " is in incorrect state: " + pNtwk.getState());
1750+
}
1751+
}
1752+
1753+
if (zoneId == null) {
1754+
zoneId = pNtwk.getDataCenterId();
1755+
}
1756+
1757+
DataCenter zone = _dcDao.findById(zoneId);
1758+
1759+
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
1760+
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getId());
1761+
}
17371762

17381763
//Only domain and account ACL types are supported in Acton
17391764
ACLType aclType = null;
17401765
if (aclTypeStr != null) {
17411766
if (aclTypeStr.equalsIgnoreCase(ACLType.Account.toString())) {
1767+
if (zone.getNetworkType() == NetworkType.Basic) {
1768+
throw new InvalidParameterValueException("Only AclType=Domain can be specified for network creation in Basic zone");
1769+
}
17421770
aclType = ACLType.Account;
17431771
} else if (aclTypeStr.equalsIgnoreCase(ACLType.Domain.toString())){
17441772
aclType = ACLType.Domain;
17451773
} else {
17461774
throw new InvalidParameterValueException("Incorrect aclType specified. Check the API documentation for supported types");
17471775
}
1776+
} else if (zone.getNetworkType() == NetworkType.Advanced) {
1777+
aclType = ACLType.Account;
1778+
} else {
1779+
aclType = ACLType.Domain;
17481780
}
17491781

17501782
// Check if the network is domain specific
@@ -1788,26 +1820,6 @@ public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityEx
17881820
endIP = startIP;
17891821
}
17901822

1791-
// Check if physical network exists
1792-
PhysicalNetwork pNtwk = null;
1793-
if (physicalNetworkId != null) {
1794-
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
1795-
if (pNtwk == null) {
1796-
throw new InvalidParameterValueException("Unable to find physical network by id " + physicalNetworkId);
1797-
}
1798-
1799-
//check that the physical network is enabled
1800-
if (pNtwk.getState() != PhysicalNetwork.State.Enabled) {
1801-
throw new InvalidParameterValueException("Physical network id " + physicalNetworkId + " is in incorrect state: " + pNtwk.getState());
1802-
}
1803-
}
1804-
1805-
DataCenter zone = _dcDao.findById(zoneId);
1806-
1807-
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
1808-
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getId());
1809-
}
1810-
18111823
// If one of the following parameters are defined (starIP/endIP/netmask/gateway), all the rest should be defined too
18121824
ArrayList<String> networkConfigs = new ArrayList<String>();
18131825
networkConfigs.add(gateway);
@@ -1966,11 +1978,13 @@ public Network createNetwork(long networkOfferingId, String name, String display
19661978
} else {
19671979
if (networkDomain == null) {
19681980
//1) Get networkDomain from the corresponding account/domain/zone
1969-
if (aclType == ACLType.Domain) {
1981+
if (aclType == null) {
1982+
networkDomain = getZoneNetworkDomain(zoneId);
1983+
} else if (aclType == ACLType.Domain) {
19701984
networkDomain = getDomainNetworkDomain(domainId, zoneId);
1971-
} else {
1985+
} else if (aclType == ACLType.Account){
19721986
networkDomain = getAccountNetworkDomain(owner.getId(), zoneId);
1973-
}
1987+
}
19741988

19751989
//2) If null, generate networkDomain using domain suffix from the global config variables
19761990
if (networkDomain == null) {

0 commit comments

Comments
 (0)