mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-26 09:44:01 -04:00
https://github.com/Microsoft/packer-hyperv/pull/21/commits/1ce6ba91f7308e1283d5d1dcc35ed43b95303ff7?diff=unified#diff-5d60887f0940c9f8d6724e59843ac1fb
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/mitchellh/multistep"
|
|
"github.com/mitchellh/packer/packer"
|
|
)
|
|
|
|
type StepUnmountDvdDrive struct {
|
|
}
|
|
|
|
func (s *StepUnmountDvdDrive) Run(state multistep.StateBag) multistep.StepAction {
|
|
driver := state.Get("driver").(Driver)
|
|
vmName := state.Get("vmName").(string)
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
ui.Say("Unmount/delete os dvd drive...")
|
|
|
|
dvdControllerState := state.Get("os.dvd.properties")
|
|
|
|
if dvdControllerState == nil {
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
dvdController := dvdControllerState.(DvdControllerProperties)
|
|
|
|
if dvdController.Existing {
|
|
ui.Say(fmt.Sprintf("Unmounting os dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
|
|
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
|
if err != nil {
|
|
err := fmt.Errorf("Error unmounting os dvd drive: %s", err)
|
|
state.Put("error", err)
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
} else {
|
|
ui.Say(fmt.Sprintf("Delete os dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
|
|
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
|
if err != nil {
|
|
err := fmt.Errorf("Error deleting os dvd drive: %s", err)
|
|
state.Put("error", err)
|
|
ui.Error(err.Error())
|
|
return multistep.ActionHalt
|
|
}
|
|
}
|
|
|
|
state.Put("os.dvd.properties", nil)
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepUnmountDvdDrive) Cleanup(state multistep.StateBag) {
|
|
}
|