2020-01-27 10:49:31 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-02-14 11:42:29 -05:00
|
|
|
"log"
|
|
|
|
|
2020-01-27 10:49:31 -05:00
|
|
|
"github.com/hashicorp/packer/common"
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Step to discover the http ip
|
|
|
|
// which guests use to reach the vm host
|
|
|
|
// To make sure the IP is set before boot command and http server steps
|
|
|
|
type StepHTTPIPDiscover struct{}
|
|
|
|
|
|
|
|
func (s *StepHTTPIPDiscover) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
// Determine the host IP
|
|
|
|
hostIP, err := driver.HostIP(state)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error detecting host IP: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Host IP for the VMware machine: %s", hostIP)
|
|
|
|
common.SetHTTPIP(hostIP)
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*StepHTTPIPDiscover) Cleanup(multistep.StateBag) {}
|