From 5dd1a1dd8eec0a37db36b5c86d847fbbe4fcc41d Mon Sep 17 00:00:00 2001 From: Harikrishna Patnala Date: Fri, 12 Jul 2013 13:22:41 +0530 Subject: [PATCH] CLOUDSTACK-2987: Fixing dynamicallyScalable flag in register and update template API Previuos commit: 7b6b8d7a077478620232ea1ac4ec2304289e8661 This fix is due to some changes made by the merges after this commit. Signed-off-by: Abhinandan Prateek --- .../src/com/cloud/storage/VMTemplateVO.java | 3 ++- .../cloud/template/TemplateAdapterBase.java | 2 +- .../cloud/template/TemplateManagerImpl.java | 21 ++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/engine/schema/src/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/com/cloud/storage/VMTemplateVO.java index 3e711911f53..60c1a4ee19a 100755 --- a/engine/schema/src/com/cloud/storage/VMTemplateVO.java +++ b/engine/schema/src/com/cloud/storage/VMTemplateVO.java @@ -175,12 +175,13 @@ public class VMTemplateVO implements VirtualMachineTemplate { public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, - HypervisorType hyperType, String templateTag, Map details, boolean sshKeyEnabled) { + HypervisorType hyperType, String templateTag, Map details, boolean sshKeyEnabled, boolean isDynamicallyScalable) { this(id, name, format, isPublic, featured, isExtractable, type, url, requiresHvm, bits, accountId, cksum, displayText, enablePassword, guestOSId, bootable, hyperType, details); this.templateTag = templateTag; this.uuid = UUID.randomUUID().toString(); this.enableSshKey = sshKeyEnabled; + this.dynamicallyScalable = isDynamicallyScalable; } diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index fce2506983c..4f29fcd6772 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -258,7 +258,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat profile.getFeatured(), profile.getIsExtractable(), profile.getTemplateType(), profile.getUrl(), profile.getRequiresHVM(), profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(), profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), - profile.getDetails(), profile.getSshKeyEnabled()); + profile.getDetails(), profile.getSshKeyEnabled(), profile.IsDynamicallyScalable()); if (zoneId == null || zoneId.longValue() == -1) { diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 5a5465603c9..8dcb0ed07d9 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1686,6 +1686,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, String format = cmd.getFormat(); Long guestOSId = cmd.getOsTypeId(); Boolean passwordEnabled = cmd.isPasswordEnabled(); + Boolean isDynamicallyScalable = cmd.isDynamicallyScalable(); + Boolean isRoutingTemplate = cmd.isRoutingType(); Boolean bootable = cmd.isBootable(); Integer sortKey = cmd.getSortKey(); Account account = UserContext.current().getCaller(); @@ -1707,9 +1709,14 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, // do a permission check _accountMgr.checkAccess(account, AccessType.ModifyEntry, true, template); + if(cmd.isRoutingType() != null){ + if(!_accountService.isRootAdmin(account.getType())){ + throw new PermissionDeniedException("Parameter isrouting can only be specified by a Root Admin, permission denied"); + } + } boolean updateNeeded = !(name == null && displayText == null && format == null && guestOSId == null && passwordEnabled == null - && bootable == null && sortKey == null); + && bootable == null && sortKey == null && isDynamicallyScalable == null && isRoutingTemplate == null); if (!updateNeeded) { return template; } @@ -1758,6 +1765,18 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, template.setBootable(bootable); } + if (isDynamicallyScalable != null) { + template.setDynamicallyScalable(isDynamicallyScalable); + } + + if (isRoutingTemplate != null) { + if (isRoutingTemplate) { + template.setTemplateType(TemplateType.ROUTING); + } else { + template.setTemplateType(TemplateType.USER); + } + } + _tmpltDao.update(id, template); return _tmpltDao.findById(id);