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

42 lines
1.0 KiB
Go

// 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"
"github.com/mitchellh/packer/powershell/hyperv"
)
type StepDisableVlan struct {
}
func (s *StepDisableVlan) Run(state multistep.StateBag) multistep.StepAction {
//config := state.Get("config").(*config)
//driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
errorMsg := "Error disabling vlan: %s"
vmName := state.Get("vmName").(string)
switchName := state.Get("SwitchName").(string)
ui.Say("Disabling vlan...")
err := hyperv.UntagVirtualMachineNetworkAdapterVlan(vmName, switchName)
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
}