packer-cn/builder/hyperv/common/step_unmount_guest_addition...

58 lines
1.8 KiB
Go
Raw Normal View History

2015-10-30 15:47:14 -04:00
package common
import (
"context"
2015-10-30 15:47:14 -04:00
"fmt"
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
2015-10-30 15:47:14 -04:00
)
type StepUnmountGuestAdditions struct {
}
func (s *StepUnmountGuestAdditions) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2015-10-30 15:47:14 -04:00
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
ui := state.Get("ui").(packersdk.Ui)
2015-10-30 15:47:14 -04:00
ui.Say("Unmount/delete Integration Services dvd drive...")
dvdControllerState := state.Get("guest.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)
2016-11-06 11:02:00 -05:00
2015-10-30 15:47:14 -04:00
if dvdController.Existing {
2018-07-09 12:20:38 -04:00
ui.Say(fmt.Sprintf("Unmounting Integration Services 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 Integration Services 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 Integration Services 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 Integration Services 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("guest.dvd.properties", nil)
2016-11-06 11:02:00 -05:00
2015-10-30 15:47:14 -04:00
return multistep.ActionContinue
}
func (s *StepUnmountGuestAdditions) Cleanup(state multistep.StateBag) {
}