util

package
v1.113.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: BSD-3-Clause, MIT Imports: 4 Imported by: 21

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitForActive

func WaitForActive(ctx context.Context, client *godo.Client, monitorURI string) error

WaitForActive waits for a droplet to become active

Example
// Create a godo client.
client := godo.NewFromToken("dop_v1_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

// Create a Droplet.
droplet, resp, err := client.Droplets.Create(context.Background(), &godo.DropletCreateRequest{
	Name:   "test-droplet",
	Region: "nyc3",
	Size:   "s-1vcpu-1gb",
	Image: godo.DropletCreateImage{
		Slug: "ubuntu-20-04-x64",
	},
})
if err != nil {
	log.Fatalf("failed to create droplet: %v\n", err)
}

// Find the Droplet create action, then wait for it to complete.
for _, action := range resp.Links.Actions {
	if action.Rel == "create" {
		// Block until the action is complete.
		if err := WaitForActive(context.Background(), client, action.HREF); err != nil {
			log.Fatalf("error waiting for droplet to become active: %v\n", err)
		}
	}
}

fmt.Println(droplet.Name)
Output:

func WaitForAvailable added in v1.90.0

func WaitForAvailable(ctx context.Context, client *godo.Client, monitorURI string) error

WaitForAvailable waits for a image to become available

Example
// Create a godo client.
client := godo.NewFromToken("dop_v1_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

// Create an Image.
image, resp, err := client.Images.Create(context.Background(), &godo.CustomImageCreateRequest{
	Name:   "test-image",
	Url:    "https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.vmdk",
	Region: "nyc3",
})
if err != nil {
	log.Fatalf("failed to create image: %v\n", err)
}

// Find the Image create action, then wait for it to complete.
for _, action := range resp.Links.Actions {
	if action.Rel == "create" {
		// Block until the action is complete.
		if err := WaitForAvailable(context.Background(), client, action.HREF); err != nil {
			log.Fatalf("error waiting for image to become active: %v\n", err)
		}
	}
}

fmt.Println(image.Name)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL