From 36bd2f5691b03674154d8db1de0db5cebfa11936 Mon Sep 17 00:00:00 2001 From: DanHam Date: Fri, 6 Jul 2018 01:45:40 +0100 Subject: [PATCH] Fix an error with an error. Add some comments. --- builder/hyperv/common/step_create_external_switch.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builder/hyperv/common/step_create_external_switch.go b/builder/hyperv/common/step_create_external_switch.go index 52626afce..483dc2c2c 100644 --- a/builder/hyperv/common/step_create_external_switch.go +++ b/builder/hyperv/common/step_create_external_switch.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/packer/packer" ) -// This step creates switch for VM. +// This step creates an external switch for the VM. // // Produces: // SwitchName string - The name of the Switch @@ -18,6 +18,9 @@ type StepCreateExternalSwitch struct { oldSwitchName string } +// Run runs the step required to create an external switch. Depending on +// the connectivity of the host machine, the external switch will allow the +// build VM to connect to the outside world. func (s *StepCreateExternalSwitch) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) @@ -30,10 +33,12 @@ func (s *StepCreateExternalSwitch) Run(_ context.Context, state multistep.StateB packerExternalSwitchName := "paes_" + uuid.TimeOrderedUUID() + // CreateExternalVirtualSwitch checks for an existing external switch, + // creating one if required, and connects the VM to it err = driver.CreateExternalVirtualSwitch(vmName, packerExternalSwitchName) if err != nil { - err := fmt.Errorf("Error creating switch: %s", err) - state.Put(errorMsg, err) + err := fmt.Errorf(errorMsg, err) + state.Put("error", err) ui.Error(err.Error()) s.SwitchName = "" return multistep.ActionHalt