CreateStoragePoolVolumeFromBackup creates a custom volume from a backup file.
(pool string, args StorageVolumeBackupArgs)
| 1254 | |
| 1255 | // CreateStoragePoolVolumeFromBackup creates a custom volume from a backup file. |
| 1256 | func (r *ProtocolIncus) CreateStoragePoolVolumeFromBackup(pool string, args StorageVolumeBackupArgs) (Operation, error) { |
| 1257 | if !r.HasExtension("custom_volume_backup") { |
| 1258 | return nil, errors.New(`The server is missing the required "custom_volume_backup" API extension`) |
| 1259 | } |
| 1260 | |
| 1261 | if args.Name != "" && !r.HasExtension("backup_override_name") { |
| 1262 | return nil, errors.New(`The server is missing the required "backup_override_name" API extension`) |
| 1263 | } |
| 1264 | |
| 1265 | path := fmt.Sprintf("/storage-pools/%s/volumes/custom", url.PathEscape(pool)) |
| 1266 | |
| 1267 | // Prepare the HTTP request. |
| 1268 | reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path)) |
| 1269 | if err != nil { |
| 1270 | return nil, err |
| 1271 | } |
| 1272 | |
| 1273 | req, err := http.NewRequest("POST", reqURL, args.BackupFile) |
| 1274 | if err != nil { |
| 1275 | return nil, err |
| 1276 | } |
| 1277 | |
| 1278 | req.Header.Set("Content-Type", "application/octet-stream") |
| 1279 | |
| 1280 | if args.Name != "" { |
| 1281 | req.Header.Set("X-Incus-name", args.Name) |
| 1282 | } |
| 1283 | |
| 1284 | // Send the request. |
| 1285 | resp, err := r.DoHTTP(req) |
| 1286 | if err != nil { |
| 1287 | return nil, err |
| 1288 | } |
| 1289 | |
| 1290 | defer logger.WarnOnError(resp.Body.Close, "Failed to close response body") |
| 1291 | |
| 1292 | // Handle errors. |
| 1293 | response, _, err := incusParseResponse(resp) |
| 1294 | if err != nil { |
| 1295 | return nil, err |
| 1296 | } |
| 1297 | |
| 1298 | // Get to the operation. |
| 1299 | respOperation, err := response.MetadataAsOperation() |
| 1300 | if err != nil { |
| 1301 | return nil, err |
| 1302 | } |
| 1303 | |
| 1304 | // Setup an Operation wrapper. |
| 1305 | op := operation{ |
| 1306 | Operation: *respOperation, |
| 1307 | r: r, |
| 1308 | chActive: make(chan bool), |
| 1309 | } |
| 1310 | |
| 1311 | return &op, nil |
| 1312 | } |
| 1313 |
nothing calls this directly
no test coverage detected