Skip to content

Commit c5e657d

Browse files
authored
VOLUME.DETACH, created during VM removal has type VirtualMachine instead of Volume and has "Vm Id: XXX" in the description. (#199) (#6891)
Co-authored-by: Maxim Prokopchuk <mprokopchuk@apple.com> (cherry picked from commit 1fcd32f
1 parent 60420b0 commit c5e657d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8062,8 +8062,22 @@ private void validateVolumes(List<VolumeVO> volumes) {
80628062
private void detachVolumesFromVm(List<VolumeVO> volumes) {
80638063

80648064
for (VolumeVO volume : volumes) {
8065-
8066-
Volume detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId());
8065+
CallContext vmContext = CallContext.current();
8066+
// Create new context and inject correct event resource type, id and details,
8067+
// otherwise VOLUME.DETACH event will be associated with VirtualMachine and contain VM id and other information.
8068+
CallContext volumeContext = CallContext.register(vmContext.getCallingUserId(), vmContext.getCallingAccountId());
8069+
volumeContext.setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, volume.getId()) + " Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, volume.getInstanceId()));
8070+
volumeContext.setEventResourceType(ApiCommandResourceType.Volume);
8071+
volumeContext.setEventResourceId(volume.getId());
8072+
volumeContext.setStartEventId(vmContext.getStartEventId());
8073+
8074+
Volume detachResult = null;
8075+
try {
8076+
detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId());
8077+
} finally {
8078+
// Remove volumeContext and pop vmContext back
8079+
CallContext.unregister();
8080+
}
80678081

80688082
if (detachResult == null) {
80698083
s_logger.error("DestroyVM remove volume - failed to detach and delete volume " + volume.getInstanceId() + " from instance " + volume.getId());

0 commit comments

Comments
 (0)