2013-09-02 23:23:52 -04:00
|
|
|
package qemu
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-09-03 23:23:39 -04:00
|
|
|
|
2013-09-02 23:23:52 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2014-09-03 23:23:39 -04:00
|
|
|
commonssh "github.com/mitchellh/packer/common/ssh"
|
2013-09-02 23:23:52 -04:00
|
|
|
"github.com/mitchellh/packer/communicator/ssh"
|
2015-06-09 00:34:20 -04:00
|
|
|
gossh "golang.org/x/crypto/ssh"
|
2013-09-02 23:23:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func sshAddress(state multistep.StateBag) (string, error) {
|
|
|
|
sshHostPort := state.Get("sshHostPort").(uint)
|
|
|
|
return fmt.Sprintf("127.0.0.1:%d", sshHostPort), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
2015-05-27 16:39:43 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2013-09-02 23:23:52 -04:00
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
auth := []gossh.AuthMethod{
|
|
|
|
gossh.Password(config.SSHPassword),
|
|
|
|
gossh.KeyboardInteractive(
|
2013-09-02 23:23:52 -04:00
|
|
|
ssh.PasswordKeyboardInteractive(config.SSHPassword)),
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.SSHKeyPath != "" {
|
2014-09-03 23:23:39 -04:00
|
|
|
signer, err := commonssh.FileSigner(config.SSHKeyPath)
|
2013-09-02 23:23:52 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-04-10 04:48:55 -04:00
|
|
|
auth = append(auth, gossh.PublicKeys(signer))
|
2013-09-02 23:23:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return &gossh.ClientConfig{
|
|
|
|
User: config.SSHUser,
|
|
|
|
Auth: auth,
|
|
|
|
}, nil
|
|
|
|
}
|