GetStorageContent retrieves storage content entries for a given node/storage pair. When contentType is empty, all content types are returned.
(nodeName, storageName, contentType string)
| 43 | // GetStorageContent retrieves storage content entries for a given node/storage pair. |
| 44 | // When contentType is empty, all content types are returned. |
| 45 | func (c *Client) GetStorageContent(nodeName, storageName, contentType string) ([]StorageContentItem, error) { |
| 46 | path := fmt.Sprintf("/nodes/%s/storage/%s/content", nodeName, storageName) |
| 47 | if strings.TrimSpace(contentType) != "" { |
| 48 | path += "?content=" + strings.TrimSpace(contentType) |
| 49 | } |
| 50 | |
| 51 | var res map[string]interface{} |
| 52 | if err := c.GetWithCache(path, &res, NodeDataTTL); err != nil { |
| 53 | return nil, fmt.Errorf("failed to get storage content for %s/%s: %w", nodeName, storageName, err) |
| 54 | } |
| 55 | |
| 56 | data, ok := res["data"].([]interface{}) |
| 57 | if !ok { |
| 58 | return nil, fmt.Errorf("invalid storage content response format") |
| 59 | } |
| 60 | |
| 61 | items := make([]StorageContentItem, 0, len(data)) |
| 62 | for _, raw := range data { |
| 63 | itemMap, ok := raw.(map[string]interface{}) |
| 64 | if !ok { |
| 65 | continue |
| 66 | } |
| 67 | |
| 68 | item := StorageContentItem{ |
| 69 | VolID: getString(itemMap, "volid"), |
| 70 | Content: getString(itemMap, "content"), |
| 71 | Format: getString(itemMap, "format"), |
| 72 | Notes: getString(itemMap, "notes"), |
| 73 | Parent: getString(itemMap, "parent"), |
| 74 | Size: int64(getFloat(itemMap, "size")), |
| 75 | Used: int64(getFloat(itemMap, "used")), |
| 76 | VMID: getInt(itemMap, "vmid"), |
| 77 | } |
| 78 | |
| 79 | if protected, ok := itemMap["protected"].(bool); ok { |
| 80 | item.Protected = protected |
| 81 | } |
| 82 | |
| 83 | if ctime, ok := itemMap["ctime"].(float64); ok && ctime > 0 { |
| 84 | item.CreatedAt = time.Unix(int64(ctime), 0) |
| 85 | } |
| 86 | |
| 87 | items = append(items, item) |
| 88 | } |
| 89 | |
| 90 | return items, nil |
| 91 | } |
| 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) { |