Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template: create/updateTemplate should allow to set/change sshKeyEnabled #2922

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -58,6 +58,9 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd {
@Parameter(name = ApiConstants.PASSWORD_ENABLED, type = CommandType.BOOLEAN, description = "true if the image supports the password reset feature; default is false")
private Boolean passwordEnabled;

@Parameter(name = ApiConstants.SSHKEY_ENABLED, type = CommandType.BOOLEAN, description = "true if the template supports the sshkey upload feature; default is false")
private Boolean sshKeyEnabled;

@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the template, integer")
private Integer sortKey;

Expand Down Expand Up @@ -109,6 +112,10 @@ public Boolean getPasswordEnabled() {
return passwordEnabled;
}

public Boolean isSshKeyEnabled() {
return sshKeyEnabled;
}

public String getFormat() {
return format;
}
Expand Down
Expand Up @@ -92,6 +92,9 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
description = "true if the template supports the password reset feature; default is false")
private Boolean passwordEnabled;

@Parameter(name = ApiConstants.SSHKEY_ENABLED, type = CommandType.BOOLEAN, description = "true if the template supports the sshkey upload feature; default is false")
private Boolean sshKeyEnabled;

@Parameter(name = ApiConstants.REQUIRES_HVM, type = CommandType.BOOLEAN, description = "true if the template requres HVM, false otherwise")
private Boolean requiresHvm;

Expand Down Expand Up @@ -163,6 +166,10 @@ public Boolean isPasswordEnabled() {
return passwordEnabled;
}

public Boolean isSshKeyEnabled() {
return sshKeyEnabled;
}

public Boolean getRequiresHvm() {
return requiresHvm;
}
Expand Down
Expand Up @@ -1736,11 +1736,13 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
Integer bits = cmd.getBits();
Boolean requiresHvm = cmd.getRequiresHvm();
Boolean passwordEnabled = cmd.isPasswordEnabled();
Boolean sshKeyEnabled = cmd.isSshKeyEnabled();
Boolean isPublic = cmd.isPublic();
Boolean featured = cmd.isFeatured();
int bitsValue = ((bits == null) ? 64 : bits.intValue());
boolean requiresHvmValue = ((requiresHvm == null) ? true : requiresHvm.booleanValue());
boolean passwordEnabledValue = ((passwordEnabled == null) ? false : passwordEnabled.booleanValue());
boolean sshKeyEnabledValue = ((sshKeyEnabled == null) ? false : sshKeyEnabled.booleanValue());
if (isPublic == null) {
isPublic = Boolean.FALSE;
}
Expand Down Expand Up @@ -1849,7 +1851,7 @@ public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account t
}
privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable,
TemplateType.USER, null, requiresHvmValue, bitsValue, templateOwner.getId(), null, description,
passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled, false);
passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), sshKeyEnabledValue, isDynamicScalingEnabled, false);

if (sourceTemplateId != null) {
if (s_logger.isDebugEnabled()) {
Expand Down Expand Up @@ -2010,6 +2012,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
String format = cmd.getFormat();
Long guestOSId = cmd.getOsTypeId();
Boolean passwordEnabled = cmd.getPasswordEnabled();
Boolean sshKeyEnabled = cmd.isSshKeyEnabled();
Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
Boolean isRoutingTemplate = cmd.isRoutingType();
Boolean bootable = cmd.getBootable();
Expand Down Expand Up @@ -2045,6 +2048,7 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
guestOSId == null &&
passwordEnabled == null &&
bootable == null &&
sshKeyEnabled == null &&
requiresHvm == null &&
sortKey == null &&
isDynamicallyScalable == null &&
Expand Down Expand Up @@ -2108,6 +2112,10 @@ private VMTemplateVO updateTemplateOrIso(BaseUpdateTemplateOrIsoCmd cmd) {
template.setEnablePassword(passwordEnabled);
}

if (sshKeyEnabled != null) {
template.setEnableSshKey(sshKeyEnabled);
}

if (bootable != null) {
template.setBootable(bootable);
}
Expand Down