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