2017-07-10 20:52:48 -04:00
|
|
|
package vsphere_template
|
2017-07-09 15:58:42 -04:00
|
|
|
|
2017-07-09 14:56:39 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2017-07-09 14:56:39 -04:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepChooseDatacenter) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2017-07-09 15:58:42 -04:00
|
|
|
cli := state.Get("client").(*govmomi.Client)
|
2017-07-09 14:56:39 -04:00
|
|
|
finder := find.NewFinder(cli.Client, false)
|
|
|
|
|
2017-08-14 22:00:19 -04:00
|
|
|
ui.Message("Choosing datacenter...")
|
|
|
|
|
2017-07-19 00:44:18 -04:00
|
|
|
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-08-14 22:00:19 -04:00
|
|
|
|
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) {}
|