From 74f217e1d0cf31b2f5eb9a1de111563077a19dbb Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 22 Nov 2011 10:54:29 -0800 Subject: [PATCH] Introduced new parameter to listNetworkOfferings API - sourceNatEnabled (Boolean). --- api/src/com/cloud/api/ApiConstants.java | 1 + .../api/commands/ListNetworkOfferingsCmd.java | 10 +++- .../src/com/cloud/api/ApiResponseHelper.java | 60 ++++++++++--------- .../ConfigurationManagerImpl.java | 57 ++++++++++++------ 4 files changed, 79 insertions(+), 49 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 9d4661da732..54467147358 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -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; diff --git a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java index c723e08b38d..dd1cc2c32f2 100644 --- a/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworkOfferingsCmd.java @@ -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 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 diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 0de84bf4554..5b43781f6ed 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1449,22 +1449,49 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) { + Account caller = UserContext.current().getCaller(); Map serviceOfferings = new HashMap(); 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 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 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()); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index a489200319f..037a0f6ed2d 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3200,31 +3200,50 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura sc.addAnd("id", SearchCriteria.Op.EQ, id); } - List offerings = _networkOfferingDao.search(sc, searchFilter);; + List offerings = _networkOfferingDao.search(sc, searchFilter); + Boolean sourceNatSupported = cmd.getSourceNatSupported(); - if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty()) { - List supportedOfferings = new ArrayList(); - 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 supportedOfferings = new ArrayList(); + 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; } }