github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/parallels/common/step_prepare_parallels_tools.go (about)

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