use of com.cloud.legacymodel.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createVpcResponse.
@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
final VpcResponse response = new VpcResponse();
response.setId(vpc.getUuid());
response.setName(vpc.getName());
response.setDisplayText(vpc.getDisplayText());
response.setState(vpc.getState().name());
final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
if (voff != null) {
response.setVpcOfferingId(voff.getUuid());
response.setVpcOfferingName(voff.getName());
response.setVpcOfferingDisplayText(voff.getDisplayText());
}
response.setCidr(vpc.getCidr());
response.setRestartRequired(vpc.isRestartRequired());
response.setNetworkDomain(vpc.getNetworkDomain());
response.setForDisplay(vpc.isDisplay());
response.setRedundantRouter(vpc.isRedundant());
response.setSourceNatList(vpc.getSourceNatList());
response.setSyslogServerList(vpc.getSyslogServerList());
response.setAdvertInterval(vpc.getAdvertInterval());
response.setAdvertMethod(vpc.getAdvertMethod());
response.setComplianceStatus(vpc.getComplianceStatus());
final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
final List<NetworkResponse> networkResponses = new ArrayList<>();
final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
for (final Network network : networks) {
final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
networkResponses.add(ntwkRsp);
}
final DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
response.setNetworks(networkResponses);
response.setServices(serviceResponses);
populateOwner(response, vpc);
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
if (tagResponse != null) {
tagResponses.add(tagResponse);
}
}
response.setTags(tagResponses);
response.setObjectName("vpc");
return response;
}
use of com.cloud.legacymodel.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method listVpcOfferings.
@Override
public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(final Long id, final String name, final String displayText, final List<String> supportedServicesStr, final Boolean isDefault, final String keyword, final String state, final Long startIndex, final Long pageSizeVal) {
final Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
final SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
if (keyword != null) {
final SearchCriteria<VpcOfferingVO> ssc = _vpcOffDao.createSearchCriteria();
ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (name != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
if (displayText != null) {
sc.addAnd("displayText", SearchCriteria.Op.LIKE, "%" + displayText + "%");
}
if (isDefault != null) {
sc.addAnd("isDefault", SearchCriteria.Op.EQ, isDefault);
}
if (state != null) {
sc.addAnd("state", SearchCriteria.Op.EQ, state);
}
if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
final List<VpcOfferingVO> offerings = _vpcOffDao.search(sc, searchFilter);
// filter by supported services
final boolean listBySupportedServices = supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty();
if (listBySupportedServices) {
final List<VpcOfferingVO> supportedOfferings = new ArrayList<>();
Service[] supportedServices = null;
if (listBySupportedServices) {
supportedServices = getServices(supportedServicesStr);
}
for (final VpcOfferingVO offering : offerings) {
if (areServicesSupportedByVpcOffering(offering.getId(), supportedServices)) {
supportedOfferings.add(offering);
}
}
final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
if (wPagination != null) {
final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<>(wPagination, supportedOfferings.size());
return listWPagination;
}
return new Pair<>(supportedOfferings, supportedOfferings.size());
} else {
final List<? extends VpcOffering> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
if (wPagination != null) {
final Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<>(wPagination, offerings.size());
return listWPagination;
}
return new Pair<>(offerings, offerings.size());
}
}
use of com.cloud.legacymodel.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method createVpcOffering.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_CREATE, eventDescription = "creating vpc offering", create = true)
public VpcOffering createVpcOffering(final String name, final String displayText, final List<String> supportedServices, final Map<String, List<String>> serviceProviders, final Map serviceCapabilitystList, final Long serviceOfferingId, final Long secondaryServiceOfferingId) {
final Map<Network.Service, Set<Network.Provider>> svcProviderMap = new HashMap<>();
final Set<Network.Provider> defaultProviders = new HashSet<>();
defaultProviders.add(Provider.VPCVirtualRouter);
// Just here for 4.1, replaced by commit 836ce6c1 in newer versions
final Set<Network.Provider> sdnProviders = new HashSet<>();
sdnProviders.add(Provider.NiciraNvp);
boolean firewallSvs = false;
// populate the services first
for (final String serviceName : supportedServices) {
// validate if the service is supported
final Service service = Network.Service.getService(serviceName);
if (service == null || nonSupportedServices.contains(service)) {
throw new InvalidParameterValueException("Service " + serviceName + " is not supported in VPC");
}
if (service == Service.Connectivity) {
s_logger.debug("Applying Connectivity workaround, setting provider to NiciraNvp");
svcProviderMap.put(service, sdnProviders);
} else {
svcProviderMap.put(service, defaultProviders);
}
if (service == Service.NetworkACL) {
firewallSvs = true;
}
}
if (!firewallSvs) {
s_logger.debug("Automatically adding network ACL service to the list of VPC services");
svcProviderMap.put(Service.NetworkACL, defaultProviders);
}
if (serviceProviders != null) {
for (final Entry<String, List<String>> serviceEntry : serviceProviders.entrySet()) {
final Network.Service service = Network.Service.getService(serviceEntry.getKey());
if (svcProviderMap.containsKey(service)) {
final Set<Provider> providers = new HashSet<>();
for (final String prvNameStr : serviceEntry.getValue()) {
// check if provider is supported
final Network.Provider provider = Network.Provider.getProvider(prvNameStr);
if (provider == null) {
throw new InvalidParameterValueException("Invalid service provider: " + prvNameStr);
}
providers.add(provider);
}
svcProviderMap.put(service, providers);
} else {
throw new InvalidParameterValueException("Service " + serviceEntry.getKey() + " is not enabled for the network " + "offering, can't add a provider to it");
}
}
}
validateConnectivtyServiceCapabilities(svcProviderMap.get(Service.Connectivity), serviceCapabilitystList);
final boolean redundantRouter = isVpcOfferingRedundantRouter(serviceCapabilitystList);
final VpcOffering offering = createVpcOffering(name, displayText, svcProviderMap, false, null, serviceOfferingId, secondaryServiceOfferingId, redundantRouter);
CallContext.current().setEventDetails(" Id: " + offering.getId() + " Name: " + name);
return offering;
}
Aggregations