github.phpd.cn/hashicorp/packer@v1.3.2/builder/parallels/common/step_prepare_parallels_tools.go (about)

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