Skip to content

Commit a54a1c2

Browse files
committed
api,server: support templatetype when upload template from local
1 parent 8eb6ddd commit a54a1c2

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd {
104104
description = "if true, the templates would be available for deploying CKS clusters", since = "4.21.0")
105105
protected Boolean forCks;
106106

107+
@Parameter(name = ApiConstants.TEMPLATE_TYPE, type = CommandType.STRING,
108+
description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).",
109+
since = "4.22.0")
110+
private String templateType;
111+
107112
public String getDisplayText() {
108113
return StringUtils.isBlank(displayText) ? getName() : displayText;
109114
}
@@ -181,6 +186,10 @@ public CPU.CPUArch getArch() {
181186
return CPU.CPUArch.fromType(arch);
182187
}
183188

189+
public String getTemplateType() {
190+
return templateType;
191+
}
192+
184193
@Override
185194
public void execute() throws ServerApiException {
186195
validateRequest();

server/src/main/java/com/cloud/storage/upload/params/TemplateUploadParams.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ public TemplateUploadParams(long userId, String name, String displayText, CPU.CP
3030
Long zoneId, Hypervisor.HypervisorType hypervisorType, String chksum,
3131
String templateTag, long templateOwnerId,
3232
Map details, Boolean sshkeyEnabled,
33-
Boolean isDynamicallyScalable, Boolean isRoutingType, boolean deployAsIs, boolean forCks) {
33+
Boolean isDynamicallyScalable, Boolean isRoutingType, boolean deployAsIs,
34+
boolean forCks, String templateType) {
3435
super(userId, name, displayText, arch, bits, passwordEnabled, requiresHVM, isPublic, featured, isExtractable,
3536
format, guestOSId, zoneId, hypervisorType, chksum, templateTag, templateOwnerId, details,
36-
sshkeyEnabled, isDynamicallyScalable, isRoutingType, deployAsIs, forCks);
37+
sshkeyEnabled, isDynamicallyScalable, isRoutingType, deployAsIs, forCks, templateType);
3738
setBootable(true);
3839
}
3940
}

server/src/main/java/com/cloud/storage/upload/params/UploadParams.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ public interface UploadParams {
4949
boolean isDirectDownload();
5050
boolean isDeployAsIs();
5151
CPU.CPUArch getArch();
52+
boolean isForCks();
53+
String getTemplateType();
5254
}

server/src/main/java/com/cloud/storage/upload/params/UploadParamsBase.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ public abstract class UploadParamsBase implements UploadParams {
4848
private boolean deployAsIs;
4949
private boolean forCks;
5050
private CPU.CPUArch arch;
51+
private String templateType;
5152

5253
UploadParamsBase(long userId, String name, String displayText, CPU.CPUArch arch,
53-
Integer bits, boolean passwordEnabled, boolean requiresHVM,
54-
boolean isPublic, boolean featured,
55-
boolean isExtractable, String format, Long guestOSId,
56-
Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum,
57-
String templateTag, long templateOwnerId,
58-
Map details, boolean sshkeyEnabled,
59-
boolean isDynamicallyScalable, boolean isRoutingType, boolean deployAsIs, boolean forCks) {
54+
Integer bits, boolean passwordEnabled, boolean requiresHVM,
55+
boolean isPublic, boolean featured,
56+
boolean isExtractable, String format, Long guestOSId,
57+
Long zoneId, Hypervisor.HypervisorType hypervisorType, String checksum,
58+
String templateTag, long templateOwnerId,
59+
Map details, boolean sshkeyEnabled,
60+
boolean isDynamicallyScalable, boolean isRoutingType, boolean deployAsIs,
61+
boolean forCks, String templateType) {
6062
this.userId = userId;
6163
this.name = name;
6264
this.displayText = displayText;
@@ -79,6 +81,8 @@ public abstract class UploadParamsBase implements UploadParams {
7981
this.isDynamicallyScalable = isDynamicallyScalable;
8082
this.isRoutingType = isRoutingType;
8183
this.deployAsIs = deployAsIs;
84+
this.forCks = forCks;
85+
this.templateType = templateType;
8286
}
8387

8488
UploadParamsBase(long userId, String name, String displayText, boolean isPublic, boolean isFeatured,
@@ -261,4 +265,14 @@ public CPU.CPUArch getArch() {
261265
public void setArch(CPU.CPUArch arch) {
262266
this.arch = arch;
263267
}
268+
269+
@Override
270+
public boolean isForCks() {
271+
return forCks;
272+
}
273+
274+
@Override
275+
public String getTemplateType() {
276+
return templateType;
277+
}
264278
}

server/src/main/java/com/cloud/template/TemplateAdapterBase.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,25 @@ private TemplateProfile prepareUploadParamsInternal(UploadParams params) throws
490490
StringUtils.join(Arrays.stream(HypervisorType.values()).filter(h -> h != HypervisorType.None).map(HypervisorType::name).toArray(), ", ")));
491491
}
492492

493+
TemplateType templateType;
494+
if (params.getTemplateType() != null) {
495+
try {
496+
templateType = TemplateType.valueOf(params.getTemplateType().toUpperCase());
497+
} catch (IllegalArgumentException ex) {
498+
throw new InvalidParameterValueException(String.format("Please specify a valid templatetype: %s",
499+
org.apache.commons.lang3.StringUtils.join(",", TemplateType.values())));
500+
}
501+
} else {
502+
templateType = params.isRoutingType() ? TemplateType.ROUTING : TemplateType.USER;
503+
}
504+
493505
return prepare(params.isIso(), params.getUserId(), params.getName(), params.getDisplayText(), params.getArch(), params.getBits(),
494506
params.isPasswordEnabled(), params.requiresHVM(), params.getUrl(), params.isPublic(), params.isFeatured(),
495507
params.isExtractable(), params.getFormat(), params.getGuestOSId(), zoneList,
496508
params.getHypervisorType(), params.getChecksum(), params.isBootable(), params.getTemplateTag(), owner,
497509
params.getDetails(), params.isSshKeyEnabled(), params.getImageStoreUuid(),
498-
params.isDynamicallyScalable(), params.isRoutingType() ? TemplateType.ROUTING : TemplateType.USER, params.isDirectDownload(), params.isDeployAsIs(), false, null);
510+
params.isDynamicallyScalable(), templateType, params.isDirectDownload(), params.isDeployAsIs(),
511+
params.isForCks(), null);
499512
}
500513

501514
private Long getDefaultDeployAsIsGuestOsId() {
@@ -516,7 +529,8 @@ public TemplateProfile prepare(GetUploadParamsForTemplateCmd cmd) throws Resourc
516529
BooleanUtils.toBoolean(cmd.isFeatured()), BooleanUtils.toBoolean(cmd.isExtractable()), cmd.getFormat(), osTypeId,
517530
cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), cmd.getChecksum(),
518531
cmd.getTemplateTag(), cmd.getEntityOwnerId(), cmd.getDetails(), BooleanUtils.toBoolean(cmd.isSshKeyEnabled()),
519-
BooleanUtils.toBoolean(cmd.isDynamicallyScalable()), BooleanUtils.toBoolean(cmd.isRoutingType()), cmd.isDeployAsIs(), cmd.isForCks());
532+
BooleanUtils.toBoolean(cmd.isDynamicallyScalable()), BooleanUtils.toBoolean(cmd.isRoutingType()), cmd.isDeployAsIs(),
533+
cmd.isForCks(), cmd.getTemplateType());
520534
return prepareUploadParamsInternal(params);
521535
}
522536

0 commit comments

Comments
 (0)