use of com.cloud.api.response.NetworkOfferingResponse in project cosmic by MissionCriticalCloud.
the class CreateNetworkOfferingCmd method execute.
@Override
public void execute() {
final NetworkOffering result = _configService.createNetworkOffering(this);
if (result != null) {
final NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network offering");
}
}
use of com.cloud.api.response.NetworkOfferingResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNetworkOfferingResponse.
@Override
public NetworkOfferingResponse createNetworkOfferingResponse(final NetworkOffering offering) {
final NetworkOfferingResponse response = new NetworkOfferingResponse();
response.setId(offering.getUuid());
response.setName(offering.getName());
response.setDisplayText(offering.getDisplayText());
response.setTags(offering.getTags());
response.setTrafficType(offering.getTrafficType().toString());
response.setIsDefault(offering.isDefault());
response.setSpecifyVlan(offering.getSpecifyVlan());
response.setConserveMode(offering.isConserveMode());
response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
response.setAvailability(offering.getAvailability().toString());
response.setIsPersistent(offering.getIsPersistent());
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
response.setEgressDefaultPolicy(offering.getEgressDefaultPolicy());
response.setConcurrentConnections(offering.getConcurrentConnections());
response.setSupportsStrechedL2Subnet(offering.getSupportsStrechedL2());
final Long so;
if (offering.getServiceOfferingId() != null) {
so = offering.getServiceOfferingId();
} else {
so = ApiDBUtils.findDefaultRouterServiceOffering();
}
if (so != null) {
final ServiceOffering serviceOffering = ApiDBUtils.findServiceOfferingById(so);
if (serviceOffering != null) {
response.setServiceOfferingId(serviceOffering.getUuid());
response.setServiceOfferingName(serviceOffering.getName());
}
}
final ServiceOffering secondaryServiceOffering = this._serviceOfferingDao.findById(offering.getSecondaryServiceOfferingId());
if (secondaryServiceOffering != null) {
response.setSecondaryServiceOfferingId(secondaryServiceOffering.getUuid());
response.setSecondaryServiceOfferingName(secondaryServiceOffering.getName());
}
if (offering.getGuestType() != null) {
response.setGuestIpType(offering.getGuestType().toString());
}
response.setState(offering.getState().name());
final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
final List<ServiceResponse> serviceResponses = new ArrayList<>();
for (final Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
final Service service = entry.getKey();
final Set<Provider> srvc_providers = entry.getValue();
final ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
svcRsp.setName(service.getName());
final List<ProviderResponse> providers = getProviderResponses(srvc_providers);
svcRsp.setProviders(providers);
if (Service.Lb == service) {
final List<CapabilityResponse> lbCapResponse = new ArrayList<>();
final CapabilityResponse lbIsoaltion = new CapabilityResponse();
lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
lbCapResponse.add(lbIsoaltion);
final CapabilityResponse eLb = new CapabilityResponse();
eLb.setName(Capability.ElasticLb.getName());
eLb.setValue(offering.getElasticLb() ? "true" : "false");
lbCapResponse.add(eLb);
final CapabilityResponse inline = new CapabilityResponse();
inline.setName(Capability.InlineMode.getName());
inline.setValue(offering.isInline() ? "true" : "false");
lbCapResponse.add(inline);
svcRsp.setCapabilities(lbCapResponse);
} else if (Service.SourceNat == service) {
final List<CapabilityResponse> capabilities = new ArrayList<>();
final CapabilityResponse sharedSourceNat = new CapabilityResponse();
sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
capabilities.add(sharedSourceNat);
final CapabilityResponse redundantRouter = new CapabilityResponse();
redundantRouter.setName(Capability.RedundantRouter.getName());
redundantRouter.setValue(offering.getRedundantRouter() ? "true" : "false");
capabilities.add(redundantRouter);
svcRsp.setCapabilities(capabilities);
} else if (service == Service.StaticNat) {
final List<CapabilityResponse> staticNatCapResponse = new ArrayList<>();
final CapabilityResponse eIp = new CapabilityResponse();
eIp.setName(Capability.ElasticIp.getName());
eIp.setValue(offering.getElasticIp() ? "true" : "false");
staticNatCapResponse.add(eIp);
final CapabilityResponse associatePublicIp = new CapabilityResponse();
associatePublicIp.setName(Capability.AssociatePublicIP.getName());
associatePublicIp.setValue(offering.getAssociatePublicIP() ? "true" : "false");
staticNatCapResponse.add(associatePublicIp);
svcRsp.setCapabilities(staticNatCapResponse);
}
serviceResponses.add(svcRsp);
}
response.setForVpc(this._configMgr.isOfferingForVpc(offering));
response.setServices(serviceResponses);
// set network offering details
final Map<Detail, String> details = this._ntwkModel.getNtwkOffDetails(offering.getId());
if (details != null && !details.isEmpty()) {
response.setDetails(details);
}
response.setObjectName("networkoffering");
return response;
}
Aggregations