Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
import org.apache.cloudstack.api.response.VpcOfferingResponse;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -72,6 +73,12 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the VPC offering, integer")
private Integer sortKey;

@Parameter(name = ApiConstants.SERVICE_OFFERING_ID,
type = CommandType.UUID,
entityType = ServiceOfferingResponse.class,
description = "the ID of the service offering for the VPC router appliance")
private Long serviceOfferingId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -156,6 +163,10 @@ public Integer getSortKey() {
return sortKey;
}

public Long getServiceOfferingId() {
return serviceOfferingId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class VpcOfferingResponse extends BaseResponse {
@Param(description = "the zone name(s) this disk offering belongs to. Ignore this information as it is not currently applicable.", since = "4.13.0")
private String zone;

@SerializedName(ApiConstants.SERVICE_OFFERING_ID)
@Param(description = "the service offering which was used to create vpc offering")
private String serviceOfferingId;

public void setId(String id) {
this.id = id;
}
Expand Down Expand Up @@ -149,4 +153,8 @@ public String getZone() {
public void setZone(String zone) {
this.zone = zone;
}

public void setServiceOfferingId(String serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public Long getServiceOfferingId() {
return serviceOfferingId;
}

public void setServiceOfferingId(Long serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}

@Override
public boolean isSupportsDistributedRouter() {
return supportsDistributedRouter;
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import javax.inject.Inject;

import com.cloud.resource.RollingMaintenanceManager;
import com.cloud.service.dao.ServiceOfferingDao;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.affinity.AffinityGroup;
Expand Down Expand Up @@ -391,6 +392,8 @@ public class ApiResponseHelper implements ResponseGenerator {
private VMSnapshotDao vmSnapshotDao;
@Inject
private BackupOfferingDao backupOfferingDao;
@Inject
private ServiceOfferingDao serviceOfferingDao;

@Override
public UserResponse createUserResponse(User user) {
Expand Down Expand Up @@ -2887,6 +2890,8 @@ public VpcOfferingResponse createVpcOfferingResponse(VpcOffering offering) {
serviceResponses.add(svcRsp);
}
response.setServices(serviceResponses);
if(offering.getServiceOfferingId() != null)
response.setServiceOfferingId(serviceOfferingDao.findById(offering.getServiceOfferingId()).getUuid());
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public boolean deleteVpcOffering(final long offId) {
@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, null, null, null);
return updateVpcOfferingInternal(vpcOffId, vpcOfferingName, displayText, state, null, null, null, null);
}

@Override
Expand All @@ -817,6 +817,7 @@ public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd cmd) {
final List<Long> domainIds = cmd.getDomainIds();
final List<Long> zoneIds = cmd.getZoneIds();
final Integer sortKey = cmd.getSortKey();
final Long serviceOfferingId = cmd.getServiceOfferingId();

// check if valid domain
if (CollectionUtils.isNotEmpty(domainIds)) {
Expand All @@ -835,10 +836,10 @@ public VpcOffering updateVpcOffering(final UpdateVPCOfferingCmd cmd) {
}
}

return updateVpcOfferingInternal(offeringId, vpcOfferingName, displayText, state, sortKey, domainIds, zoneIds);
return updateVpcOfferingInternal(offeringId, vpcOfferingName, displayText, state, sortKey, domainIds, zoneIds, serviceOfferingId);
}

private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingName, String displayText, String state, Integer sortKey, final List<Long> domainIds, final List<Long> zoneIds) {
private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingName, String displayText, String state, Integer sortKey, final List<Long> domainIds, final List<Long> zoneIds, final Long serviceOfferingId) {
CallContext.current().setEventDetails(" Id: " + vpcOffId);

// Verify input parameters
Expand Down Expand Up @@ -875,6 +876,7 @@ private VpcOffering updateVpcOfferingInternal(long vpcOffId, String vpcOfferingN
if (displayText != null) {
offering.setDisplayText(displayText);
}
offering.setServiceOfferingId(serviceOfferingId);
if (state != null) {
boolean validState = false;
for (final VpcOffering.State st : VpcOffering.State.values()) {
Expand Down
64 changes: 64 additions & 0 deletions test/integration/component/test_vpc_offerings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def __init__(self):
"cpuspeed": 100,
"memory": 128,
},
"vpc_service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100,
"memory": 128,
"systemvmtype": "domainrouter",
"issystem": True,
},
"network_offering": {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
Expand Down Expand Up @@ -189,8 +198,13 @@ def setUpClass(cls):
cls.api_client,
cls.services["service_offering"]
)
cls.system_offering = ServiceOffering.create(
cls.api_client,
cls.services["vpc_service_offering"]
)
cls._cleanup = [
cls.service_offering,
cls.system_offering
]
return

Expand Down Expand Up @@ -269,6 +283,36 @@ def validate_vpc_network(self, network):
self.logger.debug("VPC network created successfully - %s" % network.name)
return

def validate_vpc_offering_with_selected_service_offering(self, vpc_offering):
"""Validates the VPC offering with selected service offering"""

self.logger.debug("Check if the VPC offering is created successfully?")
self.logger.debug(vpc_offering.serviceofferingid)
vpc_offs = VpcOffering.list(
self.apiclient,
id=vpc_offering.id
)
self.assertEqual(
isinstance(vpc_offs, list),
True,
"List VPC offerings should return a valid list"
)
self.assertEqual(
vpc_offering.name,
vpc_offs[0].name,
"Name of the VPC offering should match with listVPCOff data"
)
self.assertEqual(
vpc_offering.serviceofferingid,
vpc_offs[0].serviceofferingid,
"Service offering of the VPC offering should match with listVPCOff data"
)
self.logger.debug(
"VPC offering is created successfully - %s" %
vpc_offering.name
)
return

@attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_01_create_vpc_offering(self):
""" Test create VPC offering
Expand Down Expand Up @@ -1201,3 +1245,23 @@ def test_09_create_redundant_vpc_offering(self):
)

return

@attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_10_create_vpc_offering_with_selected_service_offering(self):
""" Test create VPC offering with selected service offering
"""

# Steps for validation
# 1. Create VPC Offering by specifying all supported Services
# 2. VPC offering should be created successfully.

self.logger.debug("Creating inter VPC offering with selected service offering")
vpc_off = VpcOffering.create(
self.api_client,
services=self.services["vpc_offering"],
serviceofferingid=self.system_offering.id
)
self.logger.debug("Check if the VPC offering is created successfully?")
self.cleanup.append(vpc_off)
self.validate_vpc_offering_with_selected_service_offering(vpc_off)
return
3 changes: 2 additions & 1 deletion tools/marvin/marvin/lib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4409,7 +4409,7 @@ def __init__(self, items):
self.__dict__.update(items)

@classmethod
def create(cls, apiclient, services):
def create(cls, apiclient, services, serviceofferingid=None):
"""Create vpc offering"""

import logging
Expand All @@ -4418,6 +4418,7 @@ def create(cls, apiclient, services):
cmd.name = "-".join([services["name"], random_gen()])
cmd.displaytext = services["displaytext"]
cmd.supportedServices = services["supportedservices"]
cmd.serviceofferingid = serviceofferingid
if "serviceProviderList" in services:
for service, provider in services["serviceProviderList"].items():
providers = provider
Expand Down
Loading