From 5f2c12324c7df5b6aeef9cdad70d82852fd0355d Mon Sep 17 00:00:00 2001 From: Taliesin Sisson Date: Tue, 14 Jul 2015 07:51:03 +0100 Subject: [PATCH] No need to remove floppy controller for 2nd generation vms Don't want to be prompted for confirmation from powershell commandlets --- builder/hyperv/common/step_unmount_floppydrive.go | 6 +++++- builder/hyperv/iso/builder.go | 4 +++- powershell/hyperv/hyperv.go | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/builder/hyperv/common/step_unmount_floppydrive.go b/builder/hyperv/common/step_unmount_floppydrive.go index ae7813400..87d1fd4a3 100644 --- a/builder/hyperv/common/step_unmount_floppydrive.go +++ b/builder/hyperv/common/step_unmount_floppydrive.go @@ -11,14 +11,18 @@ import ( "github.com/mitchellh/packer/powershell/hyperv" ) - type StepUnmountFloppyDrive struct { + Generation uint } func (s *StepUnmountFloppyDrive) Run(state multistep.StateBag) multistep.StepAction { //driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) + if s.Generation > 1 { + return multistep.ActionContinue + } + errorMsg := "Error Unmounting floppy drive: %s" vmName := state.Get("vmName").(string) diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index edf39385c..e3556eb65 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -345,7 +345,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe // remove the integration services dvd drive // after we power down &hypervcommon.StepUnmountSecondaryDvdImages{}, - &hypervcommon.StepUnmountFloppyDrive{}, + &hypervcommon.StepUnmountFloppyDrive{ + Generation: b.config.Generation, + }, &hypervcommon.StepUnmountDvdDrive{}, &hypervcommon.StepExportVm{ diff --git a/powershell/hyperv/hyperv.go b/powershell/hyperv/hyperv.go index f1581b4d9..efd83c684 100644 --- a/powershell/hyperv/hyperv.go +++ b/powershell/hyperv/hyperv.go @@ -160,7 +160,7 @@ if (($vm.State -ne [Microsoft.HyperV.PowerShell.VMState]::Off) -and ($vm.State - Stop-VM -VM $vm -TurnOff -Force -Confirm:$false } -Remove-VM -Name $vmName -Force +Remove-VM -Name $vmName -Force -Confirm:$false ` var ps powershell.PowerShellCmd @@ -231,7 +231,7 @@ func DeleteVirtualSwitch(switchName string) error { param([string]$switchName) $switch = Get-VMSwitch -Name $switchName -ErrorAction SilentlyContinue if ($switch -ne $null) { - $switch | Remove-VMSwitch -Force + $switch | Remove-VMSwitch -Force -Confirm:$false } ` @@ -246,7 +246,7 @@ func StartVirtualMachine(vmName string) error { param([string]$vmName) $vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue if ($vm.State -eq [Microsoft.HyperV.PowerShell.VMState]::Off) { - Start-VM -Name $vmName + Start-VM -Name $vmName -Confirm:$false } ` @@ -259,7 +259,7 @@ func RestartVirtualMachine(vmName string) error { var script = ` param([string]$vmName) -Restart-VM $vmName -Force +Restart-VM $vmName -Force -Confirm:$false ` var ps powershell.PowerShellCmd