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

33 lines
564 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
if host != "" {
log.Println("Using ssh_host value: %s", ipAddress)
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
}
}