Throwing error if ostypeid, nicAdapter, rootDiskController is passed for VMWare templates

This commit is contained in:
davidjumani 2020-10-16 18:05:08 +05:30 committed by Harikrishna Patnala
parent ee5b8763a6
commit 38e119a099
1 changed files with 16 additions and 1 deletions

View File

@ -43,6 +43,7 @@ import org.apache.log4j.Logger;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.vm.VmDetailConstants;
@APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud. ", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@ -87,7 +88,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
type = CommandType.UUID,
entityType = GuestOSResponse.class,
required = true,
description = "the ID of the OS Type that best represents the OS of this template.")
description = "the ID of the OS Type that best represents the OS of this template. Not applicable with VMware, as we honour what is defined in the template")
private Long osTypeId;
@Parameter(name = ApiConstants.PASSWORD_ENABLED,
@ -340,5 +341,19 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
"Parameter directdownload is only allowed for KVM templates");
}
if (getHypervisor().equalsIgnoreCase(Hypervisor.HypervisorType.VMware.toString())) {
if (osTypeId != null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "ostypeid is not supported on VMWare");
}
details = getDetails();
if (details.containsKey(VmDetailConstants.ROOT_DISK_CONTROLLER)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "rootDiskController is not supported on VMWare");
}
if (details.containsKey(VmDetailConstants.NIC_ADAPTER)) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "nicAdapter is not supported on VMWare");
}
}
}
}