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

     1  package iso
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
     8  	"github.com/hashicorp/packer/helper/multistep"
     9  	"github.com/hashicorp/packer/packer"
    10  )
    11  
    12  // This step sets the device boot order for the virtual machine.
    13  //
    14  // Uses:
    15  //   driver Driver
    16  //   ui packer.Ui
    17  //   vmName string
    18  //
    19  // Produces:
    20  type stepSetBootOrder struct{}
    21  
    22  func (s *stepSetBootOrder) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    23  	driver := state.Get("driver").(parallelscommon.Driver)
    24  	ui := state.Get("ui").(packer.Ui)
    25  	vmName := state.Get("vmName").(string)
    26  
    27  	// Set new boot order
    28  	ui.Say("Setting the boot order...")
    29  	command := []string{
    30  		"set", vmName,
    31  		"--device-bootorder", fmt.Sprintf("hdd0 cdrom0 net0"),
    32  	}
    33  
    34  	if err := driver.Prlctl(command...); err != nil {
    35  		err := fmt.Errorf("Error setting the boot order: %s", err)
    36  		state.Put("error", err)
    37  		ui.Error(err.Error())
    38  		return multistep.ActionHalt
    39  	}
    40  
    41  	return multistep.ActionContinue
    42  }
    43  
    44  func (s *stepSetBootOrder) Cleanup(state multistep.StateBag) {}