2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2019-07-02 16:56:28 -04:00
|
|
|
"log"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// CommHost returns the VM's IP address which should be used to access it by SSH.
|
2019-07-02 16:56:28 -04:00
|
|
|
func CommHost(host string) func(multistep.StateBag) (string, error) {
|
|
|
|
return func(state multistep.StateBag) (string, error) {
|
|
|
|
if host != "" {
|
2020-01-30 18:22:22 -05:00
|
|
|
log.Printf("Using host value: %s", host)
|
2019-07-02 16:56:28 -04:00
|
|
|
return host, nil
|
|
|
|
}
|
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
driver := state.Get("driver").(Driver)
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2019-07-02 16:56:28 -04:00
|
|
|
mac, err := driver.MAC(vmName)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2019-07-02 16:56:28 -04:00
|
|
|
ip, err := driver.IPAddress(mac)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2014-04-06 13:21:22 -04:00
|
|
|
|
2019-07-02 16:56:28 -04:00
|
|
|
return ip, nil
|
|
|
|
}
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|