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

     1  package common
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  	"github.com/hashicorp/packer/packer"
     9  )
    10  
    11  type StepUnmountFloppyDrive struct {
    12  	Generation uint
    13  }
    14  
    15  func (s *StepUnmountFloppyDrive) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    16  	driver := state.Get("driver").(Driver)
    17  	ui := state.Get("ui").(packer.Ui)
    18  
    19  	if s.Generation > 1 {
    20  		return multistep.ActionContinue
    21  	}
    22  
    23  	vmName := state.Get("vmName").(string)
    24  	ui.Say("Unmount/delete floppy drive (Run)...")
    25  
    26  	errorMsg := "Error Unmounting floppy drive: %s"
    27  
    28  	err := driver.UnmountFloppyDrive(vmName)
    29  	if err != nil {
    30  		err := fmt.Errorf(errorMsg, err)
    31  		state.Put("error", err)
    32  		ui.Error(err.Error())
    33  	}
    34  
    35  	return multistep.ActionContinue
    36  }
    37  
    38  func (s *StepUnmountFloppyDrive) Cleanup(state multistep.StateBag) {
    39  	// do nothing
    40  }