CLOUDSTACK-2835: VR Deployement from admin registered template is failing because registered template type is user. Additional parameter "isrouter" in register/update template API for the root admin. True if registered template is of type ROUTING.
Signed-off-by: Abhinandan Prateek <aprat...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9385cf04 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9385cf04 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9385cf04 Branch: refs/heads/master Commit: 9385cf045359c9dd844548bdc701f4f614f37c68 Parents: 0d1f512 Author: Harikrishna Patnala <harikrishna.patn...@citrix.com> Authored: Mon Jun 24 16:31:33 2013 +0530 Committer: Abhinandan Prateek <aprat...@apache.org> Committed: Wed Jun 26 16:00:12 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/storage/Storage.java | 1 + .../org/apache/cloudstack/api/ApiConstants.java | 1 + .../api/BaseUpdateTemplateOrIsoCmd.java | 7 +++++ .../user/template/RegisterTemplateCmd.java | 7 +++++ .../user/template/UpdateTemplateCmd.java | 1 + .../cloud/storage/dao/VMTemplateDaoImpl.java | 19 ++++++++++++-- .../com/cloud/upgrade/dao/Upgrade410to420.java | 24 +++++++++++++++-- .../com/cloud/server/ManagementServerImpl.java | 20 ++++++++++++++- .../src/com/cloud/storage/TemplateProfile.java | 12 ++++++++- .../src/com/cloud/template/TemplateAdapter.java | 4 ++- .../com/cloud/template/TemplateAdapterBase.java | 27 +++++++++++--------- .../com/cloud/template/TemplateManagerImpl.java | 7 ++++- 12 files changed, 110 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/api/src/com/cloud/storage/Storage.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/storage/Storage.java b/api/src/com/cloud/storage/Storage.java index 16ef019..9a50ffa 100755 --- a/api/src/com/cloud/storage/Storage.java +++ b/api/src/com/cloud/storage/Storage.java @@ -85,6 +85,7 @@ public class Storage { } public static enum TemplateType { + ROUTING, // Router template SYSTEM, /* routing, system vm template */ BUILTIN, /* buildin template */ PERHOST, /* every host has this template, don't need to install it in secondary storage */ http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/api/src/org/apache/cloudstack/api/ApiConstants.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 8ac7c3f..809e023 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -511,6 +511,7 @@ public class ApiConstants { public static final String ACL_ID = "aclid"; public static final String NUMBER = "number"; public static final String IS_DYNAMICALLY_SCALABLE = "isdynamicallyscalable"; + public static final String ROUTING = "isrouting"; public enum HostDetails { all, capacity, events, stats, min; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java index b01c8d0..a4c5bfa 100644 --- a/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java @@ -57,6 +57,9 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { @Parameter(name = ApiConstants.IS_DYNAMICALLY_SCALABLE, type = CommandType.BOOLEAN, description = "true if template/ISO contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory") private Boolean isDynamicallyScalable; + @Parameter(name = ApiConstants.ROUTING, type = CommandType.BOOLEAN, description = "true if the template type is routing i.e., if template is used to deploy router") + protected Boolean isRoutingType; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -96,4 +99,8 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { public Boolean isDynamicallyScalable() { return isDynamicallyScalable; } + + public Boolean isRoutingType() { + return isRoutingType; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index 6a8e555..13bd5da 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -117,6 +117,9 @@ public class RegisterTemplateCmd extends BaseCmd { @Parameter(name = ApiConstants.IS_DYNAMICALLY_SCALABLE, type = CommandType.BOOLEAN, description = "true if template contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory") protected Boolean isDynamicallyScalable; + @Parameter(name = ApiConstants.ROUTING, type = CommandType.BOOLEAN, description = "true if the template type is routing i.e., if template is used to deploy router") + protected Boolean isRoutingType; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -208,6 +211,10 @@ public class RegisterTemplateCmd extends BaseCmd { return isDynamicallyScalable == null ? false : isDynamicallyScalable; } + public Boolean isRoutingType() { + return isRoutingType == null ? false : isRoutingType; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java index 9f55f9d..b4149c0 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java @@ -70,6 +70,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd { if (result != null) { TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result); response.setObjectName("template"); + response.setTemplateType(result.getTemplateType().toString());//Template can be either USER or ROUTING type response.setResponseName(getCommandName()); this.setResponseObject(response); } else { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index e7b85f8..ad33e7a 100755 --- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -790,7 +790,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem @Override public VMTemplateVO findRoutingTemplate(HypervisorType hType, String templateName) { SearchCriteria<VMTemplateVO> sc = tmpltTypeHyperSearch2.create(); - sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setParameters("templateType", TemplateType.ROUTING); sc.setParameters("hypervisorType", hType); if (templateName != null) { sc.setParameters("templateName", templateName); @@ -803,7 +803,22 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem if (tmplts.size() > 0) { return tmplts.get(0); } else { - return null; + sc = tmpltTypeHyperSearch2.create(); + sc.setParameters("templateType", TemplateType.SYSTEM); + sc.setParameters("hypervisorType", hType); + if (templateName != null) { + sc.setParameters("templateName", templateName); + } + + // order by descending order of id and select the first (this is going + // to be the latest) + tmplts = listBy(sc, new Filter(VMTemplateVO.class, "id", false, null, 1l)); + + if (tmplts.size() > 0) { + return tmplts.get(0); + } else { + return null; + } } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 8f63a6c..c67a971 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -163,7 +163,7 @@ public class Upgrade410to420 implements DbUpgrade { s_logger.debug("Updating XenSever System Vms"); //XenServer try { - //Get 4.2.0 xenserer system Vm template Id + //Get 4.2.0 XenServer system Vm template Id pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name like 'systemvm-xenserver-4.2' and removed is null order by id desc limit 1"); rs = pstmt.executeQuery(); if(rs.next()){ @@ -180,6 +180,10 @@ public class Upgrade410to420 implements DbUpgrade { pstmt.setLong(1, templateId); pstmt.executeUpdate(); pstmt.close(); + // Change value of global configuration parameter router.template.xen + pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.xen', 'systemvm-xenserver-4.2', 'Name of the default router template on Xenserver')"); + pstmt.execute(); + pstmt.close(); } else { if (xenserver){ throw new CloudRuntimeException("4.2.0 XenServer SystemVm template not found. Cannot upgrade system Vms"); @@ -209,7 +213,11 @@ public class Upgrade410to420 implements DbUpgrade { // update templete ID of system Vms pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = 'KVM'"); pstmt.setLong(1, templateId); - pstmt.executeUpdate(); + pstmt.execute(); + pstmt.close(); + // Change value of global configuration parameter router.template.kvm + pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.kvm', 'systemvm-kvm-4.2', 'Name of the default router template on KVM')"); + pstmt.execute(); pstmt.close(); } else { if (kvm){ @@ -242,6 +250,10 @@ public class Upgrade410to420 implements DbUpgrade { pstmt.setLong(1, templateId); pstmt.executeUpdate(); pstmt.close(); + // Change value of global configuration parameter router.template.vmware + pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.vmware', 'systemvm-vmware-4.2', 'Name of the default router template on Vmware')"); + pstmt.execute(); + pstmt.close(); } else { if (VMware){ throw new CloudRuntimeException("4.2.0 VMware SystemVm template not found. Cannot upgrade system Vms"); @@ -273,6 +285,10 @@ public class Upgrade410to420 implements DbUpgrade { pstmt.setLong(1, templateId); pstmt.executeUpdate(); pstmt.close(); + // Change value of global configuration parameter router.template.hyperv + pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.hyperv', 'systemvm-hyperv-4.2', 'Name of the default router template on Hyperv')"); + pstmt.execute(); + pstmt.close(); } else { if (Hyperv){ throw new CloudRuntimeException("4.2.0 HyperV SystemVm template not found. Cannot upgrade system Vms"); @@ -304,6 +320,10 @@ public class Upgrade410to420 implements DbUpgrade { pstmt.setLong(1, templateId); pstmt.executeUpdate(); pstmt.close(); + // Change value of global configuration parameter router.template.lxc + pstmt = conn.prepareStatement("INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.template.lxc', 'systemvm-lxc-4.2', 'Name of the default router template on LXC')"); + pstmt.execute(); + pstmt.close(); } else { if (LXC){ throw new CloudRuntimeException("4.2.0 LXC SystemVm template not found. Cannot upgrade system Vms"); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/server/src/com/cloud/server/ManagementServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 97bac1b..40bc437 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -486,6 +486,7 @@ import com.cloud.storage.GuestOsCategory; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; +import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; import com.cloud.storage.VolumeManager; @@ -506,6 +507,7 @@ import com.cloud.tags.dao.ResourceTagDao; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; +import com.cloud.user.AccountService; import com.cloud.user.SSHKeyPair; import com.cloud.user.SSHKeyPairVO; import com.cloud.user.User; @@ -679,6 +681,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe UserVmManager _userVmMgr; @Inject VolumeDataFactory _volFactory; + @Inject + AccountService _accountService; private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker")); private final ScheduledExecutorService _alertExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AlertChecker")); @@ -1732,6 +1736,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Boolean bootable = cmd.isBootable(); Integer sortKey = cmd.getSortKey(); Boolean isDynamicallyScalable = cmd.isDynamicallyScalable(); + Boolean isRoutingTemplate = cmd.isRoutingType(); Account account = UserContext.current().getCaller(); // verify that template exists @@ -1752,8 +1757,13 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe // 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 && isDynamicallyScalable == null); + && bootable == null && sortKey == null && isDynamicallyScalable == null && isRoutingTemplate == null); if (!updateNeeded) { return template; } @@ -1806,6 +1816,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe template.setDynamicallyScalable(isDynamicallyScalable); } + if (isRoutingTemplate != null) { + if (isRoutingTemplate) { + template.setTemplateType(TemplateType.ROUTING); + } else { + template.setTemplateType(TemplateType.USER); + } + } + _templateDao.update(id, template); return _templateDao.findById(id); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/server/src/com/cloud/storage/TemplateProfile.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/TemplateProfile.java b/server/src/com/cloud/storage/TemplateProfile.java index 00aab4d..e87a805 100755 --- a/server/src/com/cloud/storage/TemplateProfile.java +++ b/server/src/com/cloud/storage/TemplateProfile.java @@ -20,6 +20,7 @@ import java.util.Map; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Storage.ImageFormat; +import com.cloud.storage.Storage.TemplateType; public class TemplateProfile { Long userId; @@ -47,6 +48,7 @@ public class TemplateProfile { String templateTag; Map details; Boolean isDynamicallyScalable; + TemplateType templateType; public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm, @@ -86,11 +88,12 @@ public class TemplateProfile { String url, Boolean isPublic, Boolean featured, Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, HypervisorType hypervisorType, String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, String templateTag, Map details, Boolean sshKeyEnabled, - Long imageStoreId, Boolean isDynamicallyScalable) { + Long imageStoreId, Boolean isDynamicallyScalable, TemplateType templateType) { this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, isExtractable, format, guestOsId, zoneId, hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled); this.templateTag = templateTag; this.isDynamicallyScalable = isDynamicallyScalable; + this.templateType = templateType; } public Long getTemplateId() { @@ -265,4 +268,11 @@ public class TemplateProfile { this.isDynamicallyScalable = isDynamicallyScalabe; } + public TemplateType getTemplateType() { + return templateType; + } + + public void setTemplateType(TemplateType templateType) { + this.templateType = templateType; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/server/src/com/cloud/template/TemplateAdapter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/TemplateAdapter.java b/server/src/com/cloud/template/TemplateAdapter.java index d50d45b..17c6347 100755 --- a/server/src/com/cloud/template/TemplateAdapter.java +++ b/server/src/com/cloud/template/TemplateAdapter.java @@ -28,6 +28,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.TemplateProfile; import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.Storage.TemplateType; import com.cloud.user.Account; import com.cloud.utils.component.Adapter; @@ -69,6 +70,7 @@ public interface TemplateAdapter extends Adapter { public TemplateProfile prepare(boolean isIso, long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType, - String chksum, Boolean bootable, String templateTag, Account templateOwner, Map details, Boolean sshKeyEnabled, String imageStoreUuid, Boolean isDynamicallyScalable) throws ResourceAllocationException; + String chksum, Boolean bootable, String templateTag, Account templateOwner, Map details, Boolean sshKeyEnabled, + String imageStoreUuid, Boolean isDynamicallyScalable, TemplateType templateType) throws ResourceAllocationException; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/server/src/com/cloud/template/TemplateAdapterBase.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index c1f0604..7835680 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -106,7 +106,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType, String accountName, Long domainId, String chksum, Boolean bootable, Map details) throws ResourceAllocationException { return prepare(isIso, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, featured, isExtractable, format, guestOSId, zoneId, hypervisorType, - chksum, bootable, null, null, details, false, null, false); + chksum, bootable, null, null, details, false, null, false, TemplateType.USER); } @Override @@ -114,7 +114,7 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType, String chksum, Boolean bootable, String templateTag, Account templateOwner, Map details, Boolean sshkeyEnabled, - String imageStoreUuid, Boolean isDynamicallyScalable) throws ResourceAllocationException { + String imageStoreUuid, Boolean isDynamicallyScalable, TemplateType templateType) throws ResourceAllocationException { //Long accountId = null; // parameters verification @@ -214,8 +214,9 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat Long id = _tmpltDao.getNextInSequence(Long.class, "id"); UserContext.current().setEventDetails("Id: " +id+ " name: " + name); - return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, - featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, isDynamicallyScalable); + return new TemplateProfile(id, userId, name, displayText, bits, passwordEnabled, requiresHVM, url, isPublic, + featured, isExtractable, imgfmt, guestOSId, zoneId, hypervisorType, templateOwner.getAccountName(), templateOwner.getDomainId(), + templateOwner.getAccountId(), chksum, bootable, templateTag, details, sshkeyEnabled, null, isDynamicallyScalable, templateType); } @@ -228,10 +229,11 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat - return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(), - cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), - cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), - cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable()); + return prepare(false, UserContext.current().getCallerUserId(), cmd.getTemplateName(), cmd.getDisplayText(), + cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), + cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), cmd.getZoneId(), HypervisorType.getType(cmd.getHypervisor()), + cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable(), + cmd.isRoutingType() ? TemplateType.ROUTING : TemplateType.USER); } @@ -242,15 +244,16 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); - return prepare(true, UserContext.current().getCallerUserId(), cmd.getIsoName(), cmd.getDisplayText(), 64, false, - true, cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), ImageFormat.ISO.toString(), cmd.getOsTypeId(), - cmd.getZoneId(), HypervisorType.None, cmd.getChecksum(), cmd.isBootable(), null, owner, null, false, cmd.getImageStoreUuid(), cmd.isDynamicallyScalable()); + return prepare(true, UserContext.current().getCallerUserId(), cmd.getIsoName(), cmd.getDisplayText(), 64, false, + true, cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), ImageFormat.ISO.toString(), cmd.getOsTypeId(), + cmd.getZoneId(), HypervisorType.None, cmd.getChecksum(), cmd.isBootable(), null, owner, null, false, cmd.getImageStoreUuid(), cmd.isDynamicallyScalable(), + TemplateType.USER); } protected VMTemplateVO persistTemplate(TemplateProfile profile) { Long zoneId = profile.getZoneId(); VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), - profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), + 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()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9385cf04/server/src/com/cloud/template/TemplateManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index cbf70fa..f70d44d 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -347,12 +347,17 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, @Override @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template") public VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException { + Account account = UserContext.current().getCaller(); if (cmd.getTemplateTag() != null) { - Account account = UserContext.current().getCaller(); if (!_accountService.isRootAdmin(account.getType())) { throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied"); } } + if(cmd.isRoutingType() != null){ + if(!_accountService.isRootAdmin(account.getType())){ + throw new PermissionDeniedException("Parameter isrouting can only be specified by a Root Admin, permission denied"); + } + } TemplateAdapter adapter = getAdapter(HypervisorType.getType(cmd.getHypervisor())); TemplateProfile profile = adapter.prepare(cmd);