github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/builder/parallels/common/step_attach_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  )
     9  
    10  // This step attaches the Parallels Tools as a inserted CD onto
    11  // the virtual machine.
    12  //
    13  // Uses:
    14  //   driver Driver
    15  //   toolsPath string
    16  //   ui packer.Ui
    17  //   vmName string
    18  //
    19  // Produces:
    20  type StepAttachParallelsTools struct {
    21  	ParallelsToolsHostPath string
    22  	ParallelsToolsMode     string
    23  }
    24  
    25  func (s *StepAttachParallelsTools) Run(state multistep.StateBag) multistep.StepAction {
    26  	driver := state.Get("driver").(Driver)
    27  	ui := state.Get("ui").(packer.Ui)
    28  	vmName := state.Get("vmName").(string)
    29  
    30  	// If we're not attaching the guest additions then just return
    31  	if s.ParallelsToolsMode != ParallelsToolsModeAttach {
    32  		log.Println("Not attaching parallels tools since we're uploading.")
    33  		return multistep.ActionContinue
    34  	}
    35  
    36  	// Attach the guest additions to the computer
    37  	log.Println("Attaching Parallels Tools ISO onto IDE controller...")
    38  	command := []string{
    39  		"set", vmName,
    40  		"--device-add", "cdrom",
    41  		"--image", s.ParallelsToolsHostPath,
    42  	}
    43  	if err := driver.Prlctl(command...); err != nil {
    44  		err := fmt.Errorf("Error attaching Parallels Tools: %s", err)
    45  		state.Put("error", err)
    46  		ui.Error(err.Error())
    47  		return multistep.ActionHalt
    48  	}
    49  
    50  	// Set some state so we know to remove
    51  	state.Put("attachedToolsIso", true)
    52  
    53  	return multistep.ActionContinue
    54  }
    55  
    56  func (s *StepAttachParallelsTools) Cleanup(state multistep.StateBag) {}