github.phpd.cn/hashicorp/packer@v1.3.2/builder/hyperv/common/step_disable_vlan.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 StepDisableVlan struct {
    12  }
    13  
    14  func (s *StepDisableVlan) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    15  	driver := state.Get("driver").(Driver)
    16  	ui := state.Get("ui").(packer.Ui)
    17  
    18  	errorMsg := "Error disabling vlan: %s"
    19  	vmName := state.Get("vmName").(string)
    20  	switchName := state.Get("SwitchName").(string)
    21  
    22  	ui.Say("Disabling vlan...")
    23  
    24  	err := driver.UntagVirtualMachineNetworkAdapterVlan(vmName, switchName)
    25  	if err != nil {
    26  		err := fmt.Errorf(errorMsg, 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 *StepDisableVlan) Cleanup(state multistep.StateBag) {
    36  	//do nothing
    37  }