Commit 2091dffe authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/googlecompute: cancel works

parent 6cd9ee3e
...@@ -40,12 +40,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -40,12 +40,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
log.Println("Failed to create the Google Compute Engine client.") log.Println("Failed to create the Google Compute Engine client.")
return nil, err return nil, err
} }
// Set up the state. // Set up the state.
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("config", b.config) state.Put("config", b.config)
state.Put("client", client) state.Put("client", client)
state.Put("hook", hook) state.Put("hook", hook)
state.Put("ui", ui) state.Put("ui", ui)
// Build the steps. // Build the steps.
steps := []multistep.Step{ steps := []multistep.Step{
new(stepCreateSSHKey), new(stepCreateSSHKey),
...@@ -62,6 +64,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -62,6 +64,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepUploadImage), new(stepUploadImage),
new(stepRegisterImage), new(stepRegisterImage),
} }
// Run the steps. // Run the steps.
if b.config.PackerDebug { if b.config.PackerDebug {
b.runner = &multistep.DebugRunner{ b.runner = &multistep.DebugRunner{
...@@ -72,6 +75,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -72,6 +75,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b.runner = &multistep.BasicRunner{Steps: steps} b.runner = &multistep.BasicRunner{Steps: steps}
} }
b.runner.Run(state) b.runner.Run(state)
// Report any errors. // Report any errors.
if rawErr, ok := state.GetOk("error"); ok { if rawErr, ok := state.GetOk("error"); ok {
return nil, rawErr.(error) return nil, rawErr.(error)
...@@ -80,6 +84,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -80,6 +84,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
log.Println("Failed to find image_name in state. Bug?") log.Println("Failed to find image_name in state. Bug?")
return nil, nil return nil, nil
} }
artifact := &Artifact{ artifact := &Artifact{
imageName: state.Get("image_name").(string), imageName: state.Get("image_name").(string),
client: client, client: client,
...@@ -88,4 +93,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -88,4 +93,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
} }
// Cancel. // Cancel.
func (b *Builder) Cancel() {} func (b *Builder) Cancel() {
if b.runner != nil {
log.Println("Cancelling the step runner...")
b.runner.Cancel()
}
}
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