github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/builder/parallels/common/step_upload_parallels_tools.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "log" 8 "os" 9 ) 10 11 // This step uploads the Parallels Tools ISO to the virtual machine. 12 // 13 // Uses: 14 // communicator packer.Communicator 15 // parallels_tools_path string 16 // ui packer.Ui 17 // 18 // Produces: 19 type toolsPathTemplate struct { 20 Flavor string 21 } 22 23 // This step uploads the guest additions ISO to the VM. 24 type StepUploadParallelsTools struct { 25 ParallelsToolsFlavor string 26 ParallelsToolsGuestPath string 27 ParallelsToolsMode string 28 Tpl *packer.ConfigTemplate 29 } 30 31 func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction { 32 comm := state.Get("communicator").(packer.Communicator) 33 ui := state.Get("ui").(packer.Ui) 34 35 // If we're attaching then don't do this, since we attached. 36 if s.ParallelsToolsMode != ParallelsToolsModeUpload { 37 log.Println("Not uploading Parallels Tools since mode is not upload") 38 return multistep.ActionContinue 39 } 40 41 // Get the Paralells Tools path on the host machine 42 parallelsToolsPath := state.Get("parallels_tools_path").(string) 43 44 f, err := os.Open(parallelsToolsPath) 45 if err != nil { 46 state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err)) 47 return multistep.ActionHalt 48 } 49 defer f.Close() 50 51 tplData := &toolsPathTemplate{ 52 Flavor: s.ParallelsToolsFlavor, 53 } 54 55 s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData) 56 if err != nil { 57 err := fmt.Errorf("Error preparing Parallels Tools path: %s", err) 58 state.Put("error", err) 59 ui.Error(err.Error()) 60 return multistep.ActionHalt 61 } 62 63 ui.Say(fmt.Sprintf("Uploading Parallels Tools for '%s' to path: '%s'", 64 s.ParallelsToolsFlavor, s.ParallelsToolsGuestPath)) 65 if err := comm.Upload(s.ParallelsToolsGuestPath, f, nil); err != nil { 66 err := fmt.Errorf("Error uploading Parallels Tools: %s", err) 67 state.Put("error", err) 68 ui.Error(err.Error()) 69 return multistep.ActionHalt 70 } 71 72 return multistep.ActionContinue 73 } 74 75 func (s *StepUploadParallelsTools) Cleanup(state multistep.StateBag) {}