Skip to content

Commit 7bba1ad

Browse files
zhenggulbajolet-hashicorp
authored andcommitted
Remove volume by cleanup
1 parent 1e16ca7 commit 7bba1ad

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

builder/openstack/step_create_volume.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,14 @@ func (s *StepCreateVolume) Run(ctx context.Context, state multistep.StateBag) mu
7979
// Wait for volume to become available.
8080
ui.Say(fmt.Sprintf("Waiting for volume %s (volume id: %s) to become available...", config.VolumeName, volume.ID))
8181
if err := WaitForVolume(blockStorageClient, volume.ID); err != nil {
82-
_, ok := err.(*volumeErr)
8382
err := fmt.Errorf("Error waiting for volume: %s", err)
8483
state.Put("error", err)
8584
ui.Error(err.Error())
86-
if ok {
87-
ui.Say(fmt.Sprintf("Deleting volume: %s ...", volume.ID))
88-
err = volumes.Delete(blockStorageClient, volume.ID, volumes.DeleteOpts{}).ExtractErr()
89-
if err != nil {
90-
ui.Error(fmt.Sprintf(
91-
"Error cleaning up volume. Please delete the volume manually: %s", volume.ID))
92-
}
93-
}
85+
86+
// The volume ID has created, try to clean up
87+
s.doCleanup = true
88+
s.volumeID = volume.ID
89+
9490
return multistep.ActionHalt
9591
}
9692

builder/openstack/volume.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package openstack
55

66
import (
7+
"errors"
78
"log"
89
"time"
910

@@ -12,12 +13,6 @@ import (
1213
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
1314
)
1415

15-
type volumeErr struct{}
16-
17-
func (err *volumeErr) Error() string {
18-
return "The status of volume is error"
19-
}
20-
2116
// WaitForVolume waits for the given volume to become available.
2217
func WaitForVolume(blockStorageClient *gophercloud.ServiceClient, volumeID string) error {
2318
maxNumErrors := 10
@@ -46,7 +41,7 @@ func WaitForVolume(blockStorageClient *gophercloud.ServiceClient, volumeID strin
4641
}
4742

4843
if status == "error" {
49-
return &volumeErr{}
44+
return errors.New("The status of volume is error")
5045
}
5146

5247
log.Printf("Waiting for volume creation status: %s", status)

0 commit comments

Comments
 (0)