github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/builder/parallels/common/step_remove_devices.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/multistep"
     6  	"github.com/mitchellh/packer/packer"
     7  )
     8  
     9  // This step removes any devices (floppy disks, ISOs, etc.) from the
    10  // machine that we may have added.
    11  //
    12  // Uses:
    13  //   driver Driver
    14  //   ui packer.Ui
    15  //   vmName string
    16  //
    17  // Produces:
    18  type StepRemoveDevices struct{}
    19  
    20  func (s *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
    21  	driver := state.Get("driver").(Driver)
    22  	ui := state.Get("ui").(packer.Ui)
    23  	vmName := state.Get("vmName").(string)
    24  
    25  	// Remove the attached floppy disk, if it exists
    26  	if _, ok := state.GetOk("floppy_path"); ok {
    27  		ui.Message("Removing floppy drive...")
    28  		command := []string{"set", vmName, "--device-del", "fdd0"}
    29  		if err := driver.Prlctl(command...); err != nil {
    30  			err := fmt.Errorf("Error removing floppy: %s", err)
    31  			state.Put("error", err)
    32  			ui.Error(err.Error())
    33  			return multistep.ActionHalt
    34  		}
    35  	}
    36  
    37  	if _, ok := state.GetOk("attachedIso"); ok {
    38  		command := []string{
    39  			"set", vmName,
    40  			"--device-set", "cdrom0",
    41  			"--device", "Default CD/DVD-ROM",
    42  		}
    43  
    44  		if err := driver.Prlctl(command...); err != nil {
    45  			err := fmt.Errorf("Error detaching ISO: %s", err)
    46  			state.Put("error", err)
    47  			ui.Error(err.Error())
    48  			return multistep.ActionHalt
    49  		}
    50  	}
    51  
    52  	if _, ok := state.GetOk("attachedToolsIso"); ok {
    53  		command := []string{"set", vmName, "--device-del", "cdrom1"}
    54  
    55  		if err := driver.Prlctl(command...); err != nil {
    56  			err := fmt.Errorf("Error detaching ISO: %s", err)
    57  			state.Put("error", err)
    58  			ui.Error(err.Error())
    59  			return multistep.ActionHalt
    60  		}
    61  	}
    62  
    63  	return multistep.ActionContinue
    64  }
    65  
    66  func (s *StepRemoveDevices) Cleanup(state multistep.StateBag) {
    67  }