github.com/rothwerx/packer@v0.9.0/builder/parallels/common/step_prepare_parallels_tools.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/multistep"
     6  	"os"
     7  )
     8  
     9  // This step prepares parameters related to Parallels Tools.
    10  //
    11  // Uses:
    12  //   driver Driver
    13  //
    14  // Produces:
    15  //   parallels_tools_path string
    16  type StepPrepareParallelsTools struct {
    17  	ParallelsToolsFlavor string
    18  	ParallelsToolsMode   string
    19  }
    20  
    21  func (s *StepPrepareParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
    22  	driver := state.Get("driver").(Driver)
    23  
    24  	if s.ParallelsToolsMode == ParallelsToolsModeDisable {
    25  		return multistep.ActionContinue
    26  	}
    27  
    28  	path, err := driver.ToolsIsoPath(s.ParallelsToolsFlavor)
    29  
    30  	if err != nil {
    31  		state.Put("error", err)
    32  		return multistep.ActionHalt
    33  	}
    34  
    35  	if _, err := os.Stat(path); err != nil {
    36  		state.Put("error", fmt.Errorf(
    37  			"Couldn't find Parallels Tools for the '%s' flavor! Please, check the\n"+
    38  				"value of 'parallels_tools_flavor'. Valid flavors are: 'win', 'lin',\n"+
    39  				"'mac', 'os2' and 'other'", s.ParallelsToolsFlavor))
    40  		return multistep.ActionHalt
    41  	}
    42  
    43  	state.Put("parallels_tools_path", path)
    44  	return multistep.ActionContinue
    45  }
    46  
    47  func (s *StepPrepareParallelsTools) Cleanup(multistep.StateBag) {}