2015-06-21 07:36:07 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2015-06-21 07:36:07 -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-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepUnmountDvdDrive struct {
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepUnmountDvdDrive) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-10-30 04:23:30 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
2015-06-21 07:36:07 -04:00
|
|
|
vmName := state.Get("vmName").(string)
|
2015-10-30 13:19:25 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2015-10-30 04:23:30 -04:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
ui.Say("Unmount/delete os dvd drive...")
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
dvdControllerState := state.Get("os.dvd.properties")
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
if dvdControllerState == nil {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
2016-11-06 11:02:00 -05:00
|
|
|
|
|
|
|
dvdController := dvdControllerState.(DvdControllerProperties)
|
|
|
|
|
2015-10-30 13:19:25 -04:00
|
|
|
if dvdController.Existing {
|
2018-07-09 12:20:38 -04:00
|
|
|
ui.Say(fmt.Sprintf("Unmounting os dvd drives controller %d location %d ...",
|
|
|
|
dvdController.ControllerNumber, dvdController.ControllerLocation))
|
2015-11-01 11:00:56 -05:00
|
|
|
err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation)
|
2015-10-30 13:19:25 -04:00
|
|
|
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 {
|
2018-07-09 12:20:38 -04:00
|
|
|
ui.Say(fmt.Sprintf("Delete os dvd drives controller %d location %d ...",
|
|
|
|
dvdController.ControllerNumber, dvdController.ControllerLocation))
|
2015-10-30 13:19:25 -04:00
|
|
|
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
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-11-01 11:00:56 -05:00
|
|
|
state.Put("os.dvd.properties", nil)
|
2016-11-06 11:02:00 -05:00
|
|
|
|
2015-06-21 07:36:07 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUnmountDvdDrive) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|