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

34 lines
635 B
Go
Raw Normal View History

package common
import (
"log"
2018-12-27 03:33:58 -05:00
"github.com/hashicorp/packer/helper/multistep"
)
2018-12-27 03:33:58 -05:00
func CommHost(host string) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
2018-12-27 03:33:58 -05:00
// Skip IP auto detection if the configuration has an ssh host configured.
if host != "" {
2018-12-27 04:15:44 -05:00
log.Printf("Using ssh_host value: %s", host)
return host, nil
}
2018-12-27 03:33:58 -05:00
vmName := state.Get("vmName").(string)
driver := state.Get("driver").(Driver)
mac, err := driver.Mac(vmName)
if err != nil {
return "", err
}
ip, err := driver.IpAddress(mac)
if err != nil {
return "", err
}
return ip, nil
}
}