github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/hyperv/common/step_unmount_secondary_dvd_images.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 StepUnmountSecondaryDvdImages struct { 12 } 13 14 func (s *StepUnmountSecondaryDvdImages) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 15 driver := state.Get("driver").(Driver) 16 ui := state.Get("ui").(packer.Ui) 17 vmName := state.Get("vmName").(string) 18 19 ui.Say("Unmount/delete secondary dvd drives...") 20 21 dvdControllersState := state.Get("secondary.dvd.properties") 22 23 if dvdControllersState == nil { 24 return multistep.ActionContinue 25 } 26 27 dvdControllers := dvdControllersState.([]DvdControllerProperties) 28 29 for _, dvdController := range dvdControllers { 30 if dvdController.Existing { 31 ui.Say(fmt.Sprintf("Unmounting secondary dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 32 err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 33 if err != nil { 34 err := fmt.Errorf("Error unmounting secondary 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 secondary dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 41 err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 42 if err != nil { 43 err := fmt.Errorf("Error deleting secondary dvd drive: %s", err) 44 state.Put("error", err) 45 ui.Error(err.Error()) 46 return multistep.ActionHalt 47 } 48 } 49 } 50 51 state.Put("secondary.dvd.properties", nil) 52 53 return multistep.ActionContinue 54 } 55 56 func (s *StepUnmountSecondaryDvdImages) Cleanup(state multistep.StateBag) { 57 }