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