2020-01-27 10:49:31 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-02-14 11:42:29 -05:00
|
|
|
"log"
|
|
|
|
|
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"
|
2020-01-27 10:49:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2020-01-27 10:49:31 -05:00
|
|
|
|
|
|
|
// 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)
|
2020-05-19 05:49:48 -04:00
|
|
|
state.Put("http_ip", hostIP)
|
2020-01-27 10:49:31 -05:00
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*StepHTTPIPDiscover) Cleanup(multistep.StateBag) {}
|