Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
import com.cloud.org.Grouping;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectManager;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
import com.cloud.serializer.GsonHelper;
import com.cloud.server.ManagementService;
Expand Down Expand Up @@ -258,6 +259,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Inject
private ConfigurationManager _configMgr;
@Inject
private ResourceManager _resourceMgr;
@Inject
private VolumeDao _volsDao;
@Inject
private VolumeDetailsDao _volsDetailsDao;
Expand Down Expand Up @@ -564,7 +567,7 @@ private boolean validateVolume(Account caller, long ownerId, Long zoneId, String
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage);
}

sanitizeFormat(format);
checkFormatWithSupportedHypervisorsInZone(format, zoneId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still call sanitizeFormat?

@sureshanaparti sureshanaparti Jun 12, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes @DaanHoogland, it's called before. this is duplicate call. so removed

String format = sanitizeFormat(cmd.getFormat());

String format = sanitizeFormat(cmd.getFormat());


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

private void checkFormatWithSupportedHypervisorsInZone(String format, Long zoneId) {
ImageFormat imageformat = ImageFormat.valueOf(format);
final List<HypervisorType> supportedHypervisorTypesInZone = _resourceMgr.getSupportedHypervisorTypes(zoneId, false, null);
final HypervisorType hypervisorTypeFromFormat = ApiDBUtils.getHypervisorTypeFromFormat(zoneId, imageformat);
if (!(supportedHypervisorTypesInZone.contains(hypervisorTypeFromFormat))) {
throw new InvalidParameterValueException(String.format("The %s hypervisor supported for %s file format, is not found on the zone", hypervisorTypeFromFormat.toString(), format));
}
}

public String getRandomVolumeName() {
return UUID.randomUUID().toString();
}
Expand Down