packer-cn/post-processor/vsphere-template/step_choose_datacenter.go
Matthew Hooker a831d522be
change run signatures
Run now takes a context as well as a statebag. We'll assign the context
to the blank identifier to prevent namespace collisions. We'll let the
step authors opt-in to using the context.

`find . -iname "step_*.go" -exec gsed -i'' 's/func \(.*\)Run(/func \1Run(_ context.Context, /' {} \;`
2018-01-24 17:09:17 -08:00

36 lines
839 B
Go

package vsphere_template
import (
"context"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
)
type stepChooseDatacenter struct {
Datacenter string
}
func (s *stepChooseDatacenter) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
cli := state.Get("client").(*govmomi.Client)
finder := find.NewFinder(cli.Client, false)
ui.Message("Choosing datacenter...")
dc, err := finder.DatacenterOrDefault(context.Background(), s.Datacenter)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("dcPath", dc.InventoryPath)
return multistep.ActionContinue
}
func (s *stepChooseDatacenter) Cleanup(multistep.StateBag) {}