github.phpd.cn/hashicorp/packer@v1.3.2/builder/hyperv/common/step_enable_integration_service.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 StepEnableIntegrationService struct {
    12  	name string
    13  }
    14  
    15  func (s *StepEnableIntegrationService) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    16  	driver := state.Get("driver").(Driver)
    17  	ui := state.Get("ui").(packer.Ui)
    18  	ui.Say("Enabling Integration Service...")
    19  
    20  	vmName := state.Get("vmName").(string)
    21  	s.name = "Guest Service Interface"
    22  
    23  	err := driver.EnableVirtualMachineIntegrationService(vmName, s.name)
    24  
    25  	if err != nil {
    26  		err := fmt.Errorf("Error enabling Integration Service: %s", err)
    27  		state.Put("error", err)
    28  		ui.Error(err.Error())
    29  		return multistep.ActionHalt
    30  	}
    31  
    32  	return multistep.ActionContinue
    33  }
    34  
    35  func (s *StepEnableIntegrationService) Cleanup(state multistep.StateBag) {
    36  	// do nothing
    37  }