Commit d4c9ed43 authored by Prasanna Santhanam's avatar Prasanna Santhanam

Formatted googlecompute builder as per `make format`

parent 0e98b2a2
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
package googlecompute package googlecompute
import ( import (
"log" "fmt"
"time"
"fmt"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log"
"time"
) )
// The unique ID for this builder. // The unique ID for this builder.
...@@ -48,28 +48,28 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -48,28 +48,28 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("ui", ui) state.Put("ui", ui)
// Build the steps. // Build the steps.
steps := []multistep.Step{ steps := []multistep.Step{
&StepCreateSSHKey{ &StepCreateSSHKey{
Debug: b.config.PackerDebug, Debug: b.config.PackerDebug,
DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName), DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName),
}, },
&StepCreateInstance{ &StepCreateInstance{
Debug: b.config.PackerDebug, Debug: b.config.PackerDebug,
}, },
&StepInstanceInfo{ &StepInstanceInfo{
Debug: b.config.PackerDebug, Debug: b.config.PackerDebug,
}, },
&common.StepConnectSSH{ &common.StepConnectSSH{
SSHAddress: sshAddress, SSHAddress: sshAddress,
SSHConfig: sshConfig, SSHConfig: sshConfig,
SSHWaitTimeout: 5 * time.Minute, SSHWaitTimeout: 5 * time.Minute,
}, },
new(common.StepProvision), new(common.StepProvision),
new(StepUpdateGsutil), new(StepUpdateGsutil),
new(StepCreateImage), new(StepCreateImage),
new(StepUploadImage), new(StepUploadImage),
new(StepRegisterImage), new(StepRegisterImage),
} }
// Run the steps. // Run the steps.
if b.config.PackerDebug { if b.config.PackerDebug {
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
// StepCreateInstance represents a Packer build step that creates GCE instances. // StepCreateInstance represents a Packer build step that creates GCE instances.
type StepCreateInstance struct { type StepCreateInstance struct {
instanceName string instanceName string
Debug bool Debug bool
} }
// Run executes the Packer build step that creates a GCE instance. // Run executes the Packer build step that creates a GCE instance.
...@@ -57,11 +57,11 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction ...@@ -57,11 +57,11 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
ui.Message("Instance has been created!") ui.Message("Instance has been created!")
if s.Debug { if s.Debug {
if name != "" { if name != "" {
ui.Message(fmt.Sprintf("Instance: %s started in %s", name, config.Zone)) ui.Message(fmt.Sprintf("Instance: %s started in %s", name, config.Zone))
} }
} }
// Things succeeded, store the name so we can remove it later // Things succeeded, store the name so we can remove it later
state.Put("instance_name", name) state.Put("instance_name", name)
......
package googlecompute package googlecompute
import ( import (
"code.google.com/p/go.crypto/ssh"
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"os"
"fmt" "fmt"
"code.google.com/p/go.crypto/ssh"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"os"
) )
// StepCreateSSHKey represents a Packer build step that generates SSH key pairs. // StepCreateSSHKey represents a Packer build step that generates SSH key pairs.
type StepCreateSSHKey struct { type StepCreateSSHKey struct {
key int key int
Debug bool Debug bool
DebugKeyPath string DebugKeyPath string
} }
// Run executes the Packer build step that generates SSH key pairs. // Run executes the Packer build step that generates SSH key pairs.
...@@ -45,20 +45,20 @@ func (s *StepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction { ...@@ -45,20 +45,20 @@ func (s *StepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
state.Put("ssh_private_key", string(pem.EncodeToMemory(&priv_blk))) state.Put("ssh_private_key", string(pem.EncodeToMemory(&priv_blk)))
state.Put("ssh_public_key", string(ssh.MarshalAuthorizedKey(pub))) state.Put("ssh_public_key", string(ssh.MarshalAuthorizedKey(pub)))
if s.Debug { if s.Debug {
ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath)) ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.DebugKeyPath))
f, err := os.OpenFile(s.DebugKeyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) f, err := os.OpenFile(s.DebugKeyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil { if err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err)) state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
return multistep.ActionHalt return multistep.ActionHalt
} }
// Write out the key // Write out the key
pem.Encode(f, &priv_blk) pem.Encode(f, &priv_blk)
f.Close() f.Close()
} }
return multistep.ActionContinue return multistep.ActionContinue
} }
......
...@@ -11,8 +11,8 @@ import ( ...@@ -11,8 +11,8 @@ import (
// stepInstanceInfo represents a Packer build step that gathers GCE instance info. // stepInstanceInfo represents a Packer build step that gathers GCE instance info.
type StepInstanceInfo struct { type StepInstanceInfo struct {
info int info int
Debug bool Debug bool
} }
// Run executes the Packer build step that gathers GCE instance info. // Run executes the Packer build step that gathers GCE instance info.
...@@ -47,11 +47,11 @@ func (s *StepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction { ...@@ -47,11 +47,11 @@ func (s *StepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt return multistep.ActionHalt
} }
if s.Debug { if s.Debug {
if ip != "" { if ip != "" {
ui.Message(fmt.Sprintf("Public IP: %s", ip)) ui.Message(fmt.Sprintf("Public IP: %s", ip))
} }
} }
ui.Message(fmt.Sprintf("IP: %s", ip)) ui.Message(fmt.Sprintf("IP: %s", ip))
state.Put("instance_ip", ip) state.Put("instance_ip", ip)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment