github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/baremetal/v1/nodes/util.go (about)

     1  package nodes
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  )
     8  
     9  // WaitForProvisionState will continually poll a node until it successfully
    10  // transitions to a specified state. It will do this for at most the number
    11  // of seconds specified.
    12  func WaitForProvisionState(ctx context.Context, c *gophercloud.ServiceClient, id string, state ProvisionState) error {
    13  	return gophercloud.WaitFor(ctx, func(ctx context.Context) (bool, error) {
    14  		current, err := Get(ctx, c, id).Extract()
    15  		if err != nil {
    16  			return false, err
    17  		}
    18  
    19  		if current.ProvisionState == string(state) {
    20  			return true, nil
    21  		}
    22  
    23  		return false, nil
    24  	})
    25  }