This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new c5e657ddd80 VOLUME.DETACH, created during VM removal has type
VirtualMachine instead of Volume and has "Vm Id: XXX" in the description.
(#199) (#6891)
c5e657ddd80 is described below
commit c5e657ddd80faa93585aef1381e30b7e2d9a9eaa
Author: mprokopchuk <[email protected]>
AuthorDate: Sun Nov 13 02:46:08 2022 -0800
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 <[email protected]>
(cherry picked from commit 1fcd32fa3384673aff332196b27a6d1b933ec000
---
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index dd579f8a246..f9bf52ea32b 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -8062,8 +8062,22 @@ public class UserVmManagerImpl extends ManagerBase
implements UserVmManager, Vir
private void detachVolumesFromVm(List<VolumeVO> volumes) {
for (VolumeVO volume : volumes) {
-
- Volume detachResult =
_volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId());
+ 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 = 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());