2015-10-30 15:47:14 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2015-10-30 15:47:14 -04:00
|
|
|
"fmt"
|
2018-01-22 18:32:33 -05:00
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-10-30 15:47:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepUnmountSecondaryDvdImages struct {
|
|
|
|
}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *StepUnmountSecondaryDvdImages) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-10-30 15:47:14 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
ui.Say("Unmount/delete secondary dvd drives...")
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
dvdControllersState := state.Get("secondary.dvd.properties")
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
if dvdControllersState == nil {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
dvdControllers := dvdControllersState.([]DvdControllerProperties)
|
2015-10-30 15:47:14 -04:00
|
|
|
|
|
|
|
for _, dvdController := range dvdControllers {
|
|
|
|
if dvdController.Existing {
|
2015-11-01 11:00:56 -05:00
|
|
|
ui.Say(fmt.Sprintf("Unmounting secondary dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
|
|
|
|
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
2015-10-30 15:47:14 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error unmounting secondary dvd drive: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
} else {
|
2015-11-01 11:00:56 -05:00
|
|
|
ui.Say(fmt.Sprintf("Delete secondary dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation))
|
2015-10-30 15:47:14 -04:00
|
|
|
err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error deleting secondary dvd drive: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2016-11-06 11:02:00 -05:00
|
|
|
}
|
2015-10-30 15:47:14 -04:00
|
|
|
}
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
state.Put("secondary.dvd.properties", nil)
|
2015-10-30 15:47:14 -04:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUnmountSecondaryDvdImages) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|