Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd {
description = "if true, the templates would be available for deploying CKS clusters", since = "4.21.0")
protected Boolean forCks;

@Parameter(name = ApiConstants.TEMPLATE_TYPE, type = CommandType.STRING,
description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).",
since = "4.22.0")
private String templateType;

public String getDisplayText() {
return StringUtils.isBlank(displayText) ? getName() : displayText;
}
Expand Down Expand Up @@ -181,6 +186,10 @@ public CPU.CPUArch getArch() {
return CPU.CPUArch.fromType(arch);
}

public String getTemplateType() {
return templateType;
}

@Override
public void execute() throws ServerApiException {
validateRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public TemplateUploadParams(long userId, String name, String displayText, CPU.CP
Long zoneId, Hypervisor.HypervisorType hypervisorType, String chksum,
String templateTag, long templateOwnerId,
Map details, Boolean sshkeyEnabled,
Boolean isDynamicallyScalable, Boolean isRoutingType, boolean deployAsIs, boolean forCks) {
Boolean isDynamicallyScalable, Boolean isRoutingType, boolean deployAsIs,
boolean forCks, String templateType) {
super(userId, name, displayText, arch, bits, passwordEnabled, requiresHVM, isPublic, featured, isExtractable,
format, guestOSId, zoneId, hypervisorType, chksum, templateTag, templateOwnerId, details,
sshkeyEnabled, isDynamicallyScalable, isRoutingType, deployAsIs, forCks);
sshkeyEnabled, isDynamicallyScalable, isRoutingType, deployAsIs, forCks, templateType);
setBootable(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public interface UploadParams {
boolean isDirectDownload();
boolean isDeployAsIs();
CPU.CPUArch getArch();
boolean isForCks();
String getTemplateType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ public abstract class UploadParamsBase implements UploadParams {
private boolean deployAsIs;
private boolean forCks;
private CPU.CPUArch arch;
private String templateType;

UploadParamsBase(long userId, String name, String displayText, CPU.CPUArch arch,
Integer bits, boolean passwordEnabled, boolean requiresHVM,
boolean isPublic, boolean featured,
boolean isExtractable, String format, Long guestOSId,
Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum,
String templateTag, long templateOwnerId,
Map details, boolean sshkeyEnabled,
boolean isDynamicallyScalable, boolean isRoutingType, boolean deployAsIs, boolean forCks) {
Integer bits, boolean passwordEnabled, boolean requiresHVM,
boolean isPublic, boolean featured,
boolean isExtractable, String format, Long guestOSId,
Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum,
String templateTag, long templateOwnerId,
Map details, boolean sshkeyEnabled,
boolean isDynamicallyScalable, boolean isRoutingType, boolean deployAsIs,
boolean forCks, String templateType) {
this.userId = userId;
this.name = name;
this.displayText = displayText;
Expand All @@ -79,6 +81,8 @@ public abstract class UploadParamsBase implements UploadParams {
this.isDynamicallyScalable = isDynamicallyScalable;
this.isRoutingType = isRoutingType;
this.deployAsIs = deployAsIs;
this.forCks = forCks;
this.templateType = templateType;
}

UploadParamsBase(long userId, String name, String displayText, boolean isPublic, boolean isFeatured,
Expand Down Expand Up @@ -261,4 +265,14 @@ public CPU.CPUArch getArch() {
public void setArch(CPU.CPUArch arch) {
this.arch = arch;
}

@Override
public boolean isForCks() {
return forCks;
}

@Override
public String getTemplateType() {
return templateType;
}
}
16 changes: 11 additions & 5 deletions server/src/main/java/com/cloud/template/TemplateAdapterBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.inject.Inject;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd;
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
Expand Down Expand Up @@ -469,7 +470,7 @@ public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocatio
/**
* Prepare upload parameters internal method for templates and ISOs local upload
*/
private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws ResourceAllocationException {
private TemplateProfile prepareUploadParamsInternal(BaseCmd cmd, UploadParams params) throws ResourceAllocationException {
//check if the caller can operate with the template owner
Account caller = CallContext.current().getCallingAccount();
Account owner = _accountMgr.getAccount(params.getTemplateOwnerId());
Expand All @@ -490,12 +491,16 @@ private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws
StringUtils.join(Arrays.stream(HypervisorType.values()).filter(h -> h != HypervisorType.None).map(HypervisorType::name).toArray(), ", ")));
}

TemplateType templateType = templateMgr.validateTemplateType(cmd, _accountMgr.isAdmin(caller.getAccountId()),
false, params.getHypervisorType());

return prepare(params.isIso(), params.getUserId(), params.getName(), params.getDisplayText(), params.getArch(), params.getBits(),
params.isPasswordEnabled(), params.requiresHVM(), params.getUrl(), params.isPublic(), params.isFeatured(),
params.isExtractable(), params.getFormat(), params.getGuestOSId(), zoneList,
params.getHypervisorType(), params.getChecksum(), params.isBootable(), params.getTemplateTag(), owner,
params.getDetails(), params.isSshKeyEnabled(), params.getImageStoreUuid(),
params.isDynamicallyScalable(), params.isRoutingType() ? TemplateType.ROUTING : TemplateType.USER, params.isDirectDownload(), params.isDeployAsIs(), false, null);
params.isDynamicallyScalable(), templateType, params.isDirectDownload(), params.isDeployAsIs(),
params.isForCks(), null);
}

private Long getDefaultDeployAsIsGuestOsId() {
Expand All @@ -516,8 +521,9 @@ public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws Resourc
BooleanUtils.toBoolean(cmd.isFeatured()), BooleanUtils.toBoolean(cmd.isExtractable()), cmd.getFormat(), osTypeId,
cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(),
cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), BooleanUtils.toBoolean(cmd.isSshKeyEnabled()),
BooleanUtils.toBoolean(cmd.isDynamicallyScalable()), BooleanUtils.toBoolean(cmd.isRoutingType()), cmd.isDeployAsIs(), cmd.isForCks());
return prepareUploadParamsInternal(params);
BooleanUtils.toBoolean(cmd.isDynamicallyScalable()), BooleanUtils.toBoolean(cmd.isRoutingType()), cmd.isDeployAsIs(),
cmd.isForCks(), cmd.getTemplateType());
return prepareUploadParamsInternal(cmd, params);
}

@Override
Expand All @@ -526,7 +532,7 @@ public TemplateProfile prepare(GetUploadParamsForIsoCmd cmd) throws ResourceAllo
cmd.getDisplayText(), BooleanUtils.toBoolean(cmd.isPublic()), BooleanUtils.toBoolean(cmd.isFeatured()),
BooleanUtils.toBoolean(cmd.isExtractable()), cmd.getOsTypeId(),
cmd.getZoneId(), BooleanUtils.toBoolean(cmd.isBootable()), cmd.getEntityOwnerId());
return prepareUploadParamsInternal(params);
return prepareUploadParamsInternal(cmd, params);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ else if (details != null && !details.isEmpty()) {

@Override
public TemplateType validateTemplateType(BaseCmd cmd, boolean isAdmin, boolean isCrossZones, HypervisorType hypervisorType) {
if (!(cmd instanceof UpdateTemplateCmd) && !(cmd instanceof RegisterTemplateCmd)) {
if (!(cmd instanceof UpdateTemplateCmd) && !(cmd instanceof RegisterTemplateCmd) && !(cmd instanceof GetUploadParamsForTemplateCmd)) {
return null;
}
TemplateType templateType = null;
Expand All @@ -2351,6 +2351,9 @@ public TemplateType validateTemplateType(BaseCmd cmd, boolean isAdmin, boolean i
} else if (cmd instanceof RegisterTemplateCmd) {
newType = ((RegisterTemplateCmd)cmd).getTemplateType();
isRoutingType = ((RegisterTemplateCmd)cmd).isRoutingType();
} else if (cmd instanceof GetUploadParamsForTemplateCmd) {
newType = ((GetUploadParamsForTemplateCmd)cmd).getTemplateType();
isRoutingType = ((GetUploadParamsForTemplateCmd)cmd).isRoutingType();
}
if (newType != null) {
try {
Expand Down
Loading