DeleteStorageContent deletes a storage content item and returns the queued task UPID.
(nodeName, storageName, volID string)
| 281 | |
| 282 | // DeleteStorageContent deletes a storage content item and returns the queued task UPID. |
| 283 | func (c *Client) DeleteStorageContent(nodeName, storageName, volID string) (string, error) { |
| 284 | if strings.TrimSpace(nodeName) == "" { |
| 285 | return "", fmt.Errorf("node name is required") |
| 286 | } |
| 287 | if strings.TrimSpace(storageName) == "" { |
| 288 | return "", fmt.Errorf("storage name is required") |
| 289 | } |
| 290 | if strings.TrimSpace(volID) == "" { |
| 291 | return "", fmt.Errorf("volume ID is required") |
| 292 | } |
| 293 | |
| 294 | path := fmt.Sprintf( |
| 295 | "/nodes/%s/storage/%s/content/%s", |
| 296 | nodeName, |
| 297 | storageName, |
| 298 | url.PathEscape(strings.TrimSpace(volID)), |
| 299 | ) |
| 300 | |
| 301 | var res map[string]interface{} |
| 302 | if err := c.DeleteWithResponse(path, &res); err != nil { |
| 303 | return "", fmt.Errorf("failed to delete storage content %s on %s/%s: %w", volID, nodeName, storageName, err) |
| 304 | } |
| 305 | |
| 306 | if errMsg, ok := res["error"].(string); ok && errMsg != "" { |
| 307 | return "", fmt.Errorf("storage content delete failed: %s", errMsg) |
| 308 | } |
| 309 | |
| 310 | upid, ok := res["data"].(string) |
| 311 | if !ok || !strings.HasPrefix(upid, "UPID:") { |
| 312 | return "", fmt.Errorf("failed to get delete task ID") |
| 313 | } |
| 314 | |
| 315 | c.ClearAPICache() |
| 316 | |
| 317 | return upid, nil |
| 318 | } |
| 319 | |
| 320 | // RestoreGuestFromBackup restores a VM or container from a backup volume and returns the queued task UPID. |
| 321 | func (c *Client) RestoreGuestFromBackup(nodeName, guestType string, vmid int, volID string, force bool) (string, error) { |