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