github.phpd.cn/hashicorp/packer@v1.3.2/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 ...", 31 dvdController.ControllerNumber, dvdController.ControllerLocation)) 32 err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 33 if err != nil { 34 err := fmt.Errorf("Error unmounting Integration Services dvd drive: %s", err) 35 state.Put("error", err) 36 ui.Error(err.Error()) 37 return multistep.ActionHalt 38 } 39 } else { 40 ui.Say(fmt.Sprintf("Delete Integration Services dvd drives controller %d location %d ...", 41 dvdController.ControllerNumber, dvdController.ControllerLocation)) 42 err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 43 if err != nil { 44 err := fmt.Errorf("Error deleting Integration Services dvd drive: %s", err) 45 state.Put("error", err) 46 ui.Error(err.Error()) 47 return multistep.ActionHalt 48 } 49 } 50 51 state.Put("guest.dvd.properties", nil) 52 53 return multistep.ActionContinue 54 } 55 56 func (s *StepUnmountGuestAdditions) Cleanup(state multistep.StateBag) { 57 }