github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/hyperv/common/step_unmount_dvddrive.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 StepUnmountDvdDrive struct { 10 } 11 12 func (s *StepUnmountDvdDrive) Run(state multistep.StateBag) multistep.StepAction { 13 driver := state.Get("driver").(Driver) 14 vmName := state.Get("vmName").(string) 15 ui := state.Get("ui").(packer.Ui) 16 17 ui.Say("Unmount/delete os dvd drive...") 18 19 dvdControllerState := state.Get("os.dvd.properties") 20 21 if dvdControllerState == nil { 22 return multistep.ActionContinue 23 } 24 25 dvdController := dvdControllerState.(DvdControllerProperties) 26 27 if dvdController.Existing { 28 ui.Say(fmt.Sprintf("Unmounting os dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 29 err := driver.UnmountDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 30 if err != nil { 31 err := fmt.Errorf("Error unmounting os dvd drive: %s", err) 32 state.Put("error", err) 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 } else { 37 ui.Say(fmt.Sprintf("Delete os dvd drives controller %d location %d ...", dvdController.ControllerNumber, dvdController.ControllerLocation)) 38 err := driver.DeleteDvdDrive(vmName, dvdController.ControllerNumber, dvdController.ControllerLocation) 39 if err != nil { 40 err := fmt.Errorf("Error deleting os dvd drive: %s", err) 41 state.Put("error", err) 42 ui.Error(err.Error()) 43 return multistep.ActionHalt 44 } 45 } 46 47 state.Put("os.dvd.properties", nil) 48 49 return multistep.ActionContinue 50 } 51 52 func (s *StepUnmountDvdDrive) Cleanup(state multistep.StateBag) { 53 }