waitForTask polls a Proxmox task to completion using the existing WaitForTaskCompletion method and returns the final exit status string. It respects ctx cancellation (e.g. Ctrl-C).
(ctx context.Context, client *api.Client, node, upid, operationName string)
| 601 | // WaitForTaskCompletion method and returns the final exit status string. |
| 602 | // It respects ctx cancellation (e.g. Ctrl-C). |
| 603 | func waitForTask(ctx context.Context, client *api.Client, node, upid, operationName string) (exitStatus string, err error) { |
| 604 | const defaultTimeout = 10 * time.Minute |
| 605 | |
| 606 | done := make(chan error, 1) |
| 607 | go func() { |
| 608 | done <- client.WaitForTaskCompletion(upid, operationName, defaultTimeout) |
| 609 | }() |
| 610 | |
| 611 | select { |
| 612 | case <-ctx.Done(): |
| 613 | return "", fmt.Errorf("%s cancelled", operationName) |
| 614 | case err = <-done: |
| 615 | if err != nil { |
| 616 | return "ERROR", err |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // Fetch final status for structured output. |
| 621 | status, fetchErr := client.GetTaskStatus(node, upid) |
| 622 | if fetchErr != nil || status == nil { |
| 623 | return "OK", nil |
| 624 | } |
| 625 | |
| 626 | return status.ExitStatus, nil |
| 627 | } |
| 628 | |
| 629 | // inferGuestTypeFromVolID returns "qemu" or "lxc" based on the vzdump volid prefix. |
| 630 | func inferGuestTypeFromVolID(volID string) (string, error) { |