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 04:34:08 -05:00
|
|
|
// Skip IP auto detection if the configuration has an ssh host configured.
|
2018-12-27 03:55:14 -05:00
|
|
|
if host != "" {
|
2020-01-30 18:22:22 -05:00
|
|
|
log.Printf("Using host value: %s", host)
|
2018-12-27 03:55:14 -05:00
|
|
|
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
|
|
|
}
|