use of com.cloud.network.vpc.VpcOffering in project cloudstack by apache.
the class ContrailManagerImpl method locateVpcOffering.
private VpcOffering locateVpcOffering() {
VpcOffering vpcOffer = _vpcOffDao.findByUniqueName(juniperVPCOfferingName);
if (vpcOffer != null) {
if (((VpcOfferingVO) vpcOffer).getState() == VpcOffering.State.Enabled) {
return vpcOffer;
}
((VpcOfferingVO) vpcOffer).setState(VpcOffering.State.Enabled);
long id = vpcOffer.getId();
_vpcOffDao.update(id, (VpcOfferingVO) vpcOffer);
return vpcOffer;
}
Map<String, List<String>> serviceProviderMap = new HashMap<String, List<String>>();
List<String> providerSet = new ArrayList<String>();
providerSet.add(Provider.JuniperContrailVpcRouter.getName());
final List<String> services = new ArrayList<String>();
services.add(Service.Connectivity.getName());
services.add(Service.Dhcp.getName());
services.add(Service.NetworkACL.getName());
services.add(Service.StaticNat.getName());
services.add(Service.SourceNat.getName());
services.add(Service.Gateway.getName());
services.add(Service.Lb.getName());
for (String svc : services) {
if (svc.equals(Service.Lb.getName())) {
List<String> lbProviderSet = new ArrayList<String>();
lbProviderSet.add(Provider.InternalLbVm.getName());
serviceProviderMap.put(svc, lbProviderSet);
continue;
}
serviceProviderMap.put(svc, providerSet);
}
vpcOffer = _vpcProvSvc.createVpcOffering(juniperVPCOfferingName, juniperVPCOfferingDisplayText, services, serviceProviderMap, null, null, null, null, VpcOffering.State.Enabled);
long id = vpcOffer.getId();
_vpcOffDao.update(id, (VpcOfferingVO) vpcOffer);
return _vpcOffDao.findById(id);
}
use of com.cloud.network.vpc.VpcOffering 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.setCreated(vpc.getCreated());
response.setState(vpc.getState().name());
VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
if (voff != null) {
response.setVpcOfferingId(voff.getUuid());
response.setVpcOfferingName(voff.getName());
}
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.setHasAnnotation(annotationDao.hasAnnotations(vpc.getUuid(), AnnotationService.EntityType.VPC.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
response.setObjectName("vpc");
return response;
}
use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class CreateVPCOfferingCmd method execute.
@Override
public void execute() {
final VpcOffering vpc = _vpcProvSvc.getVpcOffering(getEntityId());
if (vpc != null) {
final VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC offering");
}
}
use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class UpdateVPCOfferingCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
final VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
if (result != null) {
final VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC offering");
}
}
use of com.cloud.network.vpc.VpcOffering in project cosmic by MissionCriticalCloud.
the class ListVPCOfferingsCmd method execute.
@Override
public void execute() {
final Pair<List<? extends VpcOffering>, Integer> offerings = _vpcProvSvc.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(), getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal());
final ListResponse<VpcOfferingResponse> response = new ListResponse<>();
final List<VpcOfferingResponse> offeringResponses = new ArrayList<>();
for (final VpcOffering offering : offerings.first()) {
final VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering);
offeringResponses.add(offeringResponse);
}
response.setResponses(offeringResponses, offerings.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Aggregations