public async Task <Vm> Delete(string id) { //Implemented by stopping vm (if necessary), unregistering vm, and deleting vm folder //This protects the base disk from deletion. When we get vvols, and a data provider //with instance-clone of vvols, every vm will have its own disk, and we can just //delete the vm. await Connect(); Vm vm = _vmCache[id]; string tag = vm.Name.Tag(); _logger.LogDebug($"Delete: stopping vm {vm.Name}"); await Stop(id); vm.State = VmPowerState.Off; _logger.LogDebug($"Delete: unregistering vm {vm.Name}"); await _netman.Unprovision(vm.AsVim()); await _vim.UnregisterVMAsync(vm.AsVim()); string folder = vm.Path.Substring(0, vm.Path.LastIndexOf('/')); _logger.LogDebug($"Delete: deleting vm folder {folder}"); await _vim.DeleteDatastoreFile_TaskAsync(_sic.fileManager, folder, _datacenter); _vmCache.TryRemove(vm.Id, out vm); await _netman.Clean(tag); vm.Status = "initialized"; return(vm); }