Merge pull request #8176 from winklerm/issue5575
Fix Issue 5575 - OpenStack builder should warn instead of fail on terminate if instance is already shut down
This commit is contained in:
commit
f685931cde
|
@ -92,16 +92,18 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
volume := state.Get("volume_id").(string)
|
if s.UseBlockStorageVolume {
|
||||||
if len(config.ImageMetadata) > 0 && s.UseBlockStorageVolume {
|
volume := state.Get("volume_id").(string)
|
||||||
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
|
if len(config.ImageMetadata) > 0 {
|
||||||
Metadata: config.ImageMetadata,
|
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
|
||||||
}).ExtractErr()
|
Metadata: config.ImageMetadata,
|
||||||
if err != nil {
|
}).ExtractErr()
|
||||||
err := fmt.Errorf("Error setting image metadata: %s", err)
|
if err != nil {
|
||||||
state.Put("error", err)
|
err := fmt.Errorf("Error setting image metadata: %s", err)
|
||||||
ui.Error(err.Error())
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@ package openstack
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/gophercloud/gophercloud"
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/startstop"
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
@ -27,9 +29,15 @@ func (s *StepStopServer) Run(ctx context.Context, state multistep.StateBag) mult
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Stopping server: %s ...", server.ID))
|
ui.Say(fmt.Sprintf("Stopping server: %s ...", server.ID))
|
||||||
if err := startstop.Stop(client, server.ID).ExtractErr(); err != nil {
|
if err := startstop.Stop(client, server.ID).ExtractErr(); err != nil {
|
||||||
err = fmt.Errorf("Error stopping server: %s", err)
|
if _, ok := err.(gophercloud.ErrDefault409); ok {
|
||||||
state.Put("error", err)
|
// The server might have already been shut down by Windows Sysprep
|
||||||
return multistep.ActionHalt
|
log.Printf("[WARN] 409 on stopping an already stopped server, continuing")
|
||||||
|
return multistep.ActionContinue
|
||||||
|
} else {
|
||||||
|
err = fmt.Errorf("Error stopping server: %s", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Message(fmt.Sprintf("Waiting for server to stop: %s ...", server.ID))
|
ui.Message(fmt.Sprintf("Waiting for server to stop: %s ...", server.ID))
|
||||||
|
@ -45,7 +53,6 @@ func (s *StepStopServer) Run(ctx context.Context, state multistep.StateBag) mult
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue