github.com/Hashicorp/packer@v1.3.2/builder/hyperv/common/step_configure_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 StepConfigureVlan struct { 12 VlanId string 13 SwitchVlanId string 14 } 15 16 func (s *StepConfigureVlan) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { 17 driver := state.Get("driver").(Driver) 18 ui := state.Get("ui").(packer.Ui) 19 20 errorMsg := "Error configuring vlan: %s" 21 vmName := state.Get("vmName").(string) 22 switchName := state.Get("SwitchName").(string) 23 vlanId := s.VlanId 24 switchVlanId := s.SwitchVlanId 25 26 ui.Say("Configuring vlan...") 27 28 if switchVlanId != "" { 29 err := driver.SetNetworkAdapterVlanId(switchName, vlanId) 30 if err != nil { 31 err := fmt.Errorf(errorMsg, err) 32 state.Put("error", err) 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 } 37 38 if vlanId != "" { 39 err := driver.SetVirtualMachineVlanId(vmName, vlanId) 40 if err != nil { 41 err := fmt.Errorf(errorMsg, err) 42 state.Put("error", err) 43 ui.Error(err.Error()) 44 return multistep.ActionHalt 45 } 46 } 47 48 return multistep.ActionContinue 49 } 50 51 func (s *StepConfigureVlan) Cleanup(state multistep.StateBag) { 52 //do nothing 53 }