@@ -419,6 +419,64 @@ public JContainer DestroyCommand([FromBody]dynamic cmd)
419419 }
420420 }
421421
422+ // POST api/HypervResource/DeleteCommand
423+ [ HttpPost ]
424+ [ ActionName ( CloudStackTypes . DeleteCommand ) ]
425+ public JContainer DeleteCommand ( [ FromBody ] dynamic cmd )
426+ {
427+ using ( log4net . NDC . Push ( Guid . NewGuid ( ) . ToString ( ) ) )
428+ {
429+ logger . Info ( CloudStackTypes . DestroyCommand + cmd . ToString ( ) ) ;
430+
431+ string details = null ;
432+ bool result = false ;
433+
434+ try
435+ {
436+ // Assert
437+ String errMsg = "No 'volume' details in " + CloudStackTypes . DestroyCommand + " " + cmd . ToString ( ) ;
438+ VolumeObjectTO destVolumeObjectTO = VolumeObjectTO . ParseJson ( cmd . data ) ;
439+
440+ if ( destVolumeObjectTO . name == null )
441+ {
442+ logger . Error ( errMsg ) ;
443+ throw new ArgumentException ( errMsg ) ;
444+ }
445+
446+ String path = destVolumeObjectTO . FullFileName ;
447+ if ( ! File . Exists ( path ) )
448+ {
449+ logger . Info ( CloudStackTypes . DestroyCommand + ", but volume at pass already deleted " + path ) ;
450+ }
451+
452+ string vmName = ( string ) cmd . vmName ;
453+ if ( ! string . IsNullOrEmpty ( vmName ) && File . Exists ( path ) )
454+ {
455+ // Make sure that this resource is removed from the VM
456+ wmiCallsV2 . DetachDisk ( vmName , path ) ;
457+ }
458+
459+ File . Delete ( path ) ;
460+ result = true ;
461+ }
462+ catch ( Exception sysEx )
463+ {
464+ details = CloudStackTypes . DestroyCommand + " failed due to " + sysEx . Message ;
465+ logger . Error ( details , sysEx ) ;
466+ }
467+
468+ object ansContent = new
469+ {
470+ result = result ,
471+ details = details ,
472+ contextMap = contextMap
473+ } ;
474+
475+ return ReturnCloudStackTypedJArray ( ansContent , CloudStackTypes . Answer ) ;
476+ }
477+ }
478+
479+
422480 private static JArray ReturnCloudStackTypedJArray ( object ansContent , string ansType )
423481 {
424482 JObject ansObj = Utils . CreateCloudStackObject ( ansType , ansContent ) ;
0 commit comments