2015-06-21 07:36:07 -04:00
|
|
|
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
|
|
// All Rights Reserved.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
// See License.txt in the project root for license information.
|
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepConfigureVlan struct {
|
2016-09-21 14:31:06 -04:00
|
|
|
VlanID string
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepConfigureVlan) Run(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)
|
|
|
|
|
|
|
|
ui.Say("Configuring vlan...")
|
|
|
|
|
2016-09-21 14:31:06 -04:00
|
|
|
vlanId := s.VlanID
|
2015-10-30 04:23:30 -04:00
|
|
|
|
|
|
|
if vlanId == "" {
|
2016-09-21 14:31:06 -04:00
|
|
|
// If no vlan ID is specified, do not enable Virtual LAN Identification
|
|
|
|
return multistep.ActionContinue
|
2015-10-30 04:23:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err := driver.SetNetworkAdapterVlanId(switchName, vlanId)
|
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
|
|
|
|
}
|
|
|
|
|
2015-10-30 04:23:30 -04:00
|
|
|
err = driver.SetVirtualMachineVlanId(vmName, vlanId)
|
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 *StepConfigureVlan) Cleanup(state multistep.StateBag) {
|
|
|
|
//do nothing
|
|
|
|
}
|