VOLUME.DETACH, created during VM removal has type VirtualMachine instead of Volume and has "Vm Id: XXX" in the description. (#199)

Volume detach should publish volume resource info, not VM resource info

Co-authored-by: Maxim Prokopchuk <mprokopchuk@apple.com>
This commit is contained in:
mprokopchuk 2022-09-26 10:28:48 -07:00 committed by GitHub
parent a652570408
commit 1fcd32fa33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -7833,8 +7833,22 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
private void detachVolumesFromVm(List<VolumeVO> volumes) {
for (VolumeVO volume : volumes) {
CallContext vmContext = CallContext.current();
// Create new context and inject correct event resource type, id and details,
// otherwise VOLUME.DETACH event will be associated with VirtualMachine and contain VM id and other information.
CallContext volumeContext = CallContext.register(vmContext.getCallingUserId(), vmContext.getCallingAccountId());
volumeContext.setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, volume.getId()) + " Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, volume.getInstanceId()));
volumeContext.setEventResourceType(ApiCommandResourceType.Volume);
volumeContext.setEventResourceId(volume.getId());
volumeContext.setStartEventId(vmContext.getStartEventId());
Volume detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId());
Volume detachResult = null;
try {
detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId());
} finally {
// Remove volumeContext and pop vmContext back
CallContext.unregister();
}
if (detachResult == null) {
s_logger.error("DestroyVM remove volume - failed to detach and delete volume " + volume.getInstanceId() + " from instance " + volume.getId());