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