packer-cn/post-processor/vsphere-template/step_choose_datacenter.go

36 lines
806 B
Go
Raw Normal View History

package vsphere_template
2017-07-09 14:56:39 -04:00
import (
"context"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/find"
)
2017-07-18 23:10:05 -04:00
type stepChooseDatacenter struct {
2017-07-09 14:56:39 -04:00
Datacenter string
}
2017-07-18 23:10:05 -04:00
func (s *stepChooseDatacenter) Run(state multistep.StateBag) multistep.StepAction {
2017-07-09 14:56:39 -04:00
ui := state.Get("ui").(packer.Ui)
cli := state.Get("client").(*govmomi.Client)
2017-07-09 14:56:39 -04:00
finder := find.NewFinder(cli.Client, false)
ui.Message("Choosing datacenter...")
dc, err := finder.DatacenterOrDefault(context.Background(), s.Datacenter)
2017-07-09 14:56:39 -04:00
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
2017-07-27 16:55:47 -04:00
state.Put("dcPath", dc.InventoryPath)
2017-07-09 14:56:39 -04:00
return multistep.ActionContinue
}
2017-07-18 23:10:05 -04:00
func (s *stepChooseDatacenter) Cleanup(multistep.StateBag) {}