2015-06-21 07:36:07 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-12-27 03:55:14 -05:00
|
|
|
"log"
|
2018-12-27 03:33:58 -05:00
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2015-06-21 07:36:07 -04:00
|
|
|
)
|
|
|
|
|
2018-12-27 03:33:58 -05:00
|
|
|
func CommHost(host string) func(multistep.StateBag) (string, error) {
|
2018-12-27 03:55:14 -05:00
|
|
|
return func(state multistep.StateBag) (string, error) {
|
2018-12-27 03:33:58 -05:00
|
|
|
|
2018-12-27 03:55:14 -05:00
|
|
|
if host != "" {
|
|
|
|
log.Println("Using ssh_host value: %s", ipAddress)
|
|
|
|
return host, nil
|
|
|
|
}
|
2018-12-27 03:33:58 -05:00
|
|
|
|
2018-12-27 03:55:14 -05:00
|
|
|
vmName := state.Get("vmName").(string)
|
|
|
|
driver := state.Get("driver").(Driver)
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2018-12-27 03:55:14 -05:00
|
|
|
mac, err := driver.Mac(vmName)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2018-12-27 03:55:14 -05:00
|
|
|
ip, err := driver.IpAddress(mac)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
|
2018-12-27 03:55:14 -05:00
|
|
|
return ip, nil
|
|
|
|
}
|
2015-06-21 07:36:07 -04:00
|
|
|
}
|