VPC: added "forVpc" parameter to listNetworkOfferings command. If true, the offeirng can be used for vpc networks only

Conflicts:

	api/src/com/cloud/api/ApiConstants.java
	server/src/com/cloud/api/ApiDBUtils.java
This commit is contained in:
Alena Prokharchyk 2012-07-03 15:37:07 -07:00
parent 2b799aa9ac
commit da6d876cd4
8 changed files with 50 additions and 4 deletions

View File

@ -365,7 +365,6 @@ public class ApiConstants {
public static final String RESOURCE_IDS = "resourceids";
public static final String RESOURCE_ID = "resourceid";
public static final String CUSTOMER = "customer";
public static final String S2S_VPN_GATEWAY_ID = "s2svpngatewayid";
public static final String S2S_CUSTOMER_GATEWAY_ID = "s2scustomergatewayid";
public static final String IPSEC_PSK = "ipsecpsk";
@ -374,6 +373,7 @@ public class ApiConstants {
public static final String IKE_POLICY = "ikepolicy";
public static final String ESP_POLICY = "esppolicy";
public static final String LIFETIME = "lifetime";
public static final String FOR_VPC = "forvpc";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -90,6 +90,10 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.IS_TAGGED, type=CommandType.BOOLEAN, description="true if offering has tags specified")
private Boolean isTagged;
@Parameter(name=ApiConstants.FOR_VPC, type=CommandType.BOOLEAN, description="the network offering can be used" +
" only for network creation inside the VPC")
private Boolean forVpc;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -158,6 +162,10 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
return isTagged;
}
public Boolean getForVpc() {
return forVpc;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -74,6 +74,9 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName(ApiConstants.SERVICE) @Param(description="the list of supported services", responseObject = ServiceResponse.class)
private List<ServiceResponse> services;
@SerializedName(ApiConstants.FOR_VPC) @Param(description="true if network offering can be used by VPC networks only")
private Boolean forVpc;
public void setId(Long id) {
this.id.setValue(id);
@ -142,4 +145,8 @@ public class NetworkOfferingResponse extends BaseResponse{
public void setSpecifyIpRanges(Boolean specifyIpRanges) {
this.specifyIpRanges = specifyIpRanges;
}
public void setForVpc(Boolean forVpc) {
this.forVpc = forVpc;
}
}

View File

@ -34,7 +34,6 @@ import com.cloud.api.commands.DeleteZoneCmd;
import com.cloud.api.commands.LDAPConfigCmd;
import com.cloud.api.commands.LDAPRemoveCmd;
import com.cloud.api.commands.ListNetworkOfferingsCmd;
import com.cloud.api.commands.MarkDefaultZoneForAccountCmd;
import com.cloud.api.commands.UpdateCfgCmd;
import com.cloud.api.commands.UpdateDiskOfferingCmd;
import com.cloud.api.commands.UpdateNetworkOfferingCmd;
@ -263,4 +262,10 @@ public interface ConfigurationService {
boolean updateLDAP(LDAPConfigCmd cmd) throws NamingException;
boolean removeLDAP(LDAPRemoveCmd cmd);
/**
* @param offering
* @return
*/
boolean isOfferingForVpc(NetworkOffering offering);
}

View File

@ -70,6 +70,7 @@ import com.cloud.network.security.SecurityGroupManager;
import com.cloud.network.security.SecurityGroupVO;
import com.cloud.network.security.dao.SecurityGroupDao;
import com.cloud.network.vpc.VpcManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -772,5 +773,9 @@ public class ApiDBUtils {
public static String getUuid(String resourceId, TaggedResourceType resourceType) {
return _taggedResourceService.getUuid(resourceId, resourceType);
}
public static boolean isOfferingForVpc(NetworkOffering offering) {
boolean vpcProvider = _configMgr.isOfferingForVpc(offering);
return vpcProvider;
}
}

View File

@ -2788,6 +2788,8 @@ public class ApiResponseHelper implements ResponseGenerator {
serviceResponses.add(svcRsp);
}
response.setForVpc(ApiDBUtils.isOfferingForVpc(offering));
response.setServices(serviceResponses);
response.setObjectName("networkoffering");
return response;

View File

@ -3280,6 +3280,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
Object specifyIpRanges = cmd.getSpecifyIpRanges();
String tags = cmd.getTags();
Boolean isTagged = cmd.isTagged();
Boolean forVpc = cmd.getForVpc();
if (zoneId != null) {
zone = getZone(zoneId);
@ -3407,7 +3408,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
// filter by supported services
boolean listBySupportedServices = (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
boolean checkIfProvidersAreEnabled = (zoneId != null);
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled);
boolean parseOfferings = (listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled
|| forVpc != null);
if (parseOfferings) {
List<NetworkOfferingVO> supportedOfferings = new ArrayList<NetworkOfferingVO>();
@ -3454,6 +3456,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (sourceNatSupported != null) {
addOffering = addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SourceNat) == sourceNatSupported);
}
if (forVpc != null) {
addOffering = addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue());
}
if (addOffering) {
supportedOfferings.add(offering);
@ -3467,6 +3473,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
}
@Override
public boolean isOfferingForVpc(NetworkOffering offering) {
boolean vpcProvider = _ntwkOffServiceMapDao.isProviderForNetworkOffering(offering.getId(),
Provider.VPCVirtualRouter);
return vpcProvider;
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_DELETE, eventDescription = "deleting network offering")
public boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd) {

View File

@ -2819,9 +2819,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//Create guest network
Network network = null;
if (vpcId != null) {
if (!_configMgr.isOfferingForVpc(ntwkOff)){
throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
}
network = createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId);
} else {
if (_configMgr.isOfferingForVpc(ntwkOff)){
throw new InvalidParameterValueException("Network offering can be used for VPC networks only");
}
network = createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId);
}