github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/hyperv/common/ssh.go (about) 1 package common 2 3 import ( 4 commonssh "github.com/hashicorp/packer/common/ssh" 5 "github.com/hashicorp/packer/communicator/ssh" 6 "github.com/hashicorp/packer/helper/multistep" 7 gossh "golang.org/x/crypto/ssh" 8 ) 9 10 func CommHost(state multistep.StateBag) (string, error) { 11 vmName := state.Get("vmName").(string) 12 driver := state.Get("driver").(Driver) 13 14 mac, err := driver.Mac(vmName) 15 if err != nil { 16 return "", err 17 } 18 19 ip, err := driver.IpAddress(mac) 20 if err != nil { 21 return "", err 22 } 23 24 return ip, nil 25 } 26 27 func SSHConfigFunc(config *SSHConfig) func(multistep.StateBag) (*gossh.ClientConfig, error) { 28 return func(state multistep.StateBag) (*gossh.ClientConfig, error) { 29 auth := []gossh.AuthMethod{ 30 gossh.Password(config.Comm.SSHPassword), 31 gossh.KeyboardInteractive( 32 ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)), 33 } 34 35 if config.Comm.SSHPrivateKey != "" { 36 signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey) 37 if err != nil { 38 return nil, err 39 } 40 41 auth = append(auth, gossh.PublicKeys(signer)) 42 } 43 44 return &gossh.ClientConfig{ 45 User: config.Comm.SSHUsername, 46 Auth: auth, 47 HostKeyCallback: gossh.InsecureIgnoreHostKey(), 48 }, nil 49 } 50 }