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