2015-06-21 07:36:07 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2015-06-21 07:36:07 -04:00
|
|
|
"fmt"
|
2018-01-22 18:32:33 -05:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepDisableVlan struct {
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepDisableVlan) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-10-30 04:23:30 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2015-06-21 07:36:07 -04:00
|
|
|
|
|
|
|
errorMsg := "Error disabling vlan: %s"
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
switchName := state.Get("SwitchName").(string)
|
|
|
|
|
|
|
|
ui.Say("Disabling vlan...")
|
|
|
|
|
2015-10-30 04:23:30 -04:00
|
|
|
err := driver.UntagVirtualMachineNetworkAdapterVlan(vmName, switchName)
|
2015-06-21 07:36:07 -04:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf(errorMsg, err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepDisableVlan) Cleanup(state multistep.StateBag) {
|
|
|
|
//do nothing
|
|
|
|
}
|