packer-cn/builder/hyperv/common/step_unmount_dvddrive.go

54 lines
1.6 KiB
Go
Raw Normal View History

package common
import (
"fmt"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
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...")
2016-11-06 11:02:00 -05:00
dvdControllerState := state.Get("os.dvd.properties")
2016-11-06 11:02:00 -05:00
if dvdControllerState == nil {
return multistep.ActionContinue
}
2016-11-06 11:02:00 -05:00
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
}
}
2016-11-06 11:02:00 -05:00
state.Put("os.dvd.properties", nil)
2016-11-06 11:02:00 -05:00
return multistep.ActionContinue
}
func (s *StepUnmountDvdDrive) Cleanup(state multistep.StateBag) {
}