2013-12-08 17:37:36 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
gossh "code.google.com/p/go.crypto/ssh"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/communicator/ssh"
|
|
|
|
)
|
|
|
|
|
|
|
|
// sshAddress returns the ssh address.
|
|
|
|
func sshAddress(state multistep.StateBag) (string, error) {
|
2013-12-12 19:41:44 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2013-12-08 17:37:36 -05:00
|
|
|
ipAddress := state.Get("instance_ip").(string)
|
|
|
|
return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// sshConfig returns the ssh configuration.
|
|
|
|
func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
2013-12-12 19:41:44 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2013-12-08 17:37:36 -05:00
|
|
|
privateKey := state.Get("ssh_private_key").(string)
|
|
|
|
|
|
|
|
keyring := new(ssh.SimpleKeychain)
|
|
|
|
if err := keyring.AddPEMKey(privateKey); err != nil {
|
|
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
|
|
}
|
2013-12-13 21:06:49 -05:00
|
|
|
|
2013-12-08 17:37:36 -05:00
|
|
|
sshConfig := &gossh.ClientConfig{
|
|
|
|
User: config.SSHUsername,
|
|
|
|
Auth: []gossh.ClientAuth{gossh.ClientAuthKeyring(keyring)},
|
|
|
|
}
|
2013-12-13 21:06:49 -05:00
|
|
|
|
2013-12-08 17:37:36 -05:00
|
|
|
return sshConfig, nil
|
|
|
|
}
|