DownloadStorageContentFromURL queues a storage download task from a URL and returns the task UPID.
(nodeName, storageName string, options StorageDownloadURLOptions)
| 92 | |
| 93 | // DownloadStorageContentFromURL queues a storage download task from a URL and returns the task UPID. |
| 94 | func (c *Client) DownloadStorageContentFromURL(nodeName, storageName string, options StorageDownloadURLOptions) (string, error) { |
| 95 | if strings.TrimSpace(nodeName) == "" { |
| 96 | return "", fmt.Errorf("node name is required") |
| 97 | } |
| 98 | if strings.TrimSpace(storageName) == "" { |
| 99 | return "", fmt.Errorf("storage name is required") |
| 100 | } |
| 101 | if strings.TrimSpace(options.URL) == "" { |
| 102 | return "", fmt.Errorf("url is required") |
| 103 | } |
| 104 | if strings.TrimSpace(options.Content) == "" { |
| 105 | return "", fmt.Errorf("content type is required") |
| 106 | } |
| 107 | |
| 108 | path := fmt.Sprintf("/nodes/%s/storage/%s/download-url", nodeName, storageName) |
| 109 | data := map[string]interface{}{ |
| 110 | "url": strings.TrimSpace(options.URL), |
| 111 | "content": strings.TrimSpace(options.Content), |
| 112 | "verify-certificates": options.VerifyCertificates, |
| 113 | } |
| 114 | if strings.TrimSpace(options.Filename) != "" { |
| 115 | data["filename"] = strings.TrimSpace(options.Filename) |
| 116 | } |
| 117 | if strings.TrimSpace(options.Checksum) != "" { |
| 118 | data["checksum"] = strings.TrimSpace(options.Checksum) |
| 119 | } |
| 120 | if strings.TrimSpace(options.ChecksumAlgorithm) != "" { |
| 121 | data["checksum-algorithm"] = strings.TrimSpace(options.ChecksumAlgorithm) |
| 122 | } |
| 123 | if strings.TrimSpace(options.Compression) != "" { |
| 124 | data["compression"] = strings.TrimSpace(options.Compression) |
| 125 | } |
| 126 | |
| 127 | var res map[string]interface{} |
| 128 | if err := c.PostWithResponse(path, data, &res); err != nil { |
| 129 | return "", fmt.Errorf("failed to download storage content from URL on %s/%s: %w", nodeName, storageName, err) |
| 130 | } |
| 131 | |
| 132 | if errMsg, ok := res["error"].(string); ok && errMsg != "" { |
| 133 | return "", fmt.Errorf("storage download failed: %s", errMsg) |
| 134 | } |
| 135 | |
| 136 | upid, ok := res["data"].(string) |
| 137 | if !ok || !strings.HasPrefix(upid, "UPID:") { |
| 138 | return "", fmt.Errorf("failed to get download task ID") |
| 139 | } |
| 140 | |
| 141 | c.ClearAPICache() |
| 142 | |
| 143 | return upid, nil |
| 144 | } |
| 145 | |
| 146 | // PullStorageOCIImage queues an OCI registry pull task and returns the task UPID. |
| 147 | func (c *Client) PullStorageOCIImage(nodeName, storageName string, options StorageOCIPullOptions) (string, error) { |