util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: BSD-3-Clause, MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitForActive

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

WaitForActive waits for a vm to become active

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

// Create a Vm.
vmRoot, resp, err := client.Vms.Create(context.Background(), &goApiAbrha.VmCreateRequest{
	Name:   "test-vm",
	Region: "nyc3",
	Size:   "s-1vcpu-1gb",
	Image: goApiAbrha.VmCreateImage{
		Slug: "ubuntu-20-04-x64",
	},
})
if err != nil {
	log.Fatalf("failed to create vm: %v\n", err)
}

// Find the Vm 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 vm to become active: %v\n", err)
		}
	}
}

fmt.Println(vmRoot.Vm.Name)
Output:

func WaitForAvailable

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

WaitForAvailable waits for an image to become available

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

// Create an Image.
image, resp, err := client.Images.Create(context.Background(), &goApiAbrha.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