Skip to content

Commit 503ae64

Browse files
Upload volume format check with the supported hypervisor, fail if supported hypervisor not found on zone (#9224)
1 parent 0f77019 commit 503ae64

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
import com.cloud.org.Grouping;
159159
import com.cloud.projects.Project;
160160
import com.cloud.projects.ProjectManager;
161+
import com.cloud.resource.ResourceManager;
161162
import com.cloud.resource.ResourceState;
162163
import com.cloud.serializer.GsonHelper;
163164
import com.cloud.server.ManagementService;
@@ -258,6 +259,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
258259
@Inject
259260
private ConfigurationManager _configMgr;
260261
@Inject
262+
private ResourceManager _resourceMgr;
263+
@Inject
261264
private VolumeDao _volsDao;
262265
@Inject
263266
private VolumeDetailsDao _volsDetailsDao;
@@ -564,7 +567,7 @@ private boolean validateVolume(Account caller, long ownerId, Long zoneId, String
564567
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage);
565568
}
566569

567-
sanitizeFormat(format);
570+
checkFormatWithSupportedHypervisorsInZone(format, zoneId);
568571

569572
// Check that the disk offering specified is valid
570573
if (diskOfferingId != null) {
@@ -581,6 +584,15 @@ private boolean validateVolume(Account caller, long ownerId, Long zoneId, String
581584
return false;
582585
}
583586

587+
private void checkFormatWithSupportedHypervisorsInZone(String format, Long zoneId) {
588+
ImageFormat imageformat = ImageFormat.valueOf(format);
589+
final List<HypervisorType> supportedHypervisorTypesInZone = _resourceMgr.getSupportedHypervisorTypes(zoneId, false, null);
590+
final HypervisorType hypervisorTypeFromFormat = ApiDBUtils.getHypervisorTypeFromFormat(zoneId, imageformat);
591+
if (!(supportedHypervisorTypesInZone.contains(hypervisorTypeFromFormat))) {
592+
throw new InvalidParameterValueException(String.format("The %s hypervisor supported for %s file format, is not found on the zone", hypervisorTypeFromFormat.toString(), format));
593+
}
594+
}
595+
584596
public String getRandomVolumeName() {
585597
return UUID.randomUUID().toString();
586598
}

0 commit comments

Comments
 (0)