2013-12-23 23:27:01 -07:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2013-12-24 11:00:51 -07:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2013-12-23 23:27:01 -07:00
|
|
|
|
2018-01-19 16:18:44 -08:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-12-23 23:27:01 -07:00
|
|
|
)
|
|
|
|
|
2015-06-13 19:23:33 -04:00
|
|
|
func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
|
2013-12-24 11:00:51 -07:00
|
|
|
return func(state multistep.StateBag) (string, error) {
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
|
2015-06-13 18:52:44 -04:00
|
|
|
if config.Comm.SSHHost != "" {
|
2015-06-13 19:23:33 -04:00
|
|
|
return config.Comm.SSHHost, nil
|
2014-03-28 15:22:37 -07:00
|
|
|
}
|
|
|
|
|
2015-11-11 06:39:06 -06:00
|
|
|
ipAddress, err := driver.GuestIP(state)
|
2013-12-24 11:00:51 -07:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("IP lookup failed: %s", err)
|
|
|
|
return "", fmt.Errorf("IP lookup failed: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ipAddress == "" {
|
|
|
|
log.Println("IP is blank, no IP yet.")
|
|
|
|
return "", errors.New("IP is blank")
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Detected IP: %s", ipAddress)
|
2015-06-13 19:23:33 -04:00
|
|
|
return ipAddress, nil
|
2013-12-24 11:00:51 -07:00
|
|
|
}
|
|
|
|
}
|