mirror of https://github.com/apache/cloudstack.git
Added support for listing networks based on the supported services information
This commit is contained in:
parent
0228bca0c2
commit
79e13ec3f7
|
|
@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants;
|
|||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.api.response.NetworkResponse;
|
||||
import com.cloud.network.Network;
|
||||
|
|
@ -73,8 +74,8 @@ public class ListNetworksCmd extends BaseListCmd {
|
|||
@Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="list networks by physical network id")
|
||||
private Long physicalNetworkId;
|
||||
|
||||
@Parameter(name=ApiConstants.SOURCE_NAT_ENABLED, type=CommandType.BOOLEAN, description="list networks that support/don't support sourceNat service")
|
||||
private Boolean sourceNatEnabled;
|
||||
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services")
|
||||
private List<String> supportedServices;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -124,8 +125,8 @@ public class ListNetworksCmd extends BaseListCmd {
|
|||
return physicalNetworkId;
|
||||
}
|
||||
|
||||
public Boolean getSourceNatEnabled() {
|
||||
return sourceNatEnabled;
|
||||
public List<String> getSupportedServices() {
|
||||
return supportedServices;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -2038,7 +2038,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
String path = null;
|
||||
Long sharedNetworkDomainId = null;
|
||||
Long physicalNetworkId = cmd.getPhysicalNetworkId();
|
||||
Boolean sourceNatEnabled = cmd.getSourceNatEnabled();
|
||||
List<String> supportedServicesStr = cmd.getSupportedServices();
|
||||
|
||||
//1) default is system to false if not specified
|
||||
//2) reset parameter to false if it's specified by the regular user
|
||||
|
|
@ -2143,16 +2143,27 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, isDefault, trafficType, isShared, physicalNetworkId), searchFilter);
|
||||
}
|
||||
|
||||
//sort networks by sourceNatEnabled parameter
|
||||
if (sourceNatEnabled != null) {
|
||||
List<Network> supportedNetworks = new ArrayList<Network>();
|
||||
for (Network network : networksToReturn) {
|
||||
boolean isSupported = areServicesSupportedInNetwork(network.getId(), Service.SourceNat);
|
||||
if (isSupported == sourceNatEnabled.booleanValue()) {
|
||||
|
||||
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
|
||||
List<NetworkVO> supportedNetworks = new ArrayList<NetworkVO>();
|
||||
Service[] suppportedServices = new Service[supportedServicesStr.size()];
|
||||
int i = 0;
|
||||
for (String supportedServiceStr : supportedServicesStr) {
|
||||
Service service = Service.getService(supportedServiceStr);
|
||||
if (service == null) {
|
||||
throw new InvalidParameterValueException("Invalid service specified " + supportedServiceStr);
|
||||
} else {
|
||||
suppportedServices[i] = service;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for (NetworkVO network : networksToReturn) {
|
||||
if (areServicesSupportedInNetwork(network.getId(), suppportedServices)) {
|
||||
supportedNetworks.add(network);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return supportedNetworks;
|
||||
} else {
|
||||
return networksToReturn;
|
||||
|
|
|
|||
Loading…
Reference in New Issue