CreateStoragePoolVolumeFromISO creates a custom volume from an ISO file.
(pool string, args StorageVolumeBackupArgs)
| 1196 | |
| 1197 | // CreateStoragePoolVolumeFromISO creates a custom volume from an ISO file. |
| 1198 | func (r *ProtocolIncus) CreateStoragePoolVolumeFromISO(pool string, args StorageVolumeBackupArgs) (Operation, error) { |
| 1199 | err := r.CheckExtension("custom_volume_iso") |
| 1200 | if err != nil { |
| 1201 | return nil, err |
| 1202 | } |
| 1203 | |
| 1204 | if args.Name == "" { |
| 1205 | return nil, errors.New("Missing volume name") |
| 1206 | } |
| 1207 | |
| 1208 | path := fmt.Sprintf("/storage-pools/%s/volumes/custom", url.PathEscape(pool)) |
| 1209 | |
| 1210 | // Prepare the HTTP request. |
| 1211 | reqURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0%s", r.httpBaseURL.String(), path)) |
| 1212 | if err != nil { |
| 1213 | return nil, err |
| 1214 | } |
| 1215 | |
| 1216 | req, err := http.NewRequest("POST", reqURL, args.BackupFile) |
| 1217 | if err != nil { |
| 1218 | return nil, err |
| 1219 | } |
| 1220 | |
| 1221 | req.Header.Set("Content-Type", "application/octet-stream") |
| 1222 | req.Header.Set("X-Incus-name", args.Name) |
| 1223 | req.Header.Set("X-Incus-type", "iso") |
| 1224 | |
| 1225 | // Send the request. |
| 1226 | resp, err := r.DoHTTP(req) |
| 1227 | if err != nil { |
| 1228 | return nil, err |
| 1229 | } |
| 1230 | |
| 1231 | defer logger.WarnOnError(resp.Body.Close, "Failed to close response body") |
| 1232 | |
| 1233 | // Handle errors. |
| 1234 | response, _, err := incusParseResponse(resp) |
| 1235 | if err != nil { |
| 1236 | return nil, err |
| 1237 | } |
| 1238 | |
| 1239 | // Get to the operation. |
| 1240 | respOperation, err := response.MetadataAsOperation() |
| 1241 | if err != nil { |
| 1242 | return nil, err |
| 1243 | } |
| 1244 | |
| 1245 | // Setup an Operation wrapper. |
| 1246 | op := operation{ |
| 1247 | Operation: *respOperation, |
| 1248 | r: r, |
| 1249 | chActive: make(chan bool), |
| 1250 | } |
| 1251 | |
| 1252 | return &op, nil |
| 1253 | } |
| 1254 | |
| 1255 | // CreateStoragePoolVolumeFromBackup creates a custom volume from a backup file. |
nothing calls this directly
no test coverage detected