github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/virtualbox/step_attach_iso.go (about) 1 package virtualbox 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 ) 8 9 // This step attaches the ISO to the virtual machine. 10 // 11 // Uses: 12 // 13 // Produces: 14 type stepAttachISO struct { 15 diskPath string 16 } 17 18 func (s *stepAttachISO) Run(state map[string]interface{}) multistep.StepAction { 19 driver := state["driver"].(Driver) 20 isoPath := state["iso_path"].(string) 21 ui := state["ui"].(packer.Ui) 22 vmName := state["vmName"].(string) 23 24 // Attach the disk to the controller 25 command := []string{ 26 "storageattach", vmName, 27 "--storagectl", "IDE Controller", 28 "--port", "0", 29 "--device", "1", 30 "--type", "dvddrive", 31 "--medium", isoPath, 32 } 33 if err := driver.VBoxManage(command...); err != nil { 34 err := fmt.Errorf("Error attaching ISO: %s", err) 35 state["error"] = err 36 ui.Error(err.Error()) 37 return multistep.ActionHalt 38 } 39 40 // Track the path so that we can unregister it from VirtualBox later 41 s.diskPath = isoPath 42 43 return multistep.ActionContinue 44 } 45 46 func (s *stepAttachISO) Cleanup(state map[string]interface{}) { 47 if s.diskPath == "" { 48 return 49 } 50 51 driver := state["driver"].(Driver) 52 ui := state["ui"].(packer.Ui) 53 vmName := state["vmName"].(string) 54 55 command := []string{ 56 "storageattach", vmName, 57 "--storagectl", "IDE Controller", 58 "--port", "0", 59 "--device", "1", 60 "--medium", "none", 61 } 62 63 if err := driver.VBoxManage(command...); err != nil { 64 ui.Error(fmt.Sprintf("Error unregistering ISO: %s", err)) 65 } 66 }