packer-cn/builder/qemu/ssh.go

43 lines
1.0 KiB
Go
Raw Normal View History

package qemu
import (
2017-04-04 16:39:01 -04:00
commonssh "github.com/hashicorp/packer/common/ssh"
"github.com/hashicorp/packer/communicator/ssh"
"github.com/hashicorp/packer/helper/multistep"
2015-06-09 00:34:20 -04:00
gossh "golang.org/x/crypto/ssh"
)
func commHost(state multistep.StateBag) (string, error) {
return "127.0.0.1", nil
}
func commPort(state multistep.StateBag) (int, error) {
sshHostPort := state.Get("sshHostPort").(uint)
return int(sshHostPort), nil
}
func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
2015-05-27 16:39:43 -04:00
config := state.Get("config").(*Config)
auth := []gossh.AuthMethod{
2015-06-13 18:47:59 -04:00
gossh.Password(config.Comm.SSHPassword),
gossh.KeyboardInteractive(
2015-06-13 18:47:59 -04:00
ssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
}
2015-06-13 18:47:59 -04:00
if config.Comm.SSHPrivateKey != "" {
signer, err := commonssh.FileSigner(config.Comm.SSHPrivateKey)
if err != nil {
return nil, err
}
auth = append(auth, gossh.PublicKeys(signer))
}
return &gossh.ClientConfig{
User: config.Comm.SSHUsername,
Auth: auth,
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
}, nil
}