github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/container/v1/capsules.go (about)

     1  package v1
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/internal/acceptance/tools"
     8  	"github.com/gophercloud/gophercloud/openstack/container/v1/capsules"
     9  )
    10  
    11  // WaitForCapsuleStatus will poll a capsule's status until it either matches
    12  // the specified status or the status becomes Failed.
    13  func WaitForCapsuleStatus(client *gophercloud.ServiceClient, uuid, status string) error {
    14  	return tools.WaitFor(func() (bool, error) {
    15  		v, err := capsules.Get(client, uuid).Extract()
    16  		if err != nil {
    17  			return false, err
    18  		}
    19  
    20  		var newStatus string
    21  		if capsule, ok := v.(*capsules.Capsule); ok {
    22  			newStatus = capsule.Status
    23  		}
    24  
    25  		if capsule, ok := v.(*capsules.CapsuleV132); ok {
    26  			newStatus = capsule.Status
    27  		}
    28  
    29  		fmt.Println(status)
    30  		fmt.Println(newStatus)
    31  
    32  		if newStatus == status {
    33  			// Success!
    34  			return true, nil
    35  		}
    36  
    37  		if newStatus == "Failed" {
    38  			return false, fmt.Errorf("Capsule in FAILED state")
    39  		}
    40  
    41  		if newStatus == "Error" {
    42  			return false, fmt.Errorf("Capsule in ERROR state")
    43  		}
    44  
    45  		return false, nil
    46  	})
    47  }