github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/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  type toolsPathTemplate struct {
    12  	Version string
    13  }
    14  
    15  // This step uploads the guest additions ISO to the VM.
    16  type StepUploadParallelsTools struct {
    17  	ParallelsToolsHostPath  string
    18  	ParallelsToolsGuestPath string
    19  	ParallelsToolsMode      string
    20  	Tpl                     *packer.ConfigTemplate
    21  }
    22  
    23  func (s *StepUploadParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
    24  	comm := state.Get("communicator").(packer.Communicator)
    25  	driver := state.Get("driver").(Driver)
    26  	ui := state.Get("ui").(packer.Ui)
    27  
    28  	// If we're attaching then don't do this, since we attached.
    29  	if s.ParallelsToolsMode != ParallelsToolsModeUpload {
    30  		log.Println("Not uploading Parallels Tools since mode is not upload")
    31  		return multistep.ActionContinue
    32  	}
    33  
    34  	version, err := driver.Version()
    35  	if err != nil {
    36  		state.Put("error", fmt.Errorf("Error reading version for Parallels Tools upload: %s", err))
    37  		return multistep.ActionHalt
    38  	}
    39  
    40  	f, err := os.Open(s.ParallelsToolsHostPath)
    41  	if err != nil {
    42  		state.Put("error", fmt.Errorf("Error opening Parallels Tools ISO: %s", err))
    43  		return multistep.ActionHalt
    44  	}
    45  
    46  	tplData := &toolsPathTemplate{
    47  		Version: version,
    48  	}
    49  
    50  	s.ParallelsToolsGuestPath, err = s.Tpl.Process(s.ParallelsToolsGuestPath, tplData)
    51  	if err != nil {
    52  		err := fmt.Errorf("Error preparing Parallels Tools path: %s", err)
    53  		state.Put("error", err)
    54  		ui.Error(err.Error())
    55  		return multistep.ActionHalt
    56  	}
    57  
    58  	ui.Say("Uploading Parallels Tools ISO...")
    59  	if err := comm.Upload(s.ParallelsToolsGuestPath, f); err != nil {
    60  		state.Put("error", fmt.Errorf("Error uploading Parallels Tools: %s", err))
    61  		return multistep.ActionHalt
    62  	}
    63  
    64  	return multistep.ActionContinue
    65  }
    66  
    67  func (s *StepUploadParallelsTools) Cleanup(state multistep.StateBag) {}