Skip to content
Merged
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
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/network/vpc/VpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String disp
*/
boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;

void startVpc(CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;

/**
* Shuts down the VPC which includes shutting down all VPC provider and rules cleanup on the backend
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ public void create() throws ResourceAllocationException {
public void execute() {
Vpc vpc = null;
try {
if (isStart()) {
_vpcService.startVpc(getEntityId(), true);
} else {
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
}
_vpcService.startVpc(this);
vpc = _entityMgr.findById(Vpc.class, getEntityId());
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,16 @@ public void testCreate() throws ResourceAllocationException {

@Test
public void testExecute() throws ResourceUnavailableException, InsufficientCapacityException {
ReflectionTestUtils.setField(cmd, "start", true);
Vpc vpc = Mockito.mock(Vpc.class);
VpcResponse response = Mockito.mock(VpcResponse.class);

ReflectionTestUtils.setField(cmd, "id", 1L);
responseGenerator = Mockito.mock(ResponseGenerator.class);
Mockito.when(_vpcService.startVpc(1L, true)).thenReturn(true);
Mockito.doNothing().when(_vpcService).startVpc(cmd);
Mockito.when(_entityMgr.findById(Mockito.eq(Vpc.class), Mockito.any(Long.class))).thenReturn(vpc);
cmd._responseGenerator = responseGenerator;
Mockito.when(responseGenerator.createVpcResponse(ResponseObject.ResponseView.Restricted, vpc)).thenReturn(response);
cmd.execute();
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(Mockito.anyLong(), Mockito.anyBoolean());
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(cmd);
}
}
11 changes: 11 additions & 0 deletions server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,17 @@ public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws
return result;
}


@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", async = true)
public void startVpc(final CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (!cmd.isStart()) {
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
return;
}
startVpc(cmd.getEntityId(), true);
}

protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
// deploy provider
Expand Down