From 502076c92e6f9abb15e77d6170cfa86105b0b495 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 13 Jun 2015 18:30:16 -0400 Subject: [PATCH] builder/googlecompute: use helper/comm --- builder/googlecompute/builder.go | 9 ++++--- builder/googlecompute/config.go | 26 +++---------------- builder/googlecompute/ssh.go | 4 +-- builder/googlecompute/step_create_instance.go | 2 +- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index 8e35598d2..3ed576b50 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -8,6 +8,7 @@ import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/common" + "github.com/mitchellh/packer/helper/communicator" "github.com/mitchellh/packer/packer" ) @@ -60,10 +61,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &StepInstanceInfo{ Debug: b.config.PackerDebug, }, - &common.StepConnectSSH{ - SSHAddress: sshAddress, - SSHConfig: sshConfig, - SSHWaitTimeout: b.config.sshTimeout, + &communicator.StepConnect{ + Config: &b.config.Comm, + SSHAddress: sshAddress, + SSHConfig: sshConfig, }, new(common.StepProvision), new(StepTeardownInstance), diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 69d223a75..7f59aa183 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -7,6 +7,7 @@ import ( "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common/uuid" + "github.com/mitchellh/packer/helper/communicator" "github.com/mitchellh/packer/helper/config" "github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate" @@ -17,6 +18,7 @@ import ( // state of the config object. type Config struct { common.PackerConfig `mapstructure:",squash"` + Comm communicator.Config `mapstructure:",squash"` AccountFile string `mapstructure:"account_file"` ProjectId string `mapstructure:"project_id"` @@ -31,16 +33,12 @@ type Config struct { Network string `mapstructure:"network"` SourceImage string `mapstructure:"source_image"` SourceImageProjectId string `mapstructure:"source_image_project_id"` - SSHUsername string `mapstructure:"ssh_username"` - SSHPort uint `mapstructure:"ssh_port"` - RawSSHTimeout string `mapstructure:"ssh_timeout"` RawStateTimeout string `mapstructure:"state_timeout"` Tags []string `mapstructure:"tags"` Zone string `mapstructure:"zone"` account accountFile privateKeyBytes []byte - sshTimeout time.Duration stateTimeout time.Duration ctx *interpolate.Context } @@ -88,20 +86,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.MachineType = "n1-standard-1" } - if c.RawSSHTimeout == "" { - c.RawSSHTimeout = "5m" - } - if c.RawStateTimeout == "" { c.RawStateTimeout = "5m" } - if c.SSHUsername == "" { - c.SSHUsername = "root" - } - - if c.SSHPort == 0 { - c.SSHPort = 22 + if c.Comm.SSHUsername == "" { + c.Comm.SSHUsername = "root" } var errs *packer.MultiError @@ -122,14 +112,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs, errors.New("a zone must be specified")) } - // Process timeout settings. - sshTimeout, err := time.ParseDuration(c.RawSSHTimeout) - if err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Failed parsing ssh_timeout: %s", err)) - } - c.sshTimeout = sshTimeout - stateTimeout, err := time.ParseDuration(c.RawStateTimeout) if err != nil { errs = packer.MultiErrorAppend( diff --git a/builder/googlecompute/ssh.go b/builder/googlecompute/ssh.go index e04029e44..446648884 100644 --- a/builder/googlecompute/ssh.go +++ b/builder/googlecompute/ssh.go @@ -10,7 +10,7 @@ import ( func sshAddress(state multistep.StateBag) (string, error) { config := state.Get("config").(*Config) ipAddress := state.Get("instance_ip").(string) - return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil + return fmt.Sprintf("%s:%d", ipAddress, config.Comm.SSHPort), nil } // sshConfig returns the ssh configuration. @@ -24,7 +24,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) { } return &ssh.ClientConfig{ - User: config.SSHUsername, + User: config.Comm.SSHUsername, Auth: []ssh.AuthMethod{ ssh.PublicKeys(signer), }, diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index 6bfee5460..939925c58 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -32,7 +32,7 @@ func (config *Config) getInstanceMetadata(sshPublicKey string) map[string]string // Merge any existing ssh keys with our public key sshMetaKey := "sshKeys" - sshKeys := fmt.Sprintf("%s:%s", config.SSHUsername, sshPublicKey) + sshKeys := fmt.Sprintf("%s:%s", config.Comm.SSHUsername, sshPublicKey) if confSshKeys, exists := instanceMetadata[sshMetaKey]; exists { sshKeys = fmt.Sprintf("%s\n%s", sshKeys, confSshKeys) }