mirror of https://github.com/apache/cloudstack.git
Introduced new parameter to listNetworkOfferings API - sourceNatEnabled (Boolean).
This commit is contained in:
parent
e014426889
commit
74f217e1d0
|
|
@ -305,6 +305,7 @@ public class ApiConstants {
|
|||
public static final String FIREWALL_DEVICE_DEDICATED = "fwdevicededicated";
|
||||
public static final String SERVICE = "service";
|
||||
public static final String ASSOCIATED_NETWORK_ID = "associatednetworkid";
|
||||
public static final String SOURCE_NAT_SUPPORTED = "sourcenatsupported";
|
||||
|
||||
public enum HostDetails {
|
||||
all, capacity, events, stats, min;
|
||||
|
|
|
|||
|
|
@ -76,10 +76,12 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
|
|||
@Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, description="list network offerings by guest type: Shared or Isolated")
|
||||
private String guestIpType;
|
||||
|
||||
//Network information
|
||||
@Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list network offerings supporting certain services")
|
||||
private List<String> supportedServices;
|
||||
|
||||
@Parameter(name=ApiConstants.SOURCE_NAT_SUPPORTED, type=CommandType.BOOLEAN, description="true if need to list only netwok offerings where source nat is supported, false otherwise")
|
||||
private Boolean sourceNatSupported;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -132,7 +134,11 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
|
|||
return supportedServices;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
public Boolean getSourceNatSupported() {
|
||||
return sourceNatSupported;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1449,22 +1449,49 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
@Override
|
||||
public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Map<Long, ServiceOffering> serviceOfferings = new HashMap<Long, ServiceOffering>();
|
||||
|
||||
DomainRouterResponse routerResponse = new DomainRouterResponse();
|
||||
routerResponse.setId(router.getId());
|
||||
routerResponse.setZoneId(router.getDataCenterIdToDeployIn());
|
||||
routerResponse.setName(router.getHostName());
|
||||
routerResponse.setPodId(router.getPodIdToDeployIn());
|
||||
routerResponse.setTemplateId(router.getTemplateId());
|
||||
routerResponse.setCreated(router.getCreated());
|
||||
routerResponse.setState(router.getState());
|
||||
routerResponse.setIsRedundantRouter(router.getIsRedundantRouter());
|
||||
routerResponse.setRedundantState(router.getRedundantState().toString());
|
||||
|
||||
if (router.getHostId() != null) {
|
||||
routerResponse.setHostId(router.getHostId());
|
||||
routerResponse.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName());
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
if (router.getHostId() != null) {
|
||||
routerResponse.setHostId(router.getHostId());
|
||||
routerResponse.setHostName(ApiDBUtils.findHostById(router.getHostId()).getName());
|
||||
}
|
||||
routerResponse.setPodId(router.getPodIdToDeployIn());
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(router);
|
||||
for (NicProfile singleNicProfile : nicProfiles) {
|
||||
Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
|
||||
if (network != null) {
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
routerResponse.setPublicIp(singleNicProfile.getIp4Address());
|
||||
routerResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setPublicNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setGateway(singleNicProfile.getGateway());
|
||||
routerResponse.setPublicNetworkId(singleNicProfile.getNetworkId());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
routerResponse.setLinkLocalIp(singleNicProfile.getIp4Address());
|
||||
routerResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setLinkLocalNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setLinkLocalNetworkId(singleNicProfile.getNetworkId());
|
||||
} else if (network.getTrafficType() == TrafficType.Guest) {
|
||||
routerResponse.setGuestIpAddress(singleNicProfile.getIp4Address());
|
||||
routerResponse.setGuestMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setGuestNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setGuestNetworkId(singleNicProfile.getNetworkId());
|
||||
routerResponse.setNetworkDomain(network.getNetworkDomain());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Service Offering Info
|
||||
|
|
@ -1479,30 +1506,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
populateOwner(routerResponse, router);
|
||||
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(router);
|
||||
for (NicProfile singleNicProfile : nicProfiles) {
|
||||
Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
|
||||
if (network != null) {
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
routerResponse.setPublicIp(singleNicProfile.getIp4Address());
|
||||
routerResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setPublicNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setGateway(singleNicProfile.getGateway());
|
||||
routerResponse.setPublicNetworkId(singleNicProfile.getNetworkId());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
routerResponse.setLinkLocalIp(singleNicProfile.getIp4Address());
|
||||
routerResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setLinkLocalNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setLinkLocalNetworkId(singleNicProfile.getNetworkId());
|
||||
} else if (network.getTrafficType() == TrafficType.Guest) {
|
||||
routerResponse.setGuestIpAddress(singleNicProfile.getIp4Address());
|
||||
routerResponse.setGuestMacAddress(singleNicProfile.getMacAddress());
|
||||
routerResponse.setGuestNetmask(singleNicProfile.getNetmask());
|
||||
routerResponse.setGuestNetworkId(singleNicProfile.getNetworkId());
|
||||
routerResponse.setNetworkDomain(network.getNetworkDomain());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataCenter zone = ApiDBUtils.findZoneById(router.getDataCenterIdToDeployIn());
|
||||
if (zone != null) {
|
||||
routerResponse.setZoneName(zone.getName());
|
||||
|
|
|
|||
|
|
@ -3200,31 +3200,50 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
sc.addAnd("id", SearchCriteria.Op.EQ, id);
|
||||
}
|
||||
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);;
|
||||
List<NetworkOfferingVO> offerings = _networkOfferingDao.search(sc, searchFilter);
|
||||
Boolean sourceNatSupported = cmd.getSourceNatSupported();
|
||||
|
||||
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()) {
|
||||
List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
|
||||
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;
|
||||
//filter by supported services
|
||||
boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
|
||||
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null);
|
||||
|
||||
if (parseOfferings) {
|
||||
List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
|
||||
Service[] suppportedServices = null;
|
||||
|
||||
if (listBySupportedServices) {
|
||||
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++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for (NetworkOfferingVO offering : offerings) {
|
||||
if (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), suppportedServices)) {
|
||||
supportedOfferings.add(offering);
|
||||
}
|
||||
|
||||
for (NetworkOfferingVO offering : offerings) {
|
||||
boolean addOffering = true;
|
||||
|
||||
if (listBySupportedServices) {
|
||||
addOffering = addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), suppportedServices);
|
||||
}
|
||||
|
||||
if (sourceNatSupported != null) {
|
||||
addOffering = addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported);
|
||||
}
|
||||
|
||||
if (addOffering) {
|
||||
supportedOfferings.add(offering);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return supportedOfferings;
|
||||
} else {
|
||||
return offerings;
|
||||
return offerings;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue