github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/hyperv/common/step_unmount_guest_additions.go (about) 1 package common 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 "github.com/hashicorp/packer/packer" 9 ) 10 11 type StepUnmountGuestAdditions struct { 12 } 13 14 func (s *StepUnmountGuestAdditions) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 15 driver := state.Get("driver").(Driver) 16 vmName := state.Get("vmName").(string) 17 ui := state.Get("ui").(packer.Ui) 18 19 ui.Say("Unmount/delete Integration Services dvd drive...") 20 21 dvdControllerState := state.Get("guest.dvd.properties") 22 23 if dvdControllerState == nil { 24 return multistep.ActionContinue 25 } 26 27 dvdController := dvdControllerState.(DvdControllerProperties) 28 29 if dvdController.Existing { 30 ui.Say(fmt.Sprintf("Unmounting Integration Services dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 31 err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 32 if err != nil { 33 err := fmt.Errorf("Error unmounting Integration Services dvd drive: %s", err) 34 state.Put("error", err) 35 ui.Error(err.Error()) 36 return multistep.ActionHalt 37 } 38 } else { 39 ui.Say(fmt.Sprintf("Delete Integration Services dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 40 err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 41 if err != nil { 42 err := fmt.Errorf("Error deleting Integration Services dvd drive: %s", err) 43 state.Put("error", err) 44 ui.Error(err.Error()) 45 return multistep.ActionHalt 46 } 47 } 48 49 state.Put("guest.dvd.properties", nil) 50 51 return multistep.ActionContinue 52 } 53 54 func (s *StepUnmountGuestAdditions) Cleanup(state multistep.StateBag) { 55 }