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

34 lines
642 B
Go
Raw Normal View History

package common
import (
"log"
2018-12-27 03:33:58 -05:00
2020-11-17 19:31:03 -05:00
"github.com/hashicorp/packer/packer-plugin-sdk/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 != "" {
log.Printf("Using 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
}
}