Wait for detach optimization
This commit is contained in:
parent
bbac79f0a4
commit
6dee4d2d32
|
@ -20,9 +20,10 @@ import (
|
|||
|
||||
type DiskAttacher interface {
|
||||
AttachDisk(ctx context.Context, disk string) (lun int32, err error)
|
||||
DetachDisk(ctx context.Context, disk string) (err error)
|
||||
WaitForDevice(ctx context.Context, i int32) (device string, err error)
|
||||
DiskPathForLun(lun int32) string
|
||||
WaitForDevice(ctx context.Context, i int32) (device string, err error)
|
||||
DetachDisk(ctx context.Context, disk string) (err error)
|
||||
WaitForDetach(ctx context.Context, diskID string) error
|
||||
}
|
||||
|
||||
func NewDiskAttacher(azureClient client.AzureClientSet) DiskAttacher {
|
||||
|
@ -89,7 +90,10 @@ func (da *diskAttacher) DetachDisk(ctx context.Context, diskID string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// waiting for VM update to finish takes way to long
|
||||
return nil
|
||||
}
|
||||
|
||||
func (da *diskAttacher) WaitForDetach(ctx context.Context, diskID string) error {
|
||||
for { // loop until disk is not attached, timeout or error
|
||||
list, err := da.getDisks(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -83,9 +83,12 @@ func (s StepCreateNewDisk) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
func (s StepCreateNewDisk) Cleanup(state multistep.StateBag) {
|
||||
azcli := state.Get("azureclient").(client.AzureClientSet)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
diskResourceID := state.Get("os_disk_resource_id")
|
||||
diskResourceID := state.Get("os_disk_resource_id").(string)
|
||||
|
||||
ui.Say(fmt.Sprintf("Deleting disk '%s'", diskResourceID))
|
||||
ui.Say(fmt.Sprintf("Waiting for disk %q detach to complete", diskResourceID))
|
||||
err := NewDiskAttacher(azcli).WaitForDetach(context.Background(), diskResourceID)
|
||||
|
||||
ui.Say(fmt.Sprintf("Deleting disk %q", diskResourceID))
|
||||
|
||||
f, err := azcli.DisksClient().Delete(context.TODO(), s.ResourceGroup, s.DiskName)
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in New Issue