github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/servers/util.go (about)

     1  package servers
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  )
     8  
     9  // WaitForStatus will continually poll a server until it successfully
    10  // transitions to a specified status.
    11  func WaitForStatus(ctx context.Context, c *gophercloud.ServiceClient, id, status string) error {
    12  	return gophercloud.WaitFor(ctx, func(ctx context.Context) (bool, error) {
    13  		current, err := Get(ctx, c, id).Extract()
    14  		if err != nil {
    15  			return false, err
    16  		}
    17  
    18  		if current.Status == status {
    19  			return true, nil
    20  		}
    21  
    22  		return false, nil
    23  	})
    24  }