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,8 +92,9 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.UseBlockStorageVolume {
|
||||||
volume := state.Get("volume_id").(string)
|
volume := state.Get("volume_id").(string)
|
||||||
if len(config.ImageMetadata) > 0 && s.UseBlockStorageVolume {
|
if len(config.ImageMetadata) > 0 {
|
||||||
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
|
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
|
||||||
Metadata: config.ImageMetadata,
|
Metadata: config.ImageMetadata,
|
||||||
}).ExtractErr()
|
}).ExtractErr()
|
||||||
|
@ -104,6 +105,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,10 +29,16 @@ 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 {
|
||||||
|
if _, ok := err.(gophercloud.ErrDefault409); ok {
|
||||||
|
// The server might have already been shut down by Windows Sysprep
|
||||||
|
log.Printf("[WARN] 409 on stopping an already stopped server, continuing")
|
||||||
|
return multistep.ActionContinue
|
||||||
|
} else {
|
||||||
err = fmt.Errorf("Error stopping server: %s", err)
|
err = fmt.Errorf("Error stopping server: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
return multistep.ActionHalt
|
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))
|
||||||
stateChange := StateChangeConf{
|
stateChange := StateChangeConf{
|
||||||
|
@ -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