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"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/vmware/govmomi"
|
|
|
|
"github.com/vmware/govmomi/find"
|
|
|
|
)
|
|
|
|
|
2017-07-09 20:33:03 -04:00
|
|
|
type StepChooseDatacenter struct {
|
2017-07-09 14:56:39 -04:00
|
|
|
Datacenter string
|
|
|
|
}
|
|
|
|
|
2017-07-09 20:33:03 -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)
|
2017-07-09 15:58:42 -04:00
|
|
|
cli := state.Get("client").(*govmomi.Client)
|
|
|
|
ctx := state.Get("context").(context.Context)
|
2017-07-09 14:56:39 -04:00
|
|
|
finder := find.NewFinder(cli.Client, false)
|
|
|
|
|
2017-07-09 15:58:42 -04:00
|
|
|
datacenter, err := finder.DatacenterOrDefault(ctx, s.Datacenter)
|
2017-07-09 14:56:39 -04:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
finder.SetDatacenter(datacenter)
|
|
|
|
state.Put("datacenter", datacenter.Name())
|
|
|
|
state.Put("finder", finder)
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2017-07-09 20:33:03 -04:00
|
|
|
func (s *StepChooseDatacenter) Cleanup(multistep.StateBag) {}
|