2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-09-03 23:23:39 -04:00
|
|
|
|
|
|
|
"code.google.com/p/go.crypto/ssh"
|
2014-04-06 13:21:22 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2014-09-03 23:23:39 -04:00
|
|
|
commonssh "github.com/mitchellh/packer/common/ssh"
|
2014-04-06 13:21:22 -04:00
|
|
|
packerssh "github.com/mitchellh/packer/communicator/ssh"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SSHAddress(state multistep.StateBag) (string, error) {
|
|
|
|
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 fmt.Sprintf("%s:22", ip), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SSHConfigFunc(config SSHConfig) func(multistep.StateBag) (*ssh.ClientConfig, error) {
|
|
|
|
return func(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
|
|
|
auth := []ssh.AuthMethod{
|
|
|
|
ssh.Password(config.SSHPassword),
|
|
|
|
ssh.KeyboardInteractive(
|
|
|
|
packerssh.PasswordKeyboardInteractive(config.SSHPassword)),
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.SSHKeyPath != "" {
|
2014-09-03 23:23:39 -04:00
|
|
|
signer, err := commonssh.FileSigner(config.SSHKeyPath)
|
2014-04-06 13:21:22 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
auth = append(auth, ssh.PublicKeys(signer))
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ssh.ClientConfig{
|
|
|
|
User: config.SSHUser,
|
|
|
|
Auth: auth,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|