use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.
the class ApiResponseHelper method createVpcResponse.
@Override
public VpcResponse createVpcResponse(ResponseView view, Vpc vpc) {
VpcResponse response = new VpcResponse();
response.setId(vpc.getUuid());
response.setName(vpc.getName());
response.setDisplayText(vpc.getDisplayText());
response.setState(vpc.getState().name());
VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
if (voff != null) {
response.setVpcOfferingId(voff.getUuid());
}
response.setCidr(vpc.getCidr());
response.setRestartRequired(vpc.isRestartRequired());
response.setNetworkDomain(vpc.getNetworkDomain());
response.setForDisplay(vpc.isDisplay());
response.setUsesDistributedRouter(vpc.usesDistributedRouter());
response.setRedundantRouter(vpc.isRedundant());
response.setRegionLevelVpc(vpc.isRegionLevelVpc());
Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
Service service = entry.getKey();
Set<Provider> serviceProviders = entry.getValue();
ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
svcRsp.setName(service.getName());
List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
for (Provider provider : serviceProviders) {
if (provider != null) {
ProviderResponse providerRsp = new ProviderResponse();
providerRsp.setName(provider.getName());
providers.add(providerRsp);
}
}
svcRsp.setProviders(providers);
serviceResponses.add(svcRsp);
}
List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
for (Network network : networks) {
NetworkResponse ntwkRsp = createNetworkResponse(view, network);
networkResponses.add(ntwkRsp);
}
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
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
response.setTags(tagResponses);
response.setObjectName("vpc");
return response;
}
use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.
the class ApiResponseHelper method createVpcOfferingResponse.
@Override
public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) {
VpcOfferingResponse response = new VpcOfferingResponse();
response.setId(offering.getUuid());
response.setName(offering.getName());
response.setDisplayText(offering.getDisplayText());
response.setIsDefault(offering.isDefault());
response.setState(offering.getState().name());
response.setSupportsDistributedRouter(offering.supportsDistributedRouter());
response.setSupportsRegionLevelVpc(offering.offersRegionLevelVPC());
Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(offering.getId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
Service service = entry.getKey();
Set<Provider> srvc_providers = entry.getValue();
ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
svcRsp.setName(service.getName());
List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
for (Provider provider : srvc_providers) {
if (provider != null) {
ProviderResponse providerRsp = new ProviderResponse();
providerRsp.setName(provider.getName());
providers.add(providerRsp);
}
}
svcRsp.setProviders(providers);
serviceResponses.add(svcRsp);
}
response.setServices(serviceResponses);
response.setObjectName("vpcoffering");
return response;
}
use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.
the class ApiResponseHelper method createNetworkServiceResponse.
@Override
public ServiceResponse createNetworkServiceResponse(Service service) {
ServiceResponse response = new ServiceResponse();
response.setName(service.getName());
// set list of capabilities required for the service
List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
Capability[] capabilities = service.getCapabilities();
for (Capability cap : capabilities) {
CapabilityResponse capabilityResponse = new CapabilityResponse();
capabilityResponse.setName(cap.getName());
capabilityResponse.setObjectName("capability");
if (cap.getName().equals(Capability.SupportedLBIsolation.getName()) || cap.getName().equals(Capability.SupportedSourceNatTypes.getName()) || cap.getName().equals(Capability.RedundantRouter.getName())) {
capabilityResponse.setCanChoose(true);
} else {
capabilityResponse.setCanChoose(false);
}
capabilityResponses.add(capabilityResponse);
}
response.setCapabilities(capabilityResponses);
// set list of providers providing this service
List<? extends Network.Provider> serviceProviders = ApiDBUtils.getProvidersForService(service);
List<ProviderResponse> serviceProvidersResponses = new ArrayList<ProviderResponse>();
for (Network.Provider serviceProvider : serviceProviders) {
// return only Virtual Router/JuniperSRX/CiscoVnmc as a provider for the firewall
if (service == Service.Firewall && !(serviceProvider == Provider.VirtualRouter || serviceProvider == Provider.JuniperSRX || serviceProvider == Provider.CiscoVnmc || serviceProvider == Provider.PaloAlto || serviceProvider == Provider.NuageVsp || serviceProvider == Provider.BigSwitchBcf)) {
continue;
}
ProviderResponse serviceProviderResponse = createServiceProviderResponse(serviceProvider);
serviceProvidersResponses.add(serviceProviderResponse);
}
response.setProviders(serviceProvidersResponses);
response.setObjectName("networkservice");
return response;
}
use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.
the class ApiResponseHelper method createNetworkOfferingResponse.
@Override
public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering offering) {
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());
response.setSupportsPublicAccess(offering.getSupportsPublicAccess());
Long so = null;
if (offering.getServiceOfferingId() != null) {
so = offering.getServiceOfferingId();
} else {
so = ApiDBUtils.findDefaultRouterServiceOffering();
}
if (so != null) {
ServiceOffering soffering = ApiDBUtils.findServiceOfferingById(so);
if (soffering != null) {
response.setServiceOfferingId(soffering.getUuid());
}
}
if (offering.getGuestType() != null) {
response.setGuestIpType(offering.getGuestType().toString());
}
response.setState(offering.getState().name());
Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listNetworkOfferingServices(offering.getId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
for (Map.Entry<Service, Set<Provider>> entry : serviceProviderMap.entrySet()) {
Service service = entry.getKey();
Set<Provider> srvc_providers = entry.getValue();
ServiceResponse svcRsp = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
svcRsp.setName(service.getName());
List<ProviderResponse> providers = new ArrayList<ProviderResponse>();
for (Provider provider : srvc_providers) {
if (provider != null) {
ProviderResponse providerRsp = new ProviderResponse();
providerRsp.setName(provider.getName());
providers.add(providerRsp);
}
}
svcRsp.setProviders(providers);
if (Service.Lb == service) {
List<CapabilityResponse> lbCapResponse = new ArrayList<CapabilityResponse>();
CapabilityResponse lbIsoaltion = new CapabilityResponse();
lbIsoaltion.setName(Capability.SupportedLBIsolation.getName());
lbIsoaltion.setValue(offering.getDedicatedLB() ? "dedicated" : "shared");
lbCapResponse.add(lbIsoaltion);
CapabilityResponse eLb = new CapabilityResponse();
eLb.setName(Capability.ElasticLb.getName());
eLb.setValue(offering.getElasticLb() ? "true" : "false");
lbCapResponse.add(eLb);
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) {
List<CapabilityResponse> capabilities = new ArrayList<CapabilityResponse>();
CapabilityResponse sharedSourceNat = new CapabilityResponse();
sharedSourceNat.setName(Capability.SupportedSourceNatTypes.getName());
sharedSourceNat.setValue(offering.getSharedSourceNat() ? "perzone" : "peraccount");
capabilities.add(sharedSourceNat);
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) {
List<CapabilityResponse> staticNatCapResponse = new ArrayList<CapabilityResponse>();
CapabilityResponse eIp = new CapabilityResponse();
eIp.setName(Capability.ElasticIp.getName());
eIp.setValue(offering.getElasticIp() ? "true" : "false");
staticNatCapResponse.add(eIp);
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(_configMgr.isOfferingForVpc(offering));
response.setServices(serviceResponses);
//set network offering details
Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
if (details != null && !details.isEmpty()) {
response.setDetails(details);
}
response.setObjectName("networkoffering");
return response;
}
use of org.apache.cloudstack.api.response.ProviderResponse in project cloudstack by apache.
the class UpdateNetworkServiceProviderCmd method execute.
@Override
public void execute() {
PhysicalNetworkServiceProvider result = _networkService.updateNetworkServiceProvider(getId(), getState(), getEnabledServices());
if (result != null) {
ProviderResponse response = _responseGenerator.createNetworkServiceProviderResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update service provider");
}
}
Aggregations