packer-cn/builder/vmware/common/ssh.go

34 lines
693 B
Go
Raw Normal View History

2013-12-24 01:27:01 -05:00
package common
import (
"errors"
"fmt"
"log"
2013-12-24 01:27:01 -05:00
"github.com/hashicorp/packer/helper/multistep"
2013-12-24 01:27:01 -05:00
)
func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
driver := state.Get("driver").(Driver)
2015-06-13 18:52:44 -04:00
if config.Comm.SSHHost != "" {
return config.Comm.SSHHost, nil
}
ipAddress, err := driver.GuestIP(state)
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)
return ipAddress, nil
}
}