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"
|
2016-09-29 14:37:07 -04:00
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepConfigureVlan struct {
|
2016-09-29 14:37:07 -04:00
|
|
|
VlanId string
|
|
|
|
SwitchVlanId string
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepConfigureVlan) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2015-10-30 04:23:30 -04:00
|
|
|
driver := state.Get("driver").(Driver)
|
2015-06-21 07:36:07 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
errorMsg := "Error configuring vlan: %s"
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
switchName := state.Get("SwitchName").(string)
|
2016-09-29 14:37:07 -04:00
|
|
|
vlanId := s.VlanId
|
|
|
|
switchVlanId := s.SwitchVlanId
|
2015-06-21 07:36:07 -04:00
|
|
|
|
|
|
|
ui.Say("Configuring vlan...")
|
|
|
|
|
2016-09-29 14:37:07 -04:00
|
|
|
if switchVlanId != "" {
|
|
|
|
err := driver.SetNetworkAdapterVlanId(switchName, vlanId)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf(errorMsg, err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:37:07 -04:00
|
|
|
if vlanId != "" {
|
|
|
|
err := driver.SetVirtualMachineVlanId(vmName, vlanId)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf(errorMsg, err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepConfigureVlan) Cleanup(state multistep.StateBag) {
|
|
|
|
//do nothing
|
|
|
|
}
|