Remove disk file after detaching from hyper-v guest

This commit is contained in:
Brian Cain 2020-04-14 14:01:39 -07:00
parent 318eb4e65a
commit 5405aaac82
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
3 changed files with 9 additions and 7 deletions

View File

@ -43,10 +43,7 @@ module VagrantPlugins
disk_actual = all_disks.select { |a| a["Path"] == d["path"] }.first
machine.provider.driver.remove_disk(disk_actual["ControllerType"], disk_actual["ControllerNumber"], disk_actual["ControllerLocation"])
# TODO: delete disk
# maybe we can just "dismount" instead of removing the disk all together
machine.provider.driver.remove_disk(disk_actual["ControllerType"], disk_actual["ControllerNumber"], disk_actual["ControllerLocation"], disk_actual["Path"])
end
end
end

View File

@ -56,9 +56,10 @@ module VagrantPlugins
# @param [String] controller_number
# @param [String] controller_location
# @param [Hash] opts
def remove_disk(controller_type, controller_number, controller_location, **opts)
def remove_disk(controller_type, controller_number, controller_location, disk_file_path, **opts)
execute(:remove_disk_drive, VmId: @vm_id, ControllerType: controller_type,
ControllerNumber: controller_number, ControllerLocation: controller_location)
ControllerNumber: controller_number, ControllerLocation: controller_location,
DiskFilePath: disk_file_path)
end
# @param [String] path

View File

@ -8,13 +8,17 @@ param(
[Parameter(Mandatory=$true)]
[string]$ControllerNumber,
[Parameter(Mandatory=$true)]
[string]$ControllerLocation
[string]$ControllerLocation,
[Parameter(Mandatory=$true)]
[string]$DiskFilePath
)
try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-v\Remove-VMHardDiskDrive -VMName $VM.Name -ControllerType $ControllerType -ControllerNumber $ControllerNumber -ControllerLocation $ControllerLocation
Remove-Item -Path $DiskFilePath
} catch {
Write-ErrorMessage "Failed to remove disk ${DiskFilePath} to VM ${VM}: ${PSItem}"
exit 1