packer-cn/builder/hyperv/common/step_configure_vlan.go

56 lines
1.3 KiB
Go
Raw Normal View History

// 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
}
func (s *StepConfigureVlan) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
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
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
}
err := driver.SetNetworkAdapterVlanId(switchName, vlanId)
if err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
err = driver.SetVirtualMachineVlanId(vmName, vlanId)
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
}