Destroyvm also removes volumes by houthuis · Pull Request #18 · shapeblue/cloudstack · GitHub
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
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/storage/VolumeApiService.java
2 changes: 2 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ public class ApiConstants {
public static final String EXITCODE = "exitcode";
public static final String TARGET_ID = "targetid";

public static final String VOLUME_IDS = "volumeids";

public enum HostDetails {
all, capacity, events, stats, min;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.context.CallContext;

import com.cloud.event.EventTypes;
Expand Down Expand Up @@ -63,6 +64,14 @@ public class DestroyVMCmd extends BaseAsyncCmd {
since = "4.2.1")
private Boolean expunge;

@Parameter( name = ApiConstants.VOLUME_IDS,
type = CommandType.LIST,
collectionType = CommandType.UUID,
entityType = VolumeResponse.class,
description = "Comma separated list of UUIDs for volumes that will be deleted",
since = "4.12.0")
private List<Long> volumeIds;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -78,6 +87,10 @@ public boolean getExpunge() {
return expunge;
}

public List<Long> getVolumeIds() {
return volumeIds;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,14 @@ private void validateRootVolumeDetachAttach(VolumeVO volume, UserVmVO vm) {
}
}

@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DETACH, eventDescription = "detaching volume")
public Volume detachVolumeViaDestroyVM(long vmId, long volumeId) {

Volume result = orchestrateDetachVolumeFromVM(vmId, volumeId);

return result;
}

private Volume orchestrateDetachVolumeFromVM(long vmId, long volumeId) {

Volume volume = _volsDao.findById(volumeId);
Expand Down
236 changes: 155 additions & 81 deletions server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Loading