File: capsules.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package v1

import (
	"fmt"

	"github.com/gophercloud/gophercloud"
	"github.com/gophercloud/gophercloud/acceptance/tools"
	"github.com/gophercloud/gophercloud/openstack/container/v1/capsules"
)

// WaitForCapsuleStatus will poll a capsule's status until it either matches
// the specified status or the status becomes Failed.
func WaitForCapsuleStatus(client *gophercloud.ServiceClient, uuid, status string) error {
	return tools.WaitFor(func() (bool, error) {
		v, err := capsules.Get(client, uuid).Extract()
		if err != nil {
			return false, err
		}

		var newStatus string
		if capsule, ok := v.(*capsules.Capsule); ok {
			newStatus = capsule.Status
		}

		if capsule, ok := v.(*capsules.CapsuleV132); ok {
			newStatus = capsule.Status
		}

		fmt.Println(status)
		fmt.Println(newStatus)

		if newStatus == status {
			// Success!
			return true, nil
		}

		if newStatus == "Failed" {
			return false, fmt.Errorf("Capsule in FAILED state")
		}

		if newStatus == "Error" {
			return false, fmt.Errorf("Capsule in ERROR state")
		}

		return false, nil
	})
}